@cwqt/refract
Advanced tools
Comparing version 1.3.0 to 1.3.1
{ | ||
"name": "@cwqt/refract", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Generate Prisma from TypeScript", | ||
@@ -5,0 +5,0 @@ "author": "cwqt", |
@@ -97,4 +97,29 @@ # refract | ||
All scalars are variadic functions that take values of the modifiers as follows: | ||
Scalars are the types of data that the column contains, `Int`, `String` | ||
etc. You can define & re-use Scalars wherever in your models | ||
```typescript | ||
const PrimaryKey = Int(Id, Default('autoincrement()')); | ||
// id Int @id @default("autoincrement()") | ||
m.Field('id', PrimaryKey); | ||
``` | ||
## Modifiers | ||
Modifiers are functions/objects that append attributes to a column e.g. | ||
```typescript | ||
// String? @default("Hello World") | ||
String(Default('Hello World'), Nullable); | ||
// Int @id @unique @default(autoincrement()) | ||
Int(Id, Unique, Default('autoincrement()')); | ||
// DateTime @default(now()) @updatedAt | ||
DateTime(Default('now()'), UpdatedAt); | ||
``` | ||
Certain modifiers are constrained to certain scalars, the mapping is: | ||
- `String`: Unique, Id, Default(string | 'auto()'), Limit(number) | ||
@@ -112,15 +137,7 @@ - `Int`: Unique, Id, Default('cuid' | 'autoincrement()' | 'uuid()' | number) | ||
```typescript | ||
// Int @id @default(autoincrement()) | ||
Int(Id, Default('autoincrement()')); | ||
The `Raw()` modifier can be used as an escape hatch: | ||
// DateTime @default(now()) @updatedAt | ||
DateTime(Default('now()'), UpdatedAt); | ||
``` | ||
The `Raw()` modifier to use any unsupported Prisma decorators, e.g. | ||
```typescript | ||
// String @db.ObjectId @map("_id") @default(auto()) | ||
String(Raw('@db.ObjectId'), Map('_id'), Default('auto()')); | ||
// String @db.ObjectId | ||
String(Raw('@db.ObjectId')); | ||
``` | ||
@@ -127,0 +144,0 @@ |
129529
359