UNPKG

@palmares/drizzle-engine

Version:

This is the engine that wraps the hole drizzle interface in a way palmares can understand and have full control of

150 lines (146 loc) 4.34 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); // src/fields/custom-fields/sqlite.ts import { Field, TextField } from "@palmares/databases"; // src/fields/custom-fields/utils.ts var DefaultBuilder = class _DefaultBuilder { static { __name(this, "DefaultBuilder"); } _; constructor(fieldInstance, type) { this._ = { field: fieldInstance, type }; } $type() { return this._.field._setPartialAttributes()(this._.field["__customAttributes"])._setNewBuilderMethods(new _DefaultBuilder(this._.field, this._.type)); } $default(cb) { return this._.field._setPartialAttributes()({ type: this._.type, args: this._.field["__customAttributes"]?.["args"], options: { ...this._.field["__customAttributes"]?.["options"] || {}, $default: [ cb ] } })._setNewBuilderMethods(new _DefaultBuilder(this._.field, this._.type)); } $onUpdate(cb) { return this._.field._setPartialAttributes()({ type: this._.type, args: this._.field["__customAttributes"]?.["args"], options: { ...this._.field["__customAttributes"]?.["options"] || {}, $onUpdate: [ cb ] } })._setNewBuilderMethods(new _DefaultBuilder(this._.field, this._.type)); } references(cb) { return this._.field._setPartialAttributes()({ type: this._.type, args: this._.field["__customAttributes"]?.["args"], options: { ...this._.field["__customAttributes"]?.["options"] || {}, references: [ cb ] } })._setNewBuilderMethods(new _DefaultBuilder(this._.field, this._.type)); } primaryKey() { return this._.field._setPartialAttributes()({ type: this._.type, args: this._.field["__customAttributes"]?.["args"], options: { ...this._.field["__customAttributes"]?.["options"] || {}, primaryKey: true } })._setNewBuilderMethods(new _DefaultBuilder(this._.field, this._.type)); } unique() { return this._.field._setPartialAttributes()({ type: this._.type, args: this._.field["__customAttributes"]?.["args"], options: { ...this._.field["__customAttributes"]?.["options"] || {}, unique: true } })._setNewBuilderMethods(new _DefaultBuilder(this._.field, this._.type)); } notNull() { return this._.field._setPartialAttributes()({ type: this._.type, args: this._.field["__customAttributes"]?.["args"], options: { ...this._.field["__customAttributes"]?.["options"] || {}, notNull: [] } })._setNewBuilderMethods(new _DefaultBuilder(this._.field, this._.type)); } generatedAlwaysAs(cb) { return this._.field._setPartialAttributes()({ type: this._.type, args: this._.field["__customAttributes"]?.["args"], options: { ...this._.field["__customAttributes"]?.["options"] || {}, generatedAlwaysAs: [ cb ] } })._setNewBuilderMethods(new _DefaultBuilder(this._.field, this._.type)); } }; // src/fields/custom-fields/sqlite.ts function real() { const RealField = Field._overrideType({ typeName: "real" }); const instance = RealField.new({}).allowNull(false); return instance._setNewBuilderMethods(); } __name(real, "real"); function integer(args) { const IntegerField = Field._overrideType({ typeName: "integer" }); const instance = IntegerField.new({}).allowNull(false); instance["__customAttributes"] = { args }; return instance._setNewBuilderMethods(); } __name(integer, "integer"); function text(args) { const CustomTextField = TextField._overrideType({ typeName: "text" }); const instance = CustomTextField.new({}).allowNull(false).allowBlank(true); instance["__customAttributes"] = { args }; return instance._setNewBuilderMethods(new DefaultBuilder(instance, "text")); } __name(text, "text"); function blob(args) { const CustomTextField = Field._overrideType({ typeName: "text" }); const instance = CustomTextField.new({}).allowNull(false); instance["__customAttributes"] = { args }; return instance._setNewBuilderMethods(); } __name(blob, "blob"); export { blob, integer, real, text };