172 lines
3 KiB
TypeScript
172 lines
3 KiB
TypeScript
import type { ColumnShorthand } from "./columns";
|
|
import type { Table } from "./table";
|
|
|
|
export const ColumnOf = {
|
|
PrimaryKey: {
|
|
type: "INTEGER",
|
|
primary: true,
|
|
autoincrement: true,
|
|
},
|
|
|
|
Text: {
|
|
type: "TEXT",
|
|
nullable: false,
|
|
},
|
|
|
|
Int: {
|
|
type: "INTEGER",
|
|
nullable: false,
|
|
},
|
|
|
|
Real: {
|
|
type: "REAL",
|
|
nullable: false,
|
|
},
|
|
|
|
Blob: {
|
|
type: "BLOB",
|
|
nullable: false,
|
|
},
|
|
|
|
ForeignKey(otherTable: Table<unknown>, cascade = false): ColumnShorthand {
|
|
return {
|
|
type: otherTable.primaryColumnType(),
|
|
references: otherTable.reference(),
|
|
nullable: false,
|
|
cascade,
|
|
};
|
|
},
|
|
|
|
Nullable: {
|
|
Text: {
|
|
type: "TEXT",
|
|
nullable: true,
|
|
},
|
|
|
|
Int: {
|
|
type: "INTEGER",
|
|
nullable: true,
|
|
},
|
|
|
|
Real: {
|
|
type: "REAL",
|
|
nullable: true,
|
|
},
|
|
|
|
Blob: {
|
|
type: "BLOB",
|
|
nullable: true,
|
|
},
|
|
|
|
ForeignKey(otherTable: Table<unknown>, cascade = false): ColumnShorthand {
|
|
return {
|
|
type: otherTable.primaryColumnType(),
|
|
references: otherTable.reference(),
|
|
nullable: true,
|
|
cascade,
|
|
};
|
|
},
|
|
|
|
Unique: {
|
|
Text: {
|
|
type: "TEXT",
|
|
nullable: true,
|
|
unique: true,
|
|
},
|
|
|
|
Int: {
|
|
type: "INTEGER",
|
|
nullable: true,
|
|
unique: true,
|
|
},
|
|
|
|
Real: {
|
|
type: "REAL",
|
|
nullable: true,
|
|
unique: true,
|
|
},
|
|
|
|
Blob: {
|
|
type: "BLOB",
|
|
nullable: true,
|
|
unique: true,
|
|
},
|
|
|
|
ForeignKey(otherTable: Table<unknown>, cascade = false): ColumnShorthand {
|
|
return {
|
|
type: otherTable.primaryColumnType(),
|
|
references: otherTable.reference(),
|
|
nullable: true,
|
|
unique: true,
|
|
cascade,
|
|
};
|
|
},
|
|
},
|
|
},
|
|
|
|
Unique: {
|
|
Text: {
|
|
type: "TEXT",
|
|
nullable: false,
|
|
unique: true,
|
|
},
|
|
|
|
Int: {
|
|
type: "INTEGER",
|
|
nullable: false,
|
|
unique: true,
|
|
},
|
|
|
|
Real: {
|
|
type: "REAL",
|
|
nullable: false,
|
|
unique: true,
|
|
},
|
|
|
|
Blob: {
|
|
type: "BLOB",
|
|
nullable: false,
|
|
unique: true,
|
|
},
|
|
|
|
ForeignKey(otherTable: Table<unknown>, cascade = false): ColumnShorthand {
|
|
return {
|
|
type: otherTable.primaryColumnType(),
|
|
references: otherTable.reference(),
|
|
nullable: false,
|
|
unique: true,
|
|
cascade,
|
|
};
|
|
},
|
|
},
|
|
|
|
Defaulted: {
|
|
Text(defaultValue: string): ColumnShorthand {
|
|
return {
|
|
type: "TEXT",
|
|
default: defaultValue,
|
|
};
|
|
},
|
|
|
|
Int(defaultValue: number): ColumnShorthand {
|
|
return {
|
|
type: "INTEGER",
|
|
default: defaultValue,
|
|
} as const;
|
|
},
|
|
|
|
Real(defaultValue: number): ColumnShorthand {
|
|
return {
|
|
type: "REAL",
|
|
default: defaultValue,
|
|
} as const;
|
|
},
|
|
|
|
Blob(defaultValue: string): ColumnShorthand {
|
|
return {
|
|
type: "BLOB",
|
|
default: defaultValue,
|
|
} as const;
|
|
},
|
|
},
|
|
} as const;
|