@3lineas/d1-orm 1.0.4 → 1.0.5
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/dist/index.d.mts +53 -5
- package/dist/index.d.ts +53 -5
- package/dist/index.js +84 -8
- package/dist/index.mjs +83 -8
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -465,16 +465,64 @@ declare class ModelQueryBuilder<T extends Model> extends QueryBuilder {
|
|
|
465
465
|
getModel(): typeof Model;
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
+
/**
|
|
469
|
+
* Represents a database column definition.
|
|
470
|
+
*/
|
|
471
|
+
declare class Column {
|
|
472
|
+
protected name: string;
|
|
473
|
+
protected type: string;
|
|
474
|
+
protected isNullable: boolean;
|
|
475
|
+
protected isUnique: boolean;
|
|
476
|
+
protected defaultValue: any;
|
|
477
|
+
constructor(name: string, type: string);
|
|
478
|
+
/**
|
|
479
|
+
* Set the column as nullable.
|
|
480
|
+
*/
|
|
481
|
+
nullable(): this;
|
|
482
|
+
/**
|
|
483
|
+
* Set the column as unique.
|
|
484
|
+
*/
|
|
485
|
+
unique(): this;
|
|
486
|
+
/**
|
|
487
|
+
* Set the default value for the column.
|
|
488
|
+
*/
|
|
489
|
+
default(value: any): this;
|
|
490
|
+
/**
|
|
491
|
+
* Convert the column definition to SQL.
|
|
492
|
+
*/
|
|
493
|
+
toSql(): string;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Schema Blueprint for defining tables.
|
|
497
|
+
*/
|
|
468
498
|
declare class Blueprint {
|
|
469
499
|
protected table: string;
|
|
470
|
-
protected columns: string[];
|
|
500
|
+
protected columns: (Column | string)[];
|
|
471
501
|
protected commands: string[];
|
|
472
502
|
constructor(table: string);
|
|
503
|
+
/**
|
|
504
|
+
* Add an auto-incrementing ID column.
|
|
505
|
+
*/
|
|
473
506
|
id(): this;
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
507
|
+
/**
|
|
508
|
+
* Add a string (TEXT) column.
|
|
509
|
+
*/
|
|
510
|
+
string(column: string): Column;
|
|
511
|
+
/**
|
|
512
|
+
* Add an integer column.
|
|
513
|
+
*/
|
|
514
|
+
integer(column: string): Column;
|
|
515
|
+
/**
|
|
516
|
+
* Add a boolean column.
|
|
517
|
+
*/
|
|
518
|
+
boolean(column: string): Column;
|
|
519
|
+
/**
|
|
520
|
+
* Add created_at and updated_at timestamp columns.
|
|
521
|
+
*/
|
|
477
522
|
timestamps(): this;
|
|
523
|
+
/**
|
|
524
|
+
* Convert the blueprint to a set of SQL statements.
|
|
525
|
+
*/
|
|
478
526
|
toSql(): string[];
|
|
479
527
|
}
|
|
480
528
|
|
|
@@ -483,4 +531,4 @@ declare class Schema {
|
|
|
483
531
|
static dropIfExists(table: string): string;
|
|
484
532
|
}
|
|
485
533
|
|
|
486
|
-
export { BelongsTo, Blueprint, Connection, type D1Database, type D1ExecResult, type D1PreparedStatement, type D1Result, type D1Value, Database, HasMany, HasOne, Model, ModelQueryBuilder, QueryBuilder, Relationship, Schema };
|
|
534
|
+
export { BelongsTo, Blueprint, Column, Connection, type D1Database, type D1ExecResult, type D1PreparedStatement, type D1Result, type D1Value, Database, HasMany, HasOne, Model, ModelQueryBuilder, QueryBuilder, Relationship, Schema };
|
package/dist/index.d.ts
CHANGED
|
@@ -465,16 +465,64 @@ declare class ModelQueryBuilder<T extends Model> extends QueryBuilder {
|
|
|
465
465
|
getModel(): typeof Model;
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
+
/**
|
|
469
|
+
* Represents a database column definition.
|
|
470
|
+
*/
|
|
471
|
+
declare class Column {
|
|
472
|
+
protected name: string;
|
|
473
|
+
protected type: string;
|
|
474
|
+
protected isNullable: boolean;
|
|
475
|
+
protected isUnique: boolean;
|
|
476
|
+
protected defaultValue: any;
|
|
477
|
+
constructor(name: string, type: string);
|
|
478
|
+
/**
|
|
479
|
+
* Set the column as nullable.
|
|
480
|
+
*/
|
|
481
|
+
nullable(): this;
|
|
482
|
+
/**
|
|
483
|
+
* Set the column as unique.
|
|
484
|
+
*/
|
|
485
|
+
unique(): this;
|
|
486
|
+
/**
|
|
487
|
+
* Set the default value for the column.
|
|
488
|
+
*/
|
|
489
|
+
default(value: any): this;
|
|
490
|
+
/**
|
|
491
|
+
* Convert the column definition to SQL.
|
|
492
|
+
*/
|
|
493
|
+
toSql(): string;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Schema Blueprint for defining tables.
|
|
497
|
+
*/
|
|
468
498
|
declare class Blueprint {
|
|
469
499
|
protected table: string;
|
|
470
|
-
protected columns: string[];
|
|
500
|
+
protected columns: (Column | string)[];
|
|
471
501
|
protected commands: string[];
|
|
472
502
|
constructor(table: string);
|
|
503
|
+
/**
|
|
504
|
+
* Add an auto-incrementing ID column.
|
|
505
|
+
*/
|
|
473
506
|
id(): this;
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
507
|
+
/**
|
|
508
|
+
* Add a string (TEXT) column.
|
|
509
|
+
*/
|
|
510
|
+
string(column: string): Column;
|
|
511
|
+
/**
|
|
512
|
+
* Add an integer column.
|
|
513
|
+
*/
|
|
514
|
+
integer(column: string): Column;
|
|
515
|
+
/**
|
|
516
|
+
* Add a boolean column.
|
|
517
|
+
*/
|
|
518
|
+
boolean(column: string): Column;
|
|
519
|
+
/**
|
|
520
|
+
* Add created_at and updated_at timestamp columns.
|
|
521
|
+
*/
|
|
477
522
|
timestamps(): this;
|
|
523
|
+
/**
|
|
524
|
+
* Convert the blueprint to a set of SQL statements.
|
|
525
|
+
*/
|
|
478
526
|
toSql(): string[];
|
|
479
527
|
}
|
|
480
528
|
|
|
@@ -483,4 +531,4 @@ declare class Schema {
|
|
|
483
531
|
static dropIfExists(table: string): string;
|
|
484
532
|
}
|
|
485
533
|
|
|
486
|
-
export { BelongsTo, Blueprint, Connection, type D1Database, type D1ExecResult, type D1PreparedStatement, type D1Result, type D1Value, Database, HasMany, HasOne, Model, ModelQueryBuilder, QueryBuilder, Relationship, Schema };
|
|
534
|
+
export { BelongsTo, Blueprint, Column, Connection, type D1Database, type D1ExecResult, type D1PreparedStatement, type D1Result, type D1Value, Database, HasMany, HasOne, Model, ModelQueryBuilder, QueryBuilder, Relationship, Schema };
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
BelongsTo: () => BelongsTo,
|
|
24
24
|
Blueprint: () => Blueprint,
|
|
25
|
+
Column: () => Column,
|
|
25
26
|
Connection: () => Connection,
|
|
26
27
|
Database: () => Database,
|
|
27
28
|
HasMany: () => HasMany,
|
|
@@ -716,6 +717,55 @@ var Model = class {
|
|
|
716
717
|
};
|
|
717
718
|
|
|
718
719
|
// src/database/blueprint.ts
|
|
720
|
+
var Column = class {
|
|
721
|
+
name;
|
|
722
|
+
type;
|
|
723
|
+
isNullable = false;
|
|
724
|
+
isUnique = false;
|
|
725
|
+
defaultValue = null;
|
|
726
|
+
constructor(name, type) {
|
|
727
|
+
this.name = name;
|
|
728
|
+
this.type = type;
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Set the column as nullable.
|
|
732
|
+
*/
|
|
733
|
+
nullable() {
|
|
734
|
+
this.isNullable = true;
|
|
735
|
+
return this;
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Set the column as unique.
|
|
739
|
+
*/
|
|
740
|
+
unique() {
|
|
741
|
+
this.isUnique = true;
|
|
742
|
+
return this;
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Set the default value for the column.
|
|
746
|
+
*/
|
|
747
|
+
default(value) {
|
|
748
|
+
this.defaultValue = value;
|
|
749
|
+
return this;
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Convert the column definition to SQL.
|
|
753
|
+
*/
|
|
754
|
+
toSql() {
|
|
755
|
+
let sql = `${this.name} ${this.type}`;
|
|
756
|
+
if (this.isUnique) {
|
|
757
|
+
sql += " UNIQUE";
|
|
758
|
+
}
|
|
759
|
+
if (!this.isNullable) {
|
|
760
|
+
sql += " NOT NULL";
|
|
761
|
+
}
|
|
762
|
+
if (this.defaultValue !== null) {
|
|
763
|
+
const formattedValue = typeof this.defaultValue === "string" ? `'${this.defaultValue}'` : this.defaultValue;
|
|
764
|
+
sql += ` DEFAULT ${formattedValue}`;
|
|
765
|
+
}
|
|
766
|
+
return sql;
|
|
767
|
+
}
|
|
768
|
+
};
|
|
719
769
|
var Blueprint = class {
|
|
720
770
|
table;
|
|
721
771
|
columns = [];
|
|
@@ -723,30 +773,55 @@ var Blueprint = class {
|
|
|
723
773
|
constructor(table) {
|
|
724
774
|
this.table = table;
|
|
725
775
|
}
|
|
776
|
+
/**
|
|
777
|
+
* Add an auto-incrementing ID column.
|
|
778
|
+
*/
|
|
726
779
|
id() {
|
|
727
780
|
this.columns.push("id INTEGER PRIMARY KEY AUTOINCREMENT");
|
|
728
781
|
return this;
|
|
729
782
|
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
783
|
+
/**
|
|
784
|
+
* Add a string (TEXT) column.
|
|
785
|
+
*/
|
|
786
|
+
string(column) {
|
|
787
|
+
const col = new Column(column, "TEXT");
|
|
788
|
+
this.columns.push(col);
|
|
789
|
+
return col;
|
|
733
790
|
}
|
|
791
|
+
/**
|
|
792
|
+
* Add an integer column.
|
|
793
|
+
*/
|
|
734
794
|
integer(column) {
|
|
735
|
-
|
|
736
|
-
|
|
795
|
+
const col = new Column(column, "INTEGER");
|
|
796
|
+
this.columns.push(col);
|
|
797
|
+
return col;
|
|
737
798
|
}
|
|
799
|
+
/**
|
|
800
|
+
* Add a boolean column.
|
|
801
|
+
*/
|
|
738
802
|
boolean(column) {
|
|
739
|
-
|
|
740
|
-
|
|
803
|
+
const col = new Column(column, "BOOLEAN");
|
|
804
|
+
this.columns.push(col);
|
|
805
|
+
return col;
|
|
741
806
|
}
|
|
807
|
+
/**
|
|
808
|
+
* Add created_at and updated_at timestamp columns.
|
|
809
|
+
*/
|
|
742
810
|
timestamps() {
|
|
743
811
|
this.columns.push("created_at DATETIME DEFAULT CURRENT_TIMESTAMP");
|
|
744
812
|
this.columns.push("updated_at DATETIME DEFAULT CURRENT_TIMESTAMP");
|
|
745
813
|
return this;
|
|
746
814
|
}
|
|
815
|
+
/**
|
|
816
|
+
* Convert the blueprint to a set of SQL statements.
|
|
817
|
+
*/
|
|
747
818
|
toSql() {
|
|
748
819
|
if (this.columns.length > 0) {
|
|
749
|
-
const
|
|
820
|
+
const colDefinitions = this.columns.map((col) => {
|
|
821
|
+
if (typeof col === "string") return col;
|
|
822
|
+
return col.toSql();
|
|
823
|
+
});
|
|
824
|
+
const cols = colDefinitions.join(", ");
|
|
750
825
|
return [`CREATE TABLE IF NOT EXISTS ${this.table} (${cols})`];
|
|
751
826
|
}
|
|
752
827
|
return this.commands;
|
|
@@ -768,6 +843,7 @@ var Schema = class {
|
|
|
768
843
|
0 && (module.exports = {
|
|
769
844
|
BelongsTo,
|
|
770
845
|
Blueprint,
|
|
846
|
+
Column,
|
|
771
847
|
Connection,
|
|
772
848
|
Database,
|
|
773
849
|
HasMany,
|
package/dist/index.mjs
CHANGED
|
@@ -682,6 +682,55 @@ var Model = class {
|
|
|
682
682
|
};
|
|
683
683
|
|
|
684
684
|
// src/database/blueprint.ts
|
|
685
|
+
var Column = class {
|
|
686
|
+
name;
|
|
687
|
+
type;
|
|
688
|
+
isNullable = false;
|
|
689
|
+
isUnique = false;
|
|
690
|
+
defaultValue = null;
|
|
691
|
+
constructor(name, type) {
|
|
692
|
+
this.name = name;
|
|
693
|
+
this.type = type;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Set the column as nullable.
|
|
697
|
+
*/
|
|
698
|
+
nullable() {
|
|
699
|
+
this.isNullable = true;
|
|
700
|
+
return this;
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Set the column as unique.
|
|
704
|
+
*/
|
|
705
|
+
unique() {
|
|
706
|
+
this.isUnique = true;
|
|
707
|
+
return this;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Set the default value for the column.
|
|
711
|
+
*/
|
|
712
|
+
default(value) {
|
|
713
|
+
this.defaultValue = value;
|
|
714
|
+
return this;
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Convert the column definition to SQL.
|
|
718
|
+
*/
|
|
719
|
+
toSql() {
|
|
720
|
+
let sql = `${this.name} ${this.type}`;
|
|
721
|
+
if (this.isUnique) {
|
|
722
|
+
sql += " UNIQUE";
|
|
723
|
+
}
|
|
724
|
+
if (!this.isNullable) {
|
|
725
|
+
sql += " NOT NULL";
|
|
726
|
+
}
|
|
727
|
+
if (this.defaultValue !== null) {
|
|
728
|
+
const formattedValue = typeof this.defaultValue === "string" ? `'${this.defaultValue}'` : this.defaultValue;
|
|
729
|
+
sql += ` DEFAULT ${formattedValue}`;
|
|
730
|
+
}
|
|
731
|
+
return sql;
|
|
732
|
+
}
|
|
733
|
+
};
|
|
685
734
|
var Blueprint = class {
|
|
686
735
|
table;
|
|
687
736
|
columns = [];
|
|
@@ -689,30 +738,55 @@ var Blueprint = class {
|
|
|
689
738
|
constructor(table) {
|
|
690
739
|
this.table = table;
|
|
691
740
|
}
|
|
741
|
+
/**
|
|
742
|
+
* Add an auto-incrementing ID column.
|
|
743
|
+
*/
|
|
692
744
|
id() {
|
|
693
745
|
this.columns.push("id INTEGER PRIMARY KEY AUTOINCREMENT");
|
|
694
746
|
return this;
|
|
695
747
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
748
|
+
/**
|
|
749
|
+
* Add a string (TEXT) column.
|
|
750
|
+
*/
|
|
751
|
+
string(column) {
|
|
752
|
+
const col = new Column(column, "TEXT");
|
|
753
|
+
this.columns.push(col);
|
|
754
|
+
return col;
|
|
699
755
|
}
|
|
756
|
+
/**
|
|
757
|
+
* Add an integer column.
|
|
758
|
+
*/
|
|
700
759
|
integer(column) {
|
|
701
|
-
|
|
702
|
-
|
|
760
|
+
const col = new Column(column, "INTEGER");
|
|
761
|
+
this.columns.push(col);
|
|
762
|
+
return col;
|
|
703
763
|
}
|
|
764
|
+
/**
|
|
765
|
+
* Add a boolean column.
|
|
766
|
+
*/
|
|
704
767
|
boolean(column) {
|
|
705
|
-
|
|
706
|
-
|
|
768
|
+
const col = new Column(column, "BOOLEAN");
|
|
769
|
+
this.columns.push(col);
|
|
770
|
+
return col;
|
|
707
771
|
}
|
|
772
|
+
/**
|
|
773
|
+
* Add created_at and updated_at timestamp columns.
|
|
774
|
+
*/
|
|
708
775
|
timestamps() {
|
|
709
776
|
this.columns.push("created_at DATETIME DEFAULT CURRENT_TIMESTAMP");
|
|
710
777
|
this.columns.push("updated_at DATETIME DEFAULT CURRENT_TIMESTAMP");
|
|
711
778
|
return this;
|
|
712
779
|
}
|
|
780
|
+
/**
|
|
781
|
+
* Convert the blueprint to a set of SQL statements.
|
|
782
|
+
*/
|
|
713
783
|
toSql() {
|
|
714
784
|
if (this.columns.length > 0) {
|
|
715
|
-
const
|
|
785
|
+
const colDefinitions = this.columns.map((col) => {
|
|
786
|
+
if (typeof col === "string") return col;
|
|
787
|
+
return col.toSql();
|
|
788
|
+
});
|
|
789
|
+
const cols = colDefinitions.join(", ");
|
|
716
790
|
return [`CREATE TABLE IF NOT EXISTS ${this.table} (${cols})`];
|
|
717
791
|
}
|
|
718
792
|
return this.commands;
|
|
@@ -733,6 +807,7 @@ var Schema = class {
|
|
|
733
807
|
export {
|
|
734
808
|
BelongsTo,
|
|
735
809
|
Blueprint,
|
|
810
|
+
Column,
|
|
736
811
|
Connection,
|
|
737
812
|
Database,
|
|
738
813
|
HasMany,
|