@3lineas/d1-orm 1.0.12 → 1.0.13

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.
@@ -266,40 +266,22 @@ async function makeModel(name) {
266
266
  });
267
267
  if (p3.isCancel(fieldName)) break;
268
268
  if (!fieldName) break;
269
- const fieldType = await p3.select({
270
- message: `Type for ${fieldName}:`,
271
- options: [
272
- { value: "string", label: "String" },
273
- { value: "integer", label: "Integer" },
274
- { value: "boolean", label: "Boolean" },
275
- { value: "text", label: "Text" },
276
- { value: "float", label: "Float" },
277
- { value: "json", label: "JSON" },
278
- { value: "enum", label: "Enum" },
279
- { value: "date", label: "Date" },
280
- { value: "blob", label: "Blob" },
281
- { value: "belongsToMany", label: "ManyToMany (Pivot Table)" },
282
- { value: "relation", label: "Relation (1:1, 1:N)" }
283
- ]
269
+ const isRelation = await p3.confirm({
270
+ message: `Is "${fieldName}" a relationship?`,
271
+ initialValue: false
284
272
  });
285
- if (p3.isCancel(fieldType)) break;
286
- if (fieldType === "relation" || fieldType === "belongsToMany") {
287
- let relType = fieldType;
288
- if (fieldType === "relation") {
289
- relType = await p3.select({
290
- message: `Relation type for ${fieldName}:`,
291
- options: [
292
- { value: "hasOne", label: "HasOne" },
293
- { value: "hasMany", label: "HasMany" },
294
- { value: "belongsTo", label: "BelongsTo" }
295
- ]
296
- });
297
- }
273
+ if (p3.isCancel(isRelation)) break;
274
+ if (isRelation) {
275
+ const relType = await p3.select({
276
+ message: `Relationship type for ${fieldName}:`,
277
+ options: [
278
+ { value: "hasOne", label: "HasOne (1:1)" },
279
+ { value: "hasMany", label: "HasMany (1:N)" },
280
+ { value: "belongsTo", label: "BelongsTo (N:1)" },
281
+ { value: "belongsToMany", label: "ManyToMany (Pivot Table)" }
282
+ ]
283
+ });
298
284
  if (p3.isCancel(relType)) break;
299
- const modelsPath = await findModelsPath() || "src/database/models";
300
- const availableModels = fs3.existsSync(
301
- path3.join(process.cwd(), modelsPath)
302
- ) ? fs3.readdirSync(path3.join(process.cwd(), modelPath)).map((f) => f.replace(".mts", "").replace(".ts", "")) : [];
303
285
  const targetModel = await p3.text({
304
286
  message: "Target model for this relation:",
305
287
  placeholder: "e.g. Post",
@@ -317,7 +299,7 @@ async function makeModel(name) {
317
299
  if (p3.isCancel(pivotTable)) break;
318
300
  } else if (relType === "belongsTo") {
319
301
  foreignKey = await p3.text({
320
- message: "Foreign key column name:",
302
+ message: "Foreign key column name (added to this table):",
321
303
  placeholder: `e.g. ${targetModel.toLowerCase()}_id`,
322
304
  initialValue: `${targetModel.toLowerCase()}_id`
323
305
  });
@@ -360,6 +342,21 @@ async function makeModel(name) {
360
342
  }
361
343
  }
362
344
  } else {
345
+ const fieldType = await p3.select({
346
+ message: `Type for attribute "${fieldName}":`,
347
+ options: [
348
+ { value: "string", label: "String" },
349
+ { value: "integer", label: "Integer" },
350
+ { value: "boolean", label: "Boolean" },
351
+ { value: "text", label: "Text" },
352
+ { value: "float", label: "Float" },
353
+ { value: "json", label: "JSON" },
354
+ { value: "enum", label: "Enum" },
355
+ { value: "date", label: "Date" },
356
+ { value: "blob", label: "Blob" }
357
+ ]
358
+ });
359
+ if (p3.isCancel(fieldType)) break;
363
360
  let enumValues = [];
364
361
  if (fieldType === "enum") {
365
362
  const valuesStr = await p3.text({
@@ -585,35 +582,21 @@ async function modelAdd() {
585
582
  });
586
583
  if (p4.isCancel(fieldName)) break;
587
584
  if (!fieldName) break;
588
- const fieldType = await p4.select({
589
- message: `Type for ${fieldName}:`,
590
- options: [
591
- { value: "string", label: "String" },
592
- { value: "integer", label: "Integer" },
593
- { value: "boolean", label: "Boolean" },
594
- { value: "text", label: "Text" },
595
- { value: "float", label: "Float" },
596
- { value: "json", label: "JSON" },
597
- { value: "enum", label: "Enum" },
598
- { value: "date", label: "Date" },
599
- { value: "blob", label: "Blob" },
600
- { value: "belongsToMany", label: "ManyToMany (Pivot Table)" },
601
- { value: "relation", label: "Relation (1:1, 1:N)" }
602
- ]
585
+ const isRelation = await p4.confirm({
586
+ message: `Is "${fieldName}" a relationship?`,
587
+ initialValue: false
603
588
  });
604
- if (p4.isCancel(fieldType)) break;
605
- if (fieldType === "relation" || fieldType === "belongsToMany") {
606
- let relType = fieldType;
607
- if (fieldType === "relation") {
608
- relType = await p4.select({
609
- message: `Relation type for ${fieldName}:`,
610
- options: [
611
- { value: "hasOne", label: "HasOne" },
612
- { value: "hasMany", label: "HasMany" },
613
- { value: "belongsTo", label: "BelongsTo" }
614
- ]
615
- });
616
- }
589
+ if (p4.isCancel(isRelation)) break;
590
+ if (isRelation) {
591
+ const relType = await p4.select({
592
+ message: `Relationship type for ${fieldName}:`,
593
+ options: [
594
+ { value: "hasOne", label: "HasOne (1:1)" },
595
+ { value: "hasMany", label: "HasMany (1:N)" },
596
+ { value: "belongsTo", label: "BelongsTo (N:1)" },
597
+ { value: "belongsToMany", label: "ManyToMany (Pivot Table)" }
598
+ ]
599
+ });
617
600
  if (p4.isCancel(relType)) break;
618
601
  const targetModel = await p4.text({
619
602
  message: "Target model for this relation:",
@@ -632,7 +615,7 @@ async function modelAdd() {
632
615
  if (p4.isCancel(pivotTable)) break;
633
616
  } else if (relType === "belongsTo") {
634
617
  foreignKey = await p4.text({
635
- message: "Foreign key column name:",
618
+ message: "Foreign key column name (added to this table):",
636
619
  placeholder: `e.g. ${targetModel.toLowerCase()}_id`,
637
620
  initialValue: `${targetModel.toLowerCase()}_id`
638
621
  });
@@ -675,6 +658,21 @@ async function modelAdd() {
675
658
  }
676
659
  }
677
660
  } else {
661
+ const fieldType = await p4.select({
662
+ message: `Type for attribute "${fieldName}":`,
663
+ options: [
664
+ { value: "string", label: "String" },
665
+ { value: "integer", label: "Integer" },
666
+ { value: "boolean", label: "Boolean" },
667
+ { value: "text", label: "Text" },
668
+ { value: "float", label: "Float" },
669
+ { value: "json", label: "JSON" },
670
+ { value: "enum", label: "Enum" },
671
+ { value: "date", label: "Date" },
672
+ { value: "blob", label: "Blob" }
673
+ ]
674
+ });
675
+ if (p4.isCancel(fieldType)) break;
678
676
  let enumValues = [];
679
677
  if (fieldType === "enum") {
680
678
  const valuesStr = await p4.text({
package/dist/cli/index.js CHANGED
@@ -246,40 +246,22 @@ async function makeModel(name) {
246
246
  });
247
247
  if (p3.isCancel(fieldName)) break;
248
248
  if (!fieldName) break;
249
- const fieldType = await p3.select({
250
- message: `Type for ${fieldName}:`,
251
- options: [
252
- { value: "string", label: "String" },
253
- { value: "integer", label: "Integer" },
254
- { value: "boolean", label: "Boolean" },
255
- { value: "text", label: "Text" },
256
- { value: "float", label: "Float" },
257
- { value: "json", label: "JSON" },
258
- { value: "enum", label: "Enum" },
259
- { value: "date", label: "Date" },
260
- { value: "blob", label: "Blob" },
261
- { value: "belongsToMany", label: "ManyToMany (Pivot Table)" },
262
- { value: "relation", label: "Relation (1:1, 1:N)" }
263
- ]
249
+ const isRelation = await p3.confirm({
250
+ message: `Is "${fieldName}" a relationship?`,
251
+ initialValue: false
264
252
  });
265
- if (p3.isCancel(fieldType)) break;
266
- if (fieldType === "relation" || fieldType === "belongsToMany") {
267
- let relType = fieldType;
268
- if (fieldType === "relation") {
269
- relType = await p3.select({
270
- message: `Relation type for ${fieldName}:`,
271
- options: [
272
- { value: "hasOne", label: "HasOne" },
273
- { value: "hasMany", label: "HasMany" },
274
- { value: "belongsTo", label: "BelongsTo" }
275
- ]
276
- });
277
- }
253
+ if (p3.isCancel(isRelation)) break;
254
+ if (isRelation) {
255
+ const relType = await p3.select({
256
+ message: `Relationship type for ${fieldName}:`,
257
+ options: [
258
+ { value: "hasOne", label: "HasOne (1:1)" },
259
+ { value: "hasMany", label: "HasMany (1:N)" },
260
+ { value: "belongsTo", label: "BelongsTo (N:1)" },
261
+ { value: "belongsToMany", label: "ManyToMany (Pivot Table)" }
262
+ ]
263
+ });
278
264
  if (p3.isCancel(relType)) break;
279
- const modelsPath = await findModelsPath() || "src/database/models";
280
- const availableModels = fs3.existsSync(
281
- path3.join(process.cwd(), modelsPath)
282
- ) ? fs3.readdirSync(path3.join(process.cwd(), modelPath)).map((f) => f.replace(".mts", "").replace(".ts", "")) : [];
283
265
  const targetModel = await p3.text({
284
266
  message: "Target model for this relation:",
285
267
  placeholder: "e.g. Post",
@@ -297,7 +279,7 @@ async function makeModel(name) {
297
279
  if (p3.isCancel(pivotTable)) break;
298
280
  } else if (relType === "belongsTo") {
299
281
  foreignKey = await p3.text({
300
- message: "Foreign key column name:",
282
+ message: "Foreign key column name (added to this table):",
301
283
  placeholder: `e.g. ${targetModel.toLowerCase()}_id`,
302
284
  initialValue: `${targetModel.toLowerCase()}_id`
303
285
  });
@@ -340,6 +322,21 @@ async function makeModel(name) {
340
322
  }
341
323
  }
342
324
  } else {
325
+ const fieldType = await p3.select({
326
+ message: `Type for attribute "${fieldName}":`,
327
+ options: [
328
+ { value: "string", label: "String" },
329
+ { value: "integer", label: "Integer" },
330
+ { value: "boolean", label: "Boolean" },
331
+ { value: "text", label: "Text" },
332
+ { value: "float", label: "Float" },
333
+ { value: "json", label: "JSON" },
334
+ { value: "enum", label: "Enum" },
335
+ { value: "date", label: "Date" },
336
+ { value: "blob", label: "Blob" }
337
+ ]
338
+ });
339
+ if (p3.isCancel(fieldType)) break;
343
340
  let enumValues = [];
344
341
  if (fieldType === "enum") {
345
342
  const valuesStr = await p3.text({
@@ -565,35 +562,21 @@ async function modelAdd() {
565
562
  });
566
563
  if (p4.isCancel(fieldName)) break;
567
564
  if (!fieldName) break;
568
- const fieldType = await p4.select({
569
- message: `Type for ${fieldName}:`,
570
- options: [
571
- { value: "string", label: "String" },
572
- { value: "integer", label: "Integer" },
573
- { value: "boolean", label: "Boolean" },
574
- { value: "text", label: "Text" },
575
- { value: "float", label: "Float" },
576
- { value: "json", label: "JSON" },
577
- { value: "enum", label: "Enum" },
578
- { value: "date", label: "Date" },
579
- { value: "blob", label: "Blob" },
580
- { value: "belongsToMany", label: "ManyToMany (Pivot Table)" },
581
- { value: "relation", label: "Relation (1:1, 1:N)" }
582
- ]
565
+ const isRelation = await p4.confirm({
566
+ message: `Is "${fieldName}" a relationship?`,
567
+ initialValue: false
583
568
  });
584
- if (p4.isCancel(fieldType)) break;
585
- if (fieldType === "relation" || fieldType === "belongsToMany") {
586
- let relType = fieldType;
587
- if (fieldType === "relation") {
588
- relType = await p4.select({
589
- message: `Relation type for ${fieldName}:`,
590
- options: [
591
- { value: "hasOne", label: "HasOne" },
592
- { value: "hasMany", label: "HasMany" },
593
- { value: "belongsTo", label: "BelongsTo" }
594
- ]
595
- });
596
- }
569
+ if (p4.isCancel(isRelation)) break;
570
+ if (isRelation) {
571
+ const relType = await p4.select({
572
+ message: `Relationship type for ${fieldName}:`,
573
+ options: [
574
+ { value: "hasOne", label: "HasOne (1:1)" },
575
+ { value: "hasMany", label: "HasMany (1:N)" },
576
+ { value: "belongsTo", label: "BelongsTo (N:1)" },
577
+ { value: "belongsToMany", label: "ManyToMany (Pivot Table)" }
578
+ ]
579
+ });
597
580
  if (p4.isCancel(relType)) break;
598
581
  const targetModel = await p4.text({
599
582
  message: "Target model for this relation:",
@@ -612,7 +595,7 @@ async function modelAdd() {
612
595
  if (p4.isCancel(pivotTable)) break;
613
596
  } else if (relType === "belongsTo") {
614
597
  foreignKey = await p4.text({
615
- message: "Foreign key column name:",
598
+ message: "Foreign key column name (added to this table):",
616
599
  placeholder: `e.g. ${targetModel.toLowerCase()}_id`,
617
600
  initialValue: `${targetModel.toLowerCase()}_id`
618
601
  });
@@ -655,6 +638,21 @@ async function modelAdd() {
655
638
  }
656
639
  }
657
640
  } else {
641
+ const fieldType = await p4.select({
642
+ message: `Type for attribute "${fieldName}":`,
643
+ options: [
644
+ { value: "string", label: "String" },
645
+ { value: "integer", label: "Integer" },
646
+ { value: "boolean", label: "Boolean" },
647
+ { value: "text", label: "Text" },
648
+ { value: "float", label: "Float" },
649
+ { value: "json", label: "JSON" },
650
+ { value: "enum", label: "Enum" },
651
+ { value: "date", label: "Date" },
652
+ { value: "blob", label: "Blob" }
653
+ ]
654
+ });
655
+ if (p4.isCancel(fieldType)) break;
658
656
  let enumValues = [];
659
657
  if (fieldType === "enum") {
660
658
  const valuesStr = await p4.text({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@3lineas/d1-orm",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "A lightweight and powerful ORM for Cloudflare D1, inspired by Laravel Eloquent.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",