@bunnykit/orm 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -1
- package/dist/src/typegen/TypeGenerator.js +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -394,6 +394,25 @@ await Schema.create("posts", (table) => {
|
|
|
394
394
|
});
|
|
395
395
|
```
|
|
396
396
|
|
|
397
|
+
The foreign key call adds the constraint only. Define the local column first, and make its type match the referenced column:
|
|
398
|
+
|
|
399
|
+
```ts
|
|
400
|
+
await Schema.create("users", (table) => {
|
|
401
|
+
table.uuid("id").primary();
|
|
402
|
+
table.string("email").unique();
|
|
403
|
+
table.timestamps();
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
await Schema.create("posts", (table) => {
|
|
407
|
+
table.increments("id");
|
|
408
|
+
table.uuid("user_id");
|
|
409
|
+
table.foreign("user_id").references("id").on("users").onDelete("cascade");
|
|
410
|
+
table.string("title");
|
|
411
|
+
table.text("content");
|
|
412
|
+
table.timestamps();
|
|
413
|
+
});
|
|
414
|
+
```
|
|
415
|
+
|
|
397
416
|
---
|
|
398
417
|
|
|
399
418
|
## Query Builder
|
|
@@ -1219,7 +1238,12 @@ export interface UsersAttributes {
|
|
|
1219
1238
|
}
|
|
1220
1239
|
|
|
1221
1240
|
declare module "../User" {
|
|
1222
|
-
interface User
|
|
1241
|
+
interface User {
|
|
1242
|
+
id: number;
|
|
1243
|
+
name: string;
|
|
1244
|
+
email: string | null;
|
|
1245
|
+
created_at: string;
|
|
1246
|
+
}
|
|
1223
1247
|
}
|
|
1224
1248
|
```
|
|
1225
1249
|
|
|
@@ -36,7 +36,12 @@ export class TypeGenerator {
|
|
|
36
36
|
const modelDeclaration = this.getModelDeclaration(table, className, target.modelImportPrefix);
|
|
37
37
|
if (declarationOnly && modelDeclaration) {
|
|
38
38
|
lines.push(`declare module "${modelDeclaration.path}" {`);
|
|
39
|
-
lines.push(` interface ${modelDeclaration.className}
|
|
39
|
+
lines.push(` interface ${modelDeclaration.className} {`);
|
|
40
|
+
for (const col of columns) {
|
|
41
|
+
const tsType = TypeMapper.sqlToTsType(col.type, col.nullable);
|
|
42
|
+
lines.push(` ${col.name}${col.nullable ? "?" : ""}: ${tsType};`);
|
|
43
|
+
}
|
|
44
|
+
lines.push(" }");
|
|
40
45
|
lines.push("}");
|
|
41
46
|
lines.push("");
|
|
42
47
|
}
|
package/package.json
CHANGED