Skip to content

Commit

Permalink
improve relation docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolasburk committed Nov 14, 2019
1 parent 5eb90f4 commit 5114049
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 101 deletions.
24 changes: 9 additions & 15 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
# Documentation

## Contents

- [Getting started](./getting-started.md)
- [Tutorial](./tutorial.md)
- [Prisma schema file](./prisma-schema-file.md)
- [Data sources](./data-sources.md)
- [Data modeling](./data-modeling.md)
- [Relations](./relations.md)
- [Prisma 2 CLI](./prisma2-cli.md)
- [Prisma Framework CLI](./prisma2-cli.md)
- [Development mode](./development-mode.md)
- [Introspection](./introspection.md)
- [Limitations](./limitations.md)
- Core
- Connectors
- [MySQL](./core/connectors/mysql.md)
- [PostgreSQL](./core/connectors/postgresql.md)
- [SQLite](./core/connectors/sqlite.md)
- [MongoDB](./core/connectors/mongo.md)
- Generators
- [Photon.js](./core/generators/photonjs.md)
- [Core](./core)
- Photon
- [API](./photon/api.md)
- [Use only Photon](./photon/use-only-photon.md)
- [Code generation & Node.js setup](./photon/codegen-and-node-setup.md)
- [Deployment](./photon/deployment.md)
- Lift
- [Steps](./lift/steps.md)
- [Migration files](./lift/migration-files.md)
- [Use only Lift](./lift/use-only-lift.md)
- [Lift](./lift)
- [Importing and exporting data](./import-and-export-data)
- [Supported databases](./supported-databases.md)
- [Telemetry](./telemetry.md)
- [How to provide feedback for Prisma 2?](./prisma2-feedback.md)
- [How to provide feedback for the Prisma Framework?](./prisma2-feedback.md)
- [Release process](./releases.md)
- [Upgrading from Prisma 1](./upgrading-from-prisma-1.md)
- [FAQ](./faq.md)
- [Glossary](./glossary.md)
- [Glossary](./glossary.md)
8 changes: 4 additions & 4 deletions docs/core/generators/photonjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ To determine the platform Photon is running on, you can provide two options to t

When no [generator options](#generator-options) are passed to the `photonjs` generator in your [Prisma schema file](../prisma-schema-file.md), the Prisma CLI will download the binary for the operating system on which `prisma2 generate` was executed. The following two configurations are therefore equivalent, because `["native"]` is the default value for `platforms`:

```prisma
```groovy
generator photon {
provider = "photonjs"
platforms = ["native"]
Expand All @@ -40,7 +40,7 @@ generator photon {

has the **same behavior** as:

```prisma
```groovy
generator photon {
provider = "photonjs"
}
Expand All @@ -67,7 +67,7 @@ In both cases, the Prisma CLI determines the current operating system where `pri

This example shows the configuration of a Photon.js generator for local development (`native` can resolve to any other platform) and AWS Lambda (Node 10) as the production environment.

```prisma
```groovy
generator photon {
provider = "photonjs"
platforms = ["native", "linux-glibc-libssl1.0.2"] // For Lambda (Node 10)
Expand All @@ -90,7 +90,7 @@ If a binary is not available for the platform you want to target, it is possible

To invoke the generator, you need to add a [`generator`](../../prisma-schema-file.md#generators-optional) block to your schema file and specify the `photonjs` provider:

```prisma
```groovy
generator js {
provider = "photonjs"
}
Expand Down
70 changes: 35 additions & 35 deletions docs/data-modeling.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ It describes the shape of the data per data source. For example, when connecting

Here is an example based on a local SQLite database located in the same directory of the schema file (called `data.db`):

```prisma
```groovy
// schema.prisma
datasource sqlite {
Expand Down Expand Up @@ -91,13 +91,13 @@ On a technical level, a model maps to the underlying structures of the data sour
- In MySQL, a model maps to a _table_
- In SQLite, a model maps to a _table_

> **Note**: In the future there might be connectors for non-relational databases and other data sources. For example, for MongoDB a model would map to a _collection_, for a REST API it would map to a _resource_.
> **Note**: In the future there might be connectors for non-relational databases and other data sources. For example, for MongoDB a model would map to a _collection_, for a REST API it would map to a _resource_.
### Naming models

Models are typically spelled in [PascalCase](http://wiki.c2.com/?PascalCase) and use the _singular_ form (e.g. `User` instead of `Users`).

Technically, a model can be named anything that adheres to this regular expression:
Technically, a model can be named anything that adheres to this regular expression:

```
[A-Za-z_][A-Za-z0-9_]*
Expand All @@ -116,18 +116,20 @@ Every _model_ in the data model definition will result in a number of CRUD opera
- `updateMany`
- `deleteMany`

The operations are accessible via a generated property on the Photon instance. By default the name of the property is the plural, lowercase form of the model name, e.g. `users` for a `User` model or `posts` for a `Post` model.
The operations are accessible via a generated property on the Photon instance. By default the name of the property is the plural, lowercase form of the model name, e.g. `users` for a `User` model or `posts` for a `Post` model.

Here is an example illustrating the use of a `users` property from the [Photon.js API](./photon/api.md):

```js
const newUser = await photon.users.create({ data: {
name: "Alice"
}})
const newUser = await photon.users.create({
data: {
name: 'Alice',
},
})
const allUsers = await photon.users.findMany()
```

Note that for Photon.js the name of the `users` property is auto-generated using the [`pluralize`](https://github.com/blakeembrey/pluralize) package.
Note that for Photon.js the name of the `users` property is auto-generated using the [`pluralize`](https://github.com/blakeembrey/pluralize) package.

## Fields

Expand All @@ -144,7 +146,7 @@ You can see examples of fields on the sample models [above](#examples).

Field names are typically spelled in [camelCase](http://wiki.c2.com/?CamelCase) starting with a lowercase letter.

Technically, a model can be named anything that adheres to this regular expression:
Technically, a model can be named anything that adheres to this regular expression:

```
[A-Za-z_][A-Za-z0-9_]*
Expand All @@ -163,12 +165,11 @@ The type of a field determines its _structure_. A type falls in either of two ca

The type of a field can be modified by appending either of two modifiers:

- `[]`: Make a field a **list**
- `[]`: Make a field a **list**
- `?`: Make a field **optional**

In the main example above, the field `name` on the `User` model is _optional_ and the `posts` field is a _list_.


### Field attributes

Learn more about attributes [below](#attributes).
Expand Down Expand Up @@ -283,7 +284,7 @@ model \_ { @@attribute0

_Core_ attributes must be implemented by every [data source](./prisma-schema-file.md#data-sources) connector (with a _best-effort implementation_), this means they will be available in _any_ Prisma setup.

They may be used in `model` blocks as well as on `type` definitions.
They may be used in `model` blocks as well as on `type` definitions.

Here is a list of all available core **field** attributes:

Expand All @@ -300,7 +301,7 @@ Here is a list of all available core **block** attributes:

### Connector attributes

_Connector_ attributes let you use the native features of your data source. With a PostgreSQL database, you can use it for example to X.
_Connector_ attributes let you use the native features of your data source. With a PostgreSQL database, you can use it for example to X.

Here is where you can find the documentation of connector attributes per data source connector:

Expand Down Expand Up @@ -337,14 +338,14 @@ The data types that these functions return will be defined by the data source co
Prisma core provides the following scalar types:

| Prisma Type | Description |
| --- | --- |
| `String` | Variable length text |
| `Boolean` | True or false value |
| `Int` | Integer value |
| `Float` | Floating point number |
| `DateTime` | Timestamp |
| ----------- | --------------------- |
| `String` | Variable length text |
| `Boolean` | True or false value |
| `Int` | Integer value |
| `Float` | Floating point number |
| `DateTime` | Timestamp |

The _data source connector_ determines what _native database type_ each of these types map to. Similarly, the _generator_ determines what _type in the target programming language_ each of these types map to.
The _data source connector_ determines what _native database type_ each of these types map to. Similarly, the _generator_ determines what _type in the target programming language_ each of these types map to.

Expand below to see the mappings per connector and generator.

Expand All @@ -353,27 +354,26 @@ Expand below to see the mappings per connector and generator.

**Connectors**

| Prisma Type | PostgreSQL | MySQL | SQLite | Mongo | Raw JSON |
| ---------- | --------- | --------- | ------- | ------ | -------- |
| `String` | `text` | `TEXT` | `TEXT` | `string` | `string` |
| `Boolean` | `boolean` | `BOOLEAN` | _N/A_ | `bool` | `boolean` |
| `Int` | `integer` | `INT` | `INTEGER` | `int32` | `number` |
| `Float` | `real` | `FLOAT` | `REAL` | `double` | `number` |
| `DateTime` | `timestamp` | `TIMESTAMP` | _N/A_ | `date` | _N/A_ |
| Prisma Type | PostgreSQL | MySQL | SQLite | Mongo | Raw JSON |
| ----------- | ----------- | ----------- | --------- | -------- | --------- |
| `String` | `text` | `TEXT` | `TEXT` | `string` | `string` |
| `Boolean` | `boolean` | `BOOLEAN` | _N/A_ | `bool` | `boolean` |
| `Int` | `integer` | `INT` | `INTEGER` | `int32` | `number` |
| `Float` | `real` | `FLOAT` | `REAL` | `double` | `number` |
| `DateTime` | `timestamp` | `TIMESTAMP` | _N/A_ | `date` | _N/A_ |

**_N/A_:** Means that there is no perfect equivalent, but we can probably get pretty
close.

**Generators**

| Prisma Type | JS / TS | Go |
| ---------- | ------- | --------- |
| `String` | `string` | `string` |
| `Boolean` | `boolean` | `bool` |
| `Int` | `number` | `int` |
| `Float` | `number` | `float64` |
| `DateTime` | `Date` | `time.Time` |

| Prisma Type | JS / TS | Go |
| ----------- | --------- | ----------- |
| `String` | `string` | `string` |
| `Boolean` | `boolean` | `bool` |
| `Int` | `number` | `int` |
| `Float` | `number` | `float64` |
| `DateTime` | `Date` | `time.Time` |

</Details>

Expand Down
4 changes: 2 additions & 2 deletions docs/photon/codegen-and-node-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ Using `node_modules/@generated` as the default `output` for Photon.js is still e

The default Photon.js generator can be specified as follows in your schema file:

```prisma
```groovy
generator photonjs {
provider = "photonjs"
}
```

Note that this is equivalent to specifying the default `output` path:

```prisma
```groovy
generator photonjs {
provider = "photonjs"
output = "node_modules/@generated/photon"
Expand Down

0 comments on commit 5114049

Please sign in to comment.