Skip to content

Commit f847870

Browse files
committed
almost done
1 parent 3ebe44f commit f847870

File tree

15 files changed

+250
-183
lines changed

15 files changed

+250
-183
lines changed
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
```zmodel
22
datasource db {
3-
provider = 'sqlite'
4-
url = "file:./dev.db"
3+
provider = 'sqlite'
4+
url = "file:./dev.db"
55
}
66
77
model User {
8-
id String @id @default(cuid())
9-
email String @unique
10-
posts Post[]
8+
id String @id @default(cuid())
9+
email String @unique
10+
posts Post[]
1111
}
1212
1313
model Post {
14-
id String @id @default(cuid())
15-
createdAt DateTime @default(now())
16-
updatedAt DateTime @updatedAt
17-
title String
18-
content String
19-
published Boolean @default(false)
20-
author User @relation(fields: [authorId], references: [id])
21-
authorId String
14+
id String @id @default(cuid())
15+
createdAt DateTime @default(now())
16+
updatedAt DateTime @updatedAt
17+
title String
18+
content String
19+
published Boolean @default(false)
20+
author User @relation(fields: [authorId], references: [id])
21+
authorId String
2222
}
2323
```

versioned_docs/version-3.x/modeling/attribute.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ model User {
2828
Prisma schema doesn't allow users to define custom attributes, while ZModel allows it and uses it as a key mechanism for extensibility.
2929
</ZModelVsPSL>
3030

31-
ZModel comes with a rich set of attributes that you can use directly. See [ZModel Language Reference](../category/zmodel-language) for a complete list. You can also define your own custom attributes for specific purposes. Attributes are defined with a list of typed parameters. Parameters can be named (default) or positional. Positional parameters can be passed with or without an explicit name. Parameters can also be optional.
31+
ZModel comes with a rich set of attributes that you can use directly. See [ZModel Language Reference](../reference/zmodel/attribute#predefined-attributes) for a complete list. You can also define your own attributes for specific purposes. Attributes are defined with a list of typed parameters. Parameters can be named (default) or positional. Positional parameters can be passed with or without an explicit name. Parameters can also be optional.
3232

3333
Here's an example of how the `@unique` attribute is defined:
3434

@@ -45,3 +45,5 @@ model Foo {
4545
z String @unique(map: 'z_unique', length: 10) // named parameter
4646
}
4747
```
48+
49+
Read the [ZModel Language Reference](../reference/zmodel/attribute#syntax) for more details on how to define and use attributes.

versioned_docs/version-3.x/modeling/datasource.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ datasource db {
3838
Currently, only PostgreSQL and SQLite are supported. MySQL will be supported in a future release. There's no plan for other relational database types or NoSQL databases.
3939

4040
<ZModelVsPSL>
41-
ZenStack's ORM runtime doesn't rely on the `url` information to connect to the database. Instead, you provide the information when constructing an ORM client — more on this in the [ORM](../orm/) section.
41+
ZenStack's ORM runtime doesn't rely on the `url` information to connect to the database. Instead, you provide the information when constructing an ORM client — more on this in the [ORM](../orm/) part.
4242
</ZModelVsPSL>

versioned_docs/version-3.x/modeling/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import ZModelVsPSL from '../_components/ZModelVsPSL';
99

1010
ZenStack uses a schema language named **ZModel** to define data models and their related aspects. We know that designing a good schema language is difficult, and we know it's even more challenging to convince people to learn a new one. We therefore decided to design ZModel as a superset of the [Prisma Schema Language (PSL)](https://www.prisma.io/docs/orm/prisma-schema), one of the best data modeling languages available.
1111

12-
If you're already familiar with PSL, you'll find yourself at home with ZModel. However, we recommend that you skim through this section to learn about the essential extensions we made to PSL. Please pay attention to callouts like the following one:
12+
If you're already familiar with PSL, you'll find yourself at home with ZModel. However, we recommend that you skim through this section to learn about the essential extensions we made to PSL. Please pay attention to callouts like the following:
1313

1414
<ZModelVsPSL>
1515
ZModel allows both single quotes and double quotes for string literals.
1616
</ZModelVsPSL>
1717

18-
Don't worry if you've never used Prisma before. This section will introduce all aspects of ZModel, so no prior knowledge is required.
18+
Don't worry if you've never used Prisma before. This part of documentation will introduce all aspects of ZModel, so no prior knowledge is required.
1919

2020
A simplest ZModel schema looks like this:
2121

versioned_docs/version-3.x/modeling/mixin.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ Very often you'll find many of your models share quite a few common fields. It's
2121

2222
```zmodel
2323
model User {
24-
id String @id
24+
id String @id
2525
createdAt DateTime @default(now())
2626
updatedAt DateTime @updatedAt
27-
email String @unique
27+
email String @unique
2828
}
2929
3030
model Post {

versioned_docs/version-3.x/modeling/model.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Models in ZModel
55

66
# Model
77

8-
The `model` construct is the core of ZModel. It defines the structure of your data and relations. A model represents a domain entity and is mapped to a database table.
8+
The `model` construct is the core of ZModel. It defines the structure of your data and relations. A model represents a domain entity and is backed by a database table.
99

1010
## Defining models
1111

@@ -73,7 +73,7 @@ Each model field must at least have a name and a type. A field can be typed in o
7373
- Bytes
7474
- Unsupported
7575

76-
The `Unsupported` type is for defining fields of types not supported by the ORM; however, it lets the migration engine know how to create the field in the database.
76+
The `Unsupported` type is for defining fields of types not supported by the ORM. It lets the migration engine know how to create the field in the database.
7777

7878
```zmodel
7979
// from Prisma docs
@@ -115,7 +115,7 @@ Each model field must at least have a name and a type. A field can be typed in o
115115
```
116116
4. Custom type
117117
118-
ZenStack allows you to define custom types in the schema and use them to type JSON fields. This will be covered in more detail in the [Custom Types](./custom-type) section.
118+
ZenStack allows you to define custom types in the schema and use them to type JSON fields. This will be covered in more detail in the [Custom Type](./custom-type) section.
119119
120120
```zmodel
121121
type Address {
@@ -174,9 +174,15 @@ model User {
174174
}
175175
```
176176

177-
These attributes control what data type is used when the [migration engine](../orm/migration.md) maps the schema to DDL. You can find a complete list of native type attributes in the [ZModel Language Reference](../category/zmodel-language).
177+
These attributes control what data type is used when the [migration engine](../orm/migration.md) maps the schema to DDL. You can find a complete list of native type attributes in the [ZModel Language Reference](../reference/zmodel/attribute#native-type-mapping-attributes).
178178

179179
## Name mapping
180180

181-
Quite often, you want to use a different naming scheme for your models and fields than the database. You can achieve that with the `@map` attribute. The ORM respects the mapping when generating queries, and the migration engine uses it to generate the DDL.
181+
Quite often, you want to use a different naming scheme for your models and fields than the database. You can achieve that with the `@map` and `@@map` attribute. The ORM respects the mapping when generating queries, and the migration engine uses it to generate the DDL.
182182

183+
```zmodel
184+
model User {
185+
id Int @id @map('_id')
186+
@@map('users')
187+
}
188+
```

versioned_docs/version-3.x/modeling/plugin.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ plugin myPlugin {
2525
```
2626

2727
:::info
28-
In fact, the `zen generate` command is entirely implemented with plugins. The ZModel -> TypeScript generation is supported by the built-in `@core/typescript` plugin, which can be explicitly declared if you wish:
28+
In fact, the `zen generate` command is entirely implemented with plugins. The ZModel -> TypeScript generation is supported by the built-in `@core/typescript` plugin which runs automatically. You can explicitly declare it if you wish:
2929

3030
```zmodel
3131
plugin typescript {
@@ -40,7 +40,7 @@ Please refer to the [Plugin References](../category/plugins) for the full list o
4040
A plugin declaration involves three parts:
4141

4242
1. A unique name
43-
2. A `provider` field that specifies where to load the plugin from. It can be a built-in plugin (like `@core/prisma` here), a local folder, or an npm package.
43+
2. A `provider` field that specifies where to load the plugin from. It can be a built-in plugin (like `@core/prisma` here), a local JavaScript module, or an NPM package name.
4444
3. Plugin-specific configuration options, such as `output` in this case.
4545

4646
A plugin can have the following effects to ZModel:

versioned_docs/version-3.x/modeling/polymorphism.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ It may be tempting to use mixins to share the common fields, however it's not an
2828
A true solution involves having a in-database model of polymorphism, where we really have a `Content` table that serves as an intermediary between `User` and the concrete content types. This is what ZModel polymorphism is about.
2929

3030
:::info
31-
There are [two main ways](https://www.prisma.io/docs/orm/prisma-schema/data-model/table-inheritance) to model polymorphism in relational databases: single-table inheritance (STI) and multi-table inheritance (MTI, aka. delegate types). ZModel only supports MTI.
31+
There are [two main ways](https://www.prisma.io/docs/orm/prisma-schema/data-model/table-inheritance) to model polymorphism in relational databases: single-table inheritance (STI) and multi-table inheritance (MTI, aka. "Delegate Types"). ZModel only supports MTI.
3232
:::
3333

3434
## Modeling polymorphism
@@ -83,17 +83,17 @@ erDiagram
8383
}
8484
User ||--o{ Content: owns
8585
Post {
86-
id Int PK
86+
id Int PK,FK
8787
content String
8888
}
8989
Post ||--|| Content: delegates
9090
Image {
91-
id Int PK
91+
id Int PK,FK
9292
data Bytes
9393
}
9494
Image ||--|| Content: delegates
9595
Video {
96-
id Int PK
96+
id Int PK,FK
9797
url String
9898
}
9999
Video ||--|| Content: delegates

versioned_docs/version-3.x/modeling/typed-json.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ To type a JSON field, define a custom type in ZModel, use it as the field's type
2222

2323
```zmodel
2424
model User {
25-
id Int @id
25+
id Int @id
2626
address Json
2727
}
2828
```
@@ -44,7 +44,7 @@ model User {
4444
```
4545

4646
:::info
47-
The `@json` attribute serves no purpose other than to indicate (for readability) that the field is a JSON field, not a relation to another model.
47+
The `@json` attribute serves no purpose today other than to indicate (for readability) that the field is a JSON field, not a relation to another model. We may extend it in the future for fine-tuning the JSON field's behavior.
4848
:::
4949

5050
The migration engine still sees the field as a plain JSON field. However, the ORM client enforces its structure and takes care of properly typing the query results. We'll revisit this topic in the [ORM part](../orm/typed-json.md).

versioned_docs/version-3.x/orm/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ZenStackVsPrisma from '../_components/ZenStackVsPrisma';
77

88
# ORM Overview
99

10-
ZenStack ORM is a schema-first ORM for modern TypeScript applications. It learnt from the prior arts and strives to provide an awesome developer experience by combining the best ingredients into a cohesive package.
10+
ZenStack ORM is a schema-first ORM for modern TypeScript applications. It learnt from the prior arts and strives to provide an excellent developer experience and incredible flexibility by combining the best ingredients into a cohesive package.
1111

1212
## Key Features
1313

@@ -45,7 +45,7 @@ await db.$qb
4545

4646
ZenStack ORM comes with a powerful built-in access control system. You can define access rules right inside the schema. The rules are enforced at runtime via query injection, so it doesn't rely on any database specific row-level security features.
4747

48-
```zmodel"
48+
```zmodel
4949
model Post {
5050
id Int @id
5151
title String @length(1, 256)
@@ -68,7 +68,7 @@ model Post {
6868

6969
Real-world applications often involves storing polymorphic data which is notoriously complex to model and query. ZenStack does the heavy-lifting for you so you can model an inheritance hierarchy with simple annotations, and query them with perfect type safety.
7070

71-
```zmodel title="zenstack/schema.zmodel"
71+
```zmodel
7272
model Content {
7373
id Int @id
7474
name String @length(1, 256)
@@ -106,7 +106,7 @@ Compared to Prisma and previous versions of ZenStack, v3 is more straightforward
106106

107107
### Sample playground
108108

109-
Throughout the documentation we'll use [StackBlitz](https://stackblitz.com/) to provide interactive code samples. StackBlitz's [WebContainers](https://webcontainers.io/) is an awesome technology that allows you to run a Node.js environment inside the browser. The embedded samples use the [sql.js](https://github.com/sql-js/sql.js) (a WASM implementation of SQLite) for WebContainers compatibility, which is not suitable for production use.
109+
Throughout the documentation we'll use [StackBlitz](https://stackblitz.com/) to provide interactive samples alongside with static code snippets. StackBlitz's [WebContainers](https://webcontainers.io/) is an awesome technology that allows you to run a Node.js environment inside the browser. The embedded samples use the [sql.js](https://github.com/sql-js/sql.js) (a WASM implementation of SQLite) for WebContainers compatibility, which is not suitable for production use. Feel free to make changes and try things out in the playground.
110110

111111
### If you already know Prisma
112112

0 commit comments

Comments
 (0)