Comparing version 0.0.5 to 0.0.6
@@ -256,3 +256,3 @@ // Generated by dts-bundle-generator v9.5.1 | ||
], metas: Meta[], refs: TypeRefs<Tables>); | ||
log(level?: "info" | "debug"): this; | ||
log(level?: "debug" | "verbose"): this; | ||
protected _where: { | ||
@@ -347,3 +347,3 @@ condition: string; | ||
}; | ||
toString(): string; | ||
toString(level?: "debug" | "verbose"): string; | ||
} | ||
@@ -422,2 +422,3 @@ export type SelectOptions = { | ||
(strings: TemplateStringsArray | string, ...params: any[]): Fragment; | ||
schema: Schema; | ||
dialect: Dialect; | ||
@@ -611,2 +612,3 @@ quote: (name: string) => string; | ||
} | ||
export declare function Watch(fn: (() => Record<string, any>) | (() => void)): void; | ||
export declare function pick<T extends Record<string, any> | Record<string, any>[]>(input: T, keys: string[]): T extends Record<string, any>[] ? Record<string, any>[] : Record<string, any>; | ||
@@ -794,2 +796,3 @@ export declare function omit<T extends Record<string, any> | Record<string, any>[]>(input: T, keys: string[]): T extends Record<string, any>[] ? Record<string, any>[] : Record<string, any>; | ||
(strings: string | TemplateStringsArray, ...params: any[]): Fragment; | ||
schema: Schema; | ||
dialect: Dialect; | ||
@@ -823,2 +826,3 @@ quote: (name: string) => string; | ||
(strings: string | TemplateStringsArray, ...params: any[]): Fragment; | ||
schema: Schema; | ||
dialect: Dialect; | ||
@@ -852,2 +856,3 @@ quote: (name: string) => string; | ||
(strings: string | TemplateStringsArray, ...params: any[]): Fragment; | ||
schema: Schema; | ||
dialect: Dialect; | ||
@@ -854,0 +859,0 @@ quote: (name: string) => string; |
@@ -117,5 +117,5 @@ // src/utils.ts | ||
else if (typeof table === "function" || typeof table.constructor === "function") | ||
throw new Error(`${name} is not a class or constructor function`); | ||
throw new Error(`${name} is not a Table class, missing @table?`); | ||
else | ||
throw new Error(`${name} does not contain metadata, missing @table?`); | ||
throw new Error(`${name} is not a Table class with metadata, missing @table?`); | ||
} | ||
@@ -130,3 +130,3 @@ return cls; | ||
if (!cls.$props || !cls.$props.find((x) => x.column)) { | ||
throw new Error(`${cls.name} does not have any @column annotations`); | ||
throw new Error(`${cls.name} does not have any columns, mssing @column?`); | ||
} | ||
@@ -251,6 +251,6 @@ return cls; | ||
const meta = Meta.assertMeta(table); | ||
let props = meta.props.filter((x) => x.column); | ||
if (options?.onlyProps) { | ||
props = props.filter((c) => options.onlyProps.includes(c.name) || c.column?.primaryKey); | ||
} | ||
let props = options?.onlyProps ? meta.props.filter((c) => options.onlyProps.includes(c.name) || c.column?.primaryKey) : meta.props.filter((x) => x.column); | ||
const primaryKeys = props.filter((c) => c.column?.primaryKey); | ||
if (!primaryKeys.length) | ||
throw new Error(`${meta.name} does not have a PRIMARY KEY`); | ||
const columns = props.map((x) => x.column); | ||
@@ -334,3 +334,3 @@ const setColumns = columns.filter((c) => !c.primaryKey); | ||
this.driver = connection.driver; | ||
this.schema = connection.driver.schema; | ||
this.schema = this.$.schema = connection.driver.schema; | ||
} | ||
@@ -412,3 +412,3 @@ get sync() { | ||
this.driver = connection.driver; | ||
this.schema = connection.driver.schema; | ||
this.schema = this.$.schema = connection.driver.schema; | ||
} | ||
@@ -581,3 +581,3 @@ quote(symbol) { | ||
this.$ = driver.$; | ||
this.schema = driver.schema; | ||
this.schema = this.$.schema = driver.schema; | ||
this.dialect = driver.dialect; | ||
@@ -692,3 +692,3 @@ this.async = new DbConnection(this); | ||
let to = JSON.stringify(obj, null, 4); | ||
return to.replace(/"/g, ""); | ||
return to.replace(/\\"/g, ""); | ||
} | ||
@@ -735,2 +735,24 @@ static printDump(obj) { | ||
} | ||
function Watch(fn) { | ||
try { | ||
const results = fn(); | ||
if (!results) | ||
return; | ||
for (const key in results) { | ||
console.log(`${key}:`); | ||
const val = results[key]; | ||
if (Array.isArray(val)) { | ||
console.table(val); | ||
} else { | ||
if (typeof val != "object") | ||
console.log(toStr(val).trim()); | ||
else | ||
console.log(Inspect.dump(val)); | ||
} | ||
console.log(); | ||
} | ||
} catch (e) { | ||
console.error(`${e}`); | ||
} | ||
} | ||
@@ -788,2 +810,3 @@ // src/sql.ts | ||
} | ||
$.schema = new Schema(dialect); | ||
$.dialect = dialect; | ||
@@ -983,16 +1006,4 @@ $.quote = dialect.quote.bind(dialect); | ||
} | ||
log(level = "info") { | ||
if (level == "debug") { | ||
const debug = this.toString(); | ||
const to = { | ||
refs: this.refs.map((x) => x.$ref).map((r) => [Meta.assertMeta(r.cls).tableName, r.as].filter((x) => !!x).join(" ")) | ||
}; | ||
for (const [key, val] of Object.entries(this)) { | ||
if (key[0] == "_" && Array.isArray(val) && val.length) { | ||
to[key.substring(1)] = val; | ||
} | ||
} | ||
console.log([debug.trimEnd(), Inspect.dump(to).replaceAll("\\", ""), ""].join("\n")); | ||
} else | ||
console.log(Inspect.dump(this)); | ||
log(level) { | ||
console.log(this.toString(level)); | ||
return this; | ||
@@ -1276,7 +1287,9 @@ } | ||
} | ||
toString() { | ||
toString(level) { | ||
const ret = this.build(); | ||
if (level != "debug" && level != "verbose") | ||
return Inspect.dump(ret); | ||
const { into } = ret; | ||
const intoName = into && (into.name || into.$type && into.$type.name || into.constructor.name) || ""; | ||
return [ | ||
const debug = [ | ||
Inspect.dump(ret).trim(), | ||
@@ -1289,2 +1302,17 @@ [ | ||
].join("\n"); | ||
if (level === "verbose") { | ||
const to = { | ||
refs: this.refs.map((x) => x.$ref).map((r) => [ | ||
Meta.assertMeta(r.cls).tableName, | ||
r.as != this.quote(Meta.assertMeta(r.cls).tableName) ? r.as : "" | ||
].filter((x) => !!x).join(" ")) | ||
}; | ||
for (const [key, val] of Object.entries(this)) { | ||
if (key[0] == "_" && Array.isArray(val) && val.length) { | ||
to[key.substring(1)] = val; | ||
} | ||
} | ||
return [debug.trimEnd(), Inspect.dump(to).replaceAll('"', ""), ""].join("\n"); | ||
} | ||
return debug; | ||
} | ||
@@ -1667,3 +1695,4 @@ } | ||
const unique = column2.unique ? "UNIQUE INDEX" : "INDEX"; | ||
return `CREATE ${unique} idx_${table2.name}_${column2.name} ON ${this.dialect.quoteTable(table2.name)} (${this.dialect.quoteColumn(column2.name)})`; | ||
const name = `idx_${table2.name}_${column2.name}`.toLowerCase(); | ||
return `CREATE ${unique} ${name} ON ${this.dialect.quoteTable(table2.name)} (${this.dialect.quoteColumn(column2.name)})`; | ||
} | ||
@@ -1774,3 +1803,3 @@ sqlColumnDefinition(column2) { | ||
this.types = new SqliteTypes; | ||
this.schema = new SqliteSchema(this); | ||
this.schema = this.$.schema = new SqliteSchema(this); | ||
} | ||
@@ -1867,3 +1896,3 @@ } | ||
this.types = new MySqlTypes; | ||
this.schema = new MySqlSchema(this); | ||
this.schema = this.$.schema = new MySqlSchema(this); | ||
} | ||
@@ -1950,3 +1979,3 @@ } | ||
this.types = new PostgreSqlTypes; | ||
this.schema = new PostgreSqlSchema(this); | ||
this.schema = this.$.schema = new PostgreSqlSchema(this); | ||
} | ||
@@ -1984,2 +2013,3 @@ } | ||
WhereQuery, | ||
Watch, | ||
UpdateQuery, | ||
@@ -1986,0 +2016,0 @@ Table, |
@@ -1,7 +0,7 @@ | ||
function isDate(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!isNaN(e)}function toDate(e){return e?isDate(e)?e:"/"==e[0]?new Date(parseFloat(/Date\(([^)]+)\)/.exec(e)[1])):new Date(e):null}function propsWithValues(t){return Object.keys(t).filter(e=>null!=t[e])}function uniqueKeys(e){let t=[];return e.forEach(e=>Object.keys(e).forEach(e=>{-1===t.indexOf(e)&&t.push(e)})),t}function pick(r,e){return Array.isArray(r)?r.map(r=>e.reduce((e,t)=>({...e,[t]:r[t]}),{})):e.reduce((e,t)=>({...e,[t]:r[t]}),{})}function omit(e,r){if(Array.isArray(e))return e.map(e=>{let t={...e};return r.forEach(e=>delete t[e]),t});let t={...e};return r.forEach(e=>delete t[e]),t}function leftPart(e,t){return null==e?null:-1==(t=e.indexOf(t))?e:e.substring(0,t)}function toStr(e){return"symbol"==typeof e?":"+(e.description??""):""+e}function nextParam(e){e=Object.keys(e).map(e=>"_"===e[0]?parseInt(e.substring(1)):NaN).filter(e=>!isNaN(e));return"_"+(0==e.length?1:Math.max(...e)+1)}function mergeParams(e,t){let r=t.sql;if(t.params&&"object"==typeof t.params)for(var[s,n]of Object.entries(t.params)){var i;s in e&&"_"===s[0]&&!isNaN(parseInt(s.substring(1)))?(i=nextParam(e),r=r.replaceAll("$"+s,"$"+i),e[i]=n):e[s]=n}return r}function asType(e){if("object"!=typeof e&&"function"!=typeof e)throw new Error("invalid argument: "+typeof e);var t=e.$ref?e:void 0;return!e?.$ref&&e.tables?e.table:t?t.$ref.cls:e}function asRef(e){return"object"==typeof e&&e.$ref?e:void 0}function isTemplateStrings(e){return Array.isArray(e)&&"raw"in e}function snakeCase(e){return(e||"").replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase()}function clsName(e,...t){return t&&t.length?`${e}<${Array.from(t).map(e=>"string"==typeof e?e:"name"in e?e.name:"constructor"in e&&"name"in e.constructor?e.constructor.name:"").join(",")}>`:e}var type=Symbol("type");class Meta{cls;static metadata={};constructor(e){if(!(this.cls=e))throw new Error("Class must be provided");if(!e.$type)throw new Error(`Class ${e.name??e} have a $type property`)}static assertClass(e){if(!e)throw new Error("Class must be provided");var t=e?.constructor?.$id?e?.constructor:e.$id?e:null;if(t)return t;throw(t=e?.name??e?.constructor?.name)?"function"==typeof e||"function"==typeof e.constructor?new Error(t+" is not a class or constructor function"):new Error(t+" does not contain metadata, missing @table?"):new Error("Class or constructor function required")}static assertTable(e){e=Meta.assertClass(e);if(!e.$type?.table)throw new Error(e.name+" does not have a @table annotation");if(e.$props&&e.$props.find(e=>e.column))return e;throw new Error(e.name+" does not have any @column annotations")}static assertMeta(e){var e=Meta.assertClass(e),t=e.$id;return Meta.metadata[t]??(Meta.metadata[t]=new Meta(Meta.assertTable(e)))}get name(){return this.cls.$type?.name??this.cls.name}get tableName(){var e=this.cls,t=e.$type?.table?.alias??e.$type?.name??e.name;if(t)return t;throw new Error("Table name not found for "+e.name)}get type(){return this.cls.$type}get table(){var e=this.type.table;if(e)return e;throw new Error("Table definition not found for "+this.cls.name)}get props(){return this.cls.$props??[]}get columns(){return this.props.filter(e=>e.column).map(e=>e.column)}}function converterFor(e,...t){var r,s={};for(r of t)s[r]=e;return s}class DateTimeConverter{static instance=new DateTimeConverter;toDb(e){e=toDate(e);return e?e.toISOString():null}fromDb(e){return e?toDate(e):null}}var DataType,DriverRequired="Missing Driver Implementation, see: https://github.com/litdb/litdb",DriverRequiredProxy=new Proxy({},{get:(e,t)=>{throw new Error(DriverRequired)}});function assertSql(e){if("object"==typeof e&&e.sql)return e;throw e="symbol"==typeof e?e.description:Array.isArray(e)?"Array":""+e,new Error("Expected sql`...` fragment, received: "+e)}class Schema{dialect;constructor(e){this.dialect=e}converters={...converterFor(DateTimeConverter.instance,"DATE","DATETIME","TIMESTAMP","TIMESTAMPZ")};sqlTableNames(e){throw new Error(DriverRequired)}sqlColumnDefinition(e){throw new Error(DriverRequired)}sqlIndexDefinition(e,t){throw new Error(DriverRequired)}dropTable(e){e=Meta.assertMeta(e);return"DROP TABLE IF EXISTS "+this.dialect.quoteTable(e.tableName)}createTable(e){let t=Meta.assertMeta(e);var e=t.columns,r=e.map(e=>""+this.sqlColumnDefinition(e)).join(",\n ");let s=`CREATE TABLE ${this.dialect.quoteTable(t.tableName)} ( | ||
function isDate(e){return e&&"[object Date]"===Object.prototype.toString.call(e)&&!isNaN(e)}function toDate(e){return e?isDate(e)?e:"/"==e[0]?new Date(parseFloat(/Date\(([^)]+)\)/.exec(e)[1])):new Date(e):null}function propsWithValues(t){return Object.keys(t).filter(e=>null!=t[e])}function uniqueKeys(e){let t=[];return e.forEach(e=>Object.keys(e).forEach(e=>{-1===t.indexOf(e)&&t.push(e)})),t}function pick(r,e){return Array.isArray(r)?r.map(r=>e.reduce((e,t)=>({...e,[t]:r[t]}),{})):e.reduce((e,t)=>({...e,[t]:r[t]}),{})}function omit(e,r){if(Array.isArray(e))return e.map(e=>{let t={...e};return r.forEach(e=>delete t[e]),t});let t={...e};return r.forEach(e=>delete t[e]),t}function leftPart(e,t){return null==e?null:-1==(t=e.indexOf(t))?e:e.substring(0,t)}function toStr(e){return"symbol"==typeof e?":"+(e.description??""):""+e}function nextParam(e){e=Object.keys(e).map(e=>"_"===e[0]?parseInt(e.substring(1)):NaN).filter(e=>!isNaN(e));return"_"+(0==e.length?1:Math.max(...e)+1)}function mergeParams(e,t){let r=t.sql;if(t.params&&"object"==typeof t.params)for(var[s,n]of Object.entries(t.params)){var i;s in e&&"_"===s[0]&&!isNaN(parseInt(s.substring(1)))?(i=nextParam(e),r=r.replaceAll("$"+s,"$"+i),e[i]=n):e[s]=n}return r}function asType(e){if("object"!=typeof e&&"function"!=typeof e)throw new Error("invalid argument: "+typeof e);var t=e.$ref?e:void 0;return!e?.$ref&&e.tables?e.table:t?t.$ref.cls:e}function asRef(e){return"object"==typeof e&&e.$ref?e:void 0}function isTemplateStrings(e){return Array.isArray(e)&&"raw"in e}function snakeCase(e){return(e||"").replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase()}function clsName(e,...t){return t&&t.length?`${e}<${Array.from(t).map(e=>"string"==typeof e?e:"name"in e?e.name:"constructor"in e&&"name"in e.constructor?e.constructor.name:"").join(",")}>`:e}var type=Symbol("type");class Meta{cls;static metadata={};constructor(e){if(!(this.cls=e))throw new Error("Class must be provided");if(!e.$type)throw new Error(`Class ${e.name??e} have a $type property`)}static assertClass(e){if(!e)throw new Error("Class must be provided");var t=e?.constructor?.$id?e?.constructor:e.$id?e:null;if(t)return t;throw(t=e?.name??e?.constructor?.name)?"function"==typeof e||"function"==typeof e.constructor?new Error(t+" is not a Table class, missing @table?"):new Error(t+" is not a Table class with metadata, missing @table?"):new Error("Class or constructor function required")}static assertTable(e){e=Meta.assertClass(e);if(!e.$type?.table)throw new Error(e.name+" does not have a @table annotation");if(e.$props&&e.$props.find(e=>e.column))return e;throw new Error(e.name+" does not have any columns, mssing @column?")}static assertMeta(e){var e=Meta.assertClass(e),t=e.$id;return Meta.metadata[t]??(Meta.metadata[t]=new Meta(Meta.assertTable(e)))}get name(){return this.cls.$type?.name??this.cls.name}get tableName(){var e=this.cls,t=e.$type?.table?.alias??e.$type?.name??e.name;if(t)return t;throw new Error("Table name not found for "+e.name)}get type(){return this.cls.$type}get table(){var e=this.type.table;if(e)return e;throw new Error("Table definition not found for "+this.cls.name)}get props(){return this.cls.$props??[]}get columns(){return this.props.filter(e=>e.column).map(e=>e.column)}}function converterFor(e,...t){var r,s={};for(r of t)s[r]=e;return s}class DateTimeConverter{static instance=new DateTimeConverter;toDb(e){e=toDate(e);return e?e.toISOString():null}fromDb(e){return e?toDate(e):null}}var DataType,DriverRequired="Missing Driver Implementation, see: https://github.com/litdb/litdb",DriverRequiredProxy=new Proxy({},{get:(e,t)=>{throw new Error(DriverRequired)}});function assertSql(e){if("object"==typeof e&&e.sql)return e;throw e="symbol"==typeof e?e.description:Array.isArray(e)?"Array":""+e,new Error("Expected sql`...` fragment, received: "+e)}class Schema{dialect;constructor(e){this.dialect=e}converters={...converterFor(DateTimeConverter.instance,"DATE","DATETIME","TIMESTAMP","TIMESTAMPZ")};sqlTableNames(e){throw new Error(DriverRequired)}sqlColumnDefinition(e){throw new Error(DriverRequired)}sqlIndexDefinition(e,t){throw new Error(DriverRequired)}dropTable(e){e=Meta.assertMeta(e);return"DROP TABLE IF EXISTS "+this.dialect.quoteTable(e.tableName)}createTable(e){let t=Meta.assertMeta(e);var e=t.columns,r=e.map(e=>""+this.sqlColumnDefinition(e)).join(",\n ");let s=`CREATE TABLE ${this.dialect.quoteTable(t.tableName)} ( | ||
${r} | ||
); | ||
`;r=e.filter(e=>e.index).map(e=>this.sqlIndexDefinition(t.table,e)+";");return 0<r.length&&(s+=r.join("\n")),s}insert(e,t){e=Meta.assertMeta(e);let r=e.props.filter(e=>e.column);var s=(r=t?.onlyProps?r.filter(e=>t.onlyProps.includes(e.name)):r).map(e=>e.column).filter(e=>!e.autoIncrement),n=s.map(e=>""+this.dialect.quoteColumn(e.name)).join(", "),s=s.map(e=>"$"+e.name).join(", ");return`INSERT INTO ${this.dialect.quoteTable(e.tableName)} (${n}) VALUES (${s})`}update(e,t){e=Meta.assertMeta(e);let r=e.props.filter(e=>e.column);var s=(r=t?.onlyProps?r.filter(e=>t.onlyProps.includes(e.name)||e.column?.primaryKey):r).map(e=>e.column),n=s.filter(e=>!e.primaryKey),s=s.filter(e=>e.primaryKey),n=n.map(e=>this.dialect.quoteColumn(e.name)+"=$"+e.name).join(", "),s=s.map(e=>this.dialect.quoteColumn(e.name)+" = $"+e.name).join(" AND ");let i=`UPDATE ${this.dialect.quoteTable(e.tableName)} SET `+n;if(s)return i+=" WHERE "+s;throw new Error("No WHERE clause exists for UPDATE "+e.tableName)}delete(e,t){var r,e=Meta.assertMeta(e);let s=e.props.filter(e=>e.column).map(e=>e.column).filter(e=>e.primaryKey).map(e=>this.dialect.quoteColumn(e.name)+" = $"+e.name).join(" AND "),n=(t?.where&&(r=s?" AND ":" WHERE ",t=Array.isArray(t.where)?t.where:[t.where],s+=r+t.join(" AND ")),"DELETE FROM "+this.dialect.quoteTable(e.tableName));if(s)return n+=" WHERE "+s;throw new Error("No WHERE clause exists for DELETE "+e.tableName)}toDbBindings(r){let s=[];return Meta.assertMeta(r.constructor).props.filter(e=>e.column).forEach(e=>{var t=r[e.column.name],e=this.converters[e.column.type];e?(e=e.toDb(t),s.push(e)):s.push(t)}),s}toDbObject(e,t){var r,s,n,i={};for(r of Meta.assertMeta(e.constructor).props.filter(e=>e.column))t?.onlyProps&&!t.onlyProps.includes(r.name)||(s=e[r.name],(n=this.converters[r.column.type])?(n=n.toDb(s),i[r.column.name]=n):i[r.column.name]=s);return i}}class DbConnection{connection;driver;$;schema;constructor(e){this.connection=e,this.$=e.$,this.driver=e.driver,this.schema=e.driver.schema}get sync(){if(null==this.driver.sync)throw new Error(this.$.name+" does not support sync APIs");return this.driver.sync}quote(e){return this.$.quote(e)}insert(e,t){return Promise.resolve(this.sync.insert(e,t))}insertAll(e,t){return Promise.resolve(this.sync.insertAll(e,t))}listTables(){return Promise.resolve(this.sync.listTables())}dropTable(e){return Promise.resolve(this.sync.dropTable(e))}createTable(e){return Promise.resolve(this.sync.createTable(e))}all(e,...t){return Promise.resolve(this.sync.all(e,...t))}one(e,...t){return Promise.resolve(this.sync.one(e,...t))}column(e,...t){return Promise.resolve(this.sync.column(e,...t))}value(e,...t){return Promise.resolve(this.sync.value(e,...t))}arrays(e,...t){return Promise.resolve(this.sync.arrays(e,...t))}array(e,...t){return Promise.resolve(this.sync.array(e,...t))}exec(e,...t){return Promise.resolve(this.sync.exec(e,...t))}run(e,...t){return Promise.resolve(this.sync.run(e,...t))}prepare(e,...t){if(isTemplateStrings(e))return[this.connection.prepare(e,...t),t];if("object"==typeof e){if("build"in e)return t=e.build(),[this.connection.prepare(t.sql),t.params];if("sql"in e)return[this.connection.prepare(e.sql),e.params??{}]}throw new Error("Invalid argument: "+toStr(e))}}class SyncDbConnection{connection;driver;$;schema;constructor(e){this.connection=e,this.$=e.$,this.driver=e.driver,this.schema=e.driver.schema}quote(e){return this.$.quote(e)}insert(e,t){var r,s;return e?(r=e.constructor,t?.onlyProps||t?.onlyWithValues?(t={onlyProps:t?.onlyProps??propsWithValues(e)},s=this.connection.prepareSync(this.schema.insert(r,t)),t=this.schema.toDbObject(e,t),s.execSync(t)):(s=this.connection.prepareSync(this.schema.insert(r)),t=this.schema.toDbObject(e),s.execSync(t))):{changes:0,lastInsertRowid:0}}insertAll(e,t){var r={changes:0,lastInsertRowid:0};if(0!=e.length){var s=e[0].constructor;if(t?.onlyProps||t?.onlyWithValues)for(var n of e){n=this.insert(n,t);r.changes+=n.changes,r.lastInsertRowid=n.lastInsertRowid}else{var i,a=this.connection.prepareSync(this.schema.insert(s));for(i of e){var o=this.schema.toDbObject(i),o=a.execSync(o);r.changes+=o.changes,r.lastInsertRowid=o.lastInsertRowid}}}return r}update(e,t){var r,s;return e?(r=e.constructor,t?.onlyProps||t?.onlyWithValues?(s=r.$props.filter(e=>e.column?.primaryKey).map(e=>e.column.name),t={onlyProps:Array.from(new Set([...t?.onlyProps??propsWithValues(e),...s]))},s=this.connection.prepareSync(this.schema.update(r,t)),t=this.schema.toDbObject(e,t),s.execSync(t)):(s=this.connection.prepareSync(this.schema.update(r)),t=this.schema.toDbObject(e),s.execSync(t))):{changes:0,lastInsertRowid:0}}delete(e,t){var r;return e?(r=e.constructor,t=this.connection.prepareSync(this.schema.delete(r,t)),r=Meta.assertMeta(r).props.filter(e=>e.column?.primaryKey).map(e=>e.name),e=this.schema.toDbObject(e,{onlyProps:r}),t.execSync(e)):{changes:0,lastInsertRowid:0}}listTables(){return this.column({sql:this.schema.sqlTableNames(),params:{}})}dropTable(e){return this.connection.prepareSync(this.schema.dropTable(e)).execSync()}createTable(e){return this.connection.prepareSync(this.schema.createTable(e)).execSync()}prepareSync(e,...t){var r;if(isTemplateStrings(e))return[this.connection.prepareSync(e,...t),t,void 0];if("object"==typeof e){if("build"in e)return t=e.build(),[this.connection.prepareSync(t.sql),t.params??{},t.into];if("sql"in e)return t=e.sql,r=e.params??{},[this.connection.prepareSync(t),r,e.into]}throw new Error("Invalid argument: "+toStr(e))}all(e,...t){var[e,t,r]=this.prepareSync(e,...t);return r?(r=e.as(r),Array.isArray(t)?r.allSync(...t):r.allSync(t)):Array.isArray(t)?e.allSync(...t):e.allSync(t)}one(e,...t){var[e,t,r]=this.prepareSync(e,...t);return r?(r=e.as(r),Array.isArray(t)?r.oneSync(...t):r.oneSync(t)):Array.isArray(t)?e.oneSync(...t):e.oneSync(t)}column(e,...t){var[e,t]=this.prepareSync(e,...t);return Array.isArray(t)?e.arraysSync(...t).map(e=>e[0]):e.arraysSync(t).map(e=>e[0])}value(e,...t){var[e,t,r]=this.prepareSync(e,...t),e=Array.isArray(t)?e.valueSync(...t):e.valueSync(t);return r&&r===Boolean?!!e:e}arrays(e,...t){var[e,t]=this.prepareSync(e,...t);return Array.isArray(t)?e.arraysSync(...t):e.arraysSync(t)}array(e,...t){var[e,t]=this.prepareSync(e,...t);return Array.isArray(t)?e.arraySync(...t):e.arraySync(t)}exec(e,...t){var[e,t]=this.prepareSync(e,...t);return Array.isArray(t)?e.execSync(...t):e.execSync(t)}run(e,...t){var[e,t]=this.prepareSync(e,...t);Array.isArray(t)?e.runSync(...t):e.runSync(t)}}class ConnectionBase{driver;$;async;sync;schema;dialect;constructor(e){this.driver=e,this.$=e.$,this.schema=e.schema,this.dialect=e.dialect,this.async=new DbConnection(this),this.sync=new SyncDbConnection(this)}prepare(e){throw new Error(DriverRequired)}prepareSync(e){throw new Error(DriverRequired)}}class DefaultStrategy{tableName(e){return e}columnName(e){return e}tableFromDef(e){return e.alias??e.name}}class SnakeCaseStrategy{tableName(e){return snakeCase(e)}columnName(e){return snakeCase(e)}tableFromDef(e){return snakeCase(e.alias??e.name)}}class FilterConnection{db;fn;$;orig;constructor(e,t){this.db=e,this.fn=t,this.orig=e.connection,(e.connection=this).$=e.$}get driver(){return this.db.driver}prepareSync(e,...t){return this.fn(e,t),this.orig.prepareSync(e,...t)}release(){this.db.connection=this.orig}}function useFilter(e,t){return new FilterConnection(e,t)}function alignLeft(e,t,r=" "){return t<0?"":t+1-e.length<=0?e:r+e+r.repeat(t+1-e.length)}function alignCenter(e,t,r=" "){var s,n;return t<0?"":(n=(e=e||"").length,s=Math.floor(t/2-n/2),n=Math.abs(n%2-t%2),r.repeat(s+1)+e+r.repeat(s+1+n))}function alignRight(e,t,r=" "){return t<0?"":t+1-e.length<=0?e:r.repeat(t+1-e.length)+e+r}function alignAuto(e,t,r=" "){var s=""+e;return s.length<=t?("number"==typeof e?alignRight:alignLeft)(s,t,r):s}class Inspect{static dump(e){return"object"==typeof e&&"sql"in(e="function"==typeof e.build?e.build():e)&&"params"in e?[e.sql,"PARAMS "+Inspect.dump(e.params)].join("\n")+"\n":JSON.stringify(e,null,4).replace(/"/g,"")}static printDump(e){console.log(Inspect.dump(e))}static dumpTable(e){let s=e,n=uniqueKeys(s),i={};n.forEach(t=>{let r=t.length;s.forEach(e=>{var e=e[t];null!=e&&(e=(""+e).length)>r&&(r=e)}),i[t]=r});e=Object.keys(i).length,e=Object.keys(i).map(e=>i[e]).reduce((e,t)=>e+t,0)+2*e+(e+1);let a=[],t=(a.push(`+${"-".repeat(e-2)}+`),"|");return n.forEach(e=>t+=alignCenter(e,i[e])+"|"),a.push(t),a.push(`|${"-".repeat(e-2)}|`),s.forEach(t=>{let r="|";n.forEach(e=>r+=alignAuto(t[e],i[e])+"|"),a.push(r)}),a.push(`+${"-".repeat(e-2)}+`),a.join("\n")}static printDumpTable(e){console.log(Inspect.dumpTable(e))}}class Sql{static ops={equals:"=","=":"=",notEquals:"<>","!=":"!=",like:"LIKE",startsWith:"LIKE",endsWith:"LIKE",contains:"LIKE",notLike:"NOT LIKE",in:"IN",notIn:"NOT IN",isNull:"IS NULL",notNull:"IS NOT NULL"};static opKeys=Object.keys(Sql.ops);static create(o){function s(r,...s){if(isTemplateStrings(r)){let t="";var n,i,a={};for(let e=0;e<r.length;e++)t+=r[e],e>=s.length||("symbol"==typeof(n=s[e])?t+=n.description??"":"object"==typeof n&&n.$ref?t+=o.quoteTable(Meta.assertMeta(n.$ref.cls).tableName):"object"==typeof n&&"function"==typeof n.build?(i=n.build(),t+=mergeParams(a,i).replaceAll("\n","\n ")):"object"==typeof n&&"string"==typeof n.sql?t+=mergeParams(a,n).replaceAll("\n","\n "):n&&(i="_"+(Object.keys(a).length+1),t+="$"+i,a[i]=n));return{sql:t,params:a}}if("string"==typeof r)return{sql:r,params:s[0]};throw new Error(`sql(${typeof r}) is invalid`)}return s.dialect=o,s.quote=o.quote.bind(o),s.quoteColumn=o.quoteColumn.bind(o),s.quoteTable=o.quoteTable.bind(o),s.ref=function(r,s){let n=Meta.assertMeta(r);null==s&&(s=o.quoteTable(n.tableName));return new Proxy({prefix:s?s+".":"",meta:n},{get:(e,t)=>"$ref"==t?{cls:r,as:s}:Symbol(e.prefix+((e,t)=>{var r=e.props.find(e=>e.name==t)?.column;if(r)return o.quoteColumn(r.name);throw new Error(e.name+" does not have a column property "+t)})(n,"string"==typeof t?t:t.description))})},s.refs=function(...e){return e.map(e=>s.ref(e))},s.fragment=function(e,t={}){return"object"==typeof e?{sql:mergeParams(t,e),params:t}:{sql:e,params:t}},s.from=function(e,t){var r=asType(e),e=asRef(e)??s.ref(e,t??"");return new SelectQuery(s,[r],[Meta.assertMeta(r)],[e])},s.update=function(e){return new UpdateQuery(s,[e],[Meta.assertMeta(e)],[s.ref(e,"")])},s.deleteFrom=function(e){return new DeleteQuery(s,[e],[Meta.assertMeta(e)],[s.ref(e,"")])},s.join=function(...e){return new SqlJoinBuilder(s,...e)},s.groupBy=function(...e){return new SqlGroupByBuilder(s,...e)},s.having=function(...e){return new SqlHavingBuilder(s,...e)},s.orderBy=function(...e){return new SqlOrderByBuilder(s,...e)},s.idEquals=function(t){return e=>s.fragment(s`${e.id} = $id`,{id:t})},s.log=function(e){console.log(Inspect.dump(e))},s.dump=function(e){console.log(Inspect.dumpTable(e))},s}}class SqlJoinBuilder{$;get table(){return this.tables[0]}tables;refs;exprs=[];params={};alias="";buildOn;constructor(e,...t){this.$=e,this.tables=t,this.refs=this.tables.map(e=>this.$.ref(e))}join(e,...t){return this.add("JOIN",e,...t)}leftJoin(e,...t){return this.add("LEFT JOIN",e,...t)}rightJoin(e,...t){return this.add("RIGHT JOIN",e,...t)}fullJoin(e,...t){return this.add("FULL JOIN",e,...t)}crossJoin(e,...t){return this.add("CROSS JOIN",e,...t)}add(e,t,...r){return Array.isArray(t)?this.exprs.push({type:e,expr:e=>this.$(t,...r)}):"function"==typeof t&&this.exprs.push({type:e,expr:e=>t.call(this,...e)}),this}as(e){return this.alias=e,this}build(e){null!=this.alias&&(e[0].$ref.as=this.$.ref(e[0].$ref.cls,this.alias));var t,r={},s=[];for(t of this.exprs){var n=t.expr(e),i=s.length?""+alignRight(t.type,5):"";s.push(i+" "+mergeParams(r,n))}var a=s.join("");return{type:this.exprs[0].type,on:a,params:r}}}class SqlBuilderBase{$;tables;params={};exprs=[];delimiter=", ";constructor(e,...t){this.$=e,this.tables=t}add(t,...r){return Array.isArray(t)?this.exprs.push(e=>this.$(t,...r)):"function"==typeof t&&this.exprs.push(e=>t.call(this,...e)),this}build(e){var t,r={},s=[];for(t of this.exprs){var n=t(e);s.push(mergeParams(r,n))}return{sql:s.join(this.delimiter),params:r}}}class SqlGroupByBuilder extends SqlBuilderBase{}class SqlOrderByBuilder extends SqlBuilderBase{}class SqlHavingBuilder extends SqlBuilderBase{constructor(e,...t){super(e,...t),this.delimiter="\n AND "}}function joinOptions(e,t,r,s){var n,i;if("object"==typeof r)return r?.sql?({sql:n,params:i}=r,{type:e,cls:t,ref:s,on:n,params:i}):{type:e,cls:t,ref:s,as:r?.as,on:r?.on,params:r?.params};if("function"==typeof r)return{sql:n,params:i}=r.build(),{type:e,cls:t,on:n,params:i};throw new Error("Invalid Join Option: "+typeof r)}class WhereQuery{$;tables;metas;refs;get[type](){return clsName("WhereQuery",...this.tables)}constructor(e,t,r,s){this.$=e,this.tables=t,this.metas=r,this.refs=s}log(e="info"){if("debug"==e){var t,r,e=this.toString(),s={refs:this.refs.map(e=>e.$ref).map(e=>[Meta.assertMeta(e.cls).tableName,e.as].filter(e=>!!e).join(" "))};for([t,r]of Object.entries(this))"_"==t[0]&&Array.isArray(r)&&r.length&&(s[t.substring(1)]=r);console.log([e.trimEnd(),Inspect.dump(s).replaceAll("\\",""),""].join("\n"))}else console.log(Inspect.dump(this));return this}_where=[];_joins=[];params={};get ref(){return this.refs[0]}get meta(){return this.metas[0]}get hasWhere(){return 0<this._where.length}refOf(e){for(var t of this.refs)if(e==t.$ref.cls)return t;return null}refsOf(...e){return e.map(e=>{var t=this.refOf(e);if(null==t)throw new Error(`Could not find ref for '${e.name}'`);return t})}createInstance(e,t){var r=Meta.assertMeta(e);return t=t??this.$.ref(e),new this.constructor(this.$,[...this.tables,e],[...this.metas,r],[...this.refs,t])}copyInto(e){return e.params=Object.assign({},this.params),e._where=Array.from(this._where),e._joins=Array.from(this._joins),e}clone(){var e=new this.constructor(this.$,[...this.tables],[...this.metas],[...this.refs]);return this.copyInto(e),e}addJoin(e){var t=e.cls,r=e?.ref??(e.as?this.$.ref(t,e.as):void 0),r=this.createInstance(t,r),s=(this.copyInto(r),r);s.refs[0].$ref.as||(s.refs[0]=s.$.ref(s.meta.cls,s.quoteTable(s.meta.tableName)));let n="";var i,a=s;return"string"==typeof e.on?n=e.params?a.mergeParams({sql:e.on,params:e.params}):e.on:"function"==typeof e.on&&(i=s.refs.slice(-2).concat([s.ref]),s=assertSql(e.on.call(s,...i)),n=a.mergeParams(s)),a._joins.push({type:e.type,table:t,on:n,params:e.params}),r}joinBuilder(e,t="JOIN"){var r=e.tables[0],r=this.createInstance(r),s=(this.copyInto(r),e.tables.map(e=>this.refOf(e)??this.$.ref(e)));let{type:n,on:i,params:a}=e.build(s,t);return i&&a&&(i=this.mergeParams({sql:i,params:a})),r._joins.push({type:n,on:i,params:a}),r}join(e,t){if("object"!=typeof e&&"function"!=typeof e)throw new Error("invalid argument: "+typeof e);return!e?.$ref&&e.tables?this.joinBuilder(e,"JOIN"):this.addJoin(joinOptions("JOIN",asType(e),t,asRef(e)))}leftJoin(e,t){if("object"!=typeof e&&"function"!=typeof e)throw new Error("invalid argument: "+typeof e);return this.addJoin(joinOptions("LEFT JOIN",asType(e),t,asRef(e)))}rightJoin(e,t){if("object"!=typeof e&&"function"!=typeof e)throw new Error("invalid argument: "+typeof e);return this.addJoin(joinOptions("RIGHT JOIN",asType(e),t,asRef(e)))}fullJoin(e,t){if("object"!=typeof e&&"function"!=typeof e)throw new Error("invalid argument: "+typeof e);return this.addJoin(joinOptions("FULL JOIN",asType(e),t,asRef(e)))}crossJoin(e,t){if("object"!=typeof e&&"function"!=typeof e)throw new Error("invalid argument: "+typeof e);return this.addJoin(joinOptions("CROSS JOIN",asType(e),t,asRef(e)))}where(e,...t){return this.and(e,...t)}and(e,...t){return e||0!=t.length?isTemplateStrings(e)?this.condition("AND",this.$(e,...t)):"function"==typeof e?(t=assertSql(e.call(this,...this.refs)),this.condition("AND",t)):this.condition("AND",e):(this._where.length=0,this)}or(e,...t){return e||0!=t.length?Array.isArray(e)?this.condition("OR",this.$(e,...t)):"function"==typeof e?(t=assertSql(e.call(this,...this.refs)),this.condition("OR",t)):this.condition("OR",e):(this._where.length=0,this)}condition(e,t){if("sql"in t&&"params"in t)this._where.push({condition:e,sql:this.mergeParams(t)});else if(t.rawSql){var r;for(r of Array.isArray(t.rawSql)?t.rawSql:[t.rawSql])this._where.push({condition:e,sql:r});this.addParams(t.params)}for(var[s,n]of Object.entries(t))Sql.opKeys.includes(s)?this.addWhere(e,Sql.ops[s],n,s):"op"===s&&Array.isArray(n)&&2<=n.length&&([s,n]=n,this.addWhere(e,s,n));return this}quote(e){return this.$.quote(e)}quoteTable(e){return this.$.quoteTable(e)}quoteColumn(e){var t=this.ref.$ref.as;return(t?t+".":"")+this.$.quoteColumn(e)}as(e){return this.refs[0]=this.$.ref(this.refs[0].$ref.cls,e),this}addParams(e){if(e&&"object"==typeof e)for(var[t,r]of Object.entries(e))this.params[t]=r}mergeParams(e){let t=e.sql;if(e.params&&"object"==typeof e.params)for(var[r,s]of Object.entries(e.params)){var n;r in this.params&&"_"===r[0]&&!isNaN(parseInt(r.substring(1)))?(n=nextParam(this.params),t=t.replaceAll("$"+r,"$"+n),this.params[n]=s):this.params[r]=s}return t}addWhere(s,e,n,i){if(!s)throw new Error("condition is required");if(!e)throw new Error("sqlOp is required");if(!n)throw new Error("values is required");if("isNull"===i||"notNull"===i){if(!Array.isArray(n))throw new Error(i+" requires an array of property names, but was: "+toStr(n));var r=[];for(let t of n){var a=this.meta.props.find(e=>e.name===t);if(!a)throw new Error(`Property ${t} not found in `+this.meta.name);if(!a.column)throw new Error(`Property ${t} is not a column`);r.push(a.column.name)}var t=r.map(e=>this.$.quoteColumn(e)+" "+Sql.ops[i]).join(` ${s} `);this._where.push({condition:s,sql:t})}else{if("object"!=typeof n)throw new Error(`Unsupported ${s} value: `+n);for(let[t,r]of Object.entries(n)){var o=this.meta.props.find(e=>e.name===t);if(!o)throw new Error(`Property ${t} not found in `+this.meta.name);if(!o.column)throw new Error(`Property ${t} is not a column`);var l=this.$.quoteColumn(o.column.name)+" "+e;if(Array.isArray(r)){let e="";for(var u in r){e&&(e+=",");var c=nextParam(this.params);e+="$"+c,this.params[c]=u}this._where.push({condition:s,sql:l+` (${e})`})}else{this._where.push({condition:s,sql:l+" $"+o.name});l="startsWith"===i?r+"%":"endsWith"===i?"%"+r:"contains"===i?`%${r}%`:r;this.params[o.name]=l}}}}buildWhere(){if(0===this._where.length)return"";let e="\n WHERE ";for(var[t,{condition:r,sql:s}]of this._where.entries())0<t&&(e+=` | ||
`;r=e.filter(e=>e.index).map(e=>this.sqlIndexDefinition(t.table,e)+";");return 0<r.length&&(s+=r.join("\n")),s}insert(e,t){e=Meta.assertMeta(e);let r=e.props.filter(e=>e.column);var s=(r=t?.onlyProps?r.filter(e=>t.onlyProps.includes(e.name)):r).map(e=>e.column).filter(e=>!e.autoIncrement),n=s.map(e=>""+this.dialect.quoteColumn(e.name)).join(", "),s=s.map(e=>"$"+e.name).join(", ");return`INSERT INTO ${this.dialect.quoteTable(e.tableName)} (${n}) VALUES (${s})`}update(e,t){var e=Meta.assertMeta(e),r=t?.onlyProps?e.props.filter(e=>t.onlyProps.includes(e.name)||e.column?.primaryKey):e.props.filter(e=>e.column);if(!r.filter(e=>e.column?.primaryKey).length)throw new Error(e.name+" does not have a PRIMARY KEY");var r=r.map(e=>e.column),s=r.filter(e=>!e.primaryKey),r=r.filter(e=>e.primaryKey),s=s.map(e=>this.dialect.quoteColumn(e.name)+"=$"+e.name).join(", "),r=r.map(e=>this.dialect.quoteColumn(e.name)+" = $"+e.name).join(" AND ");let n=`UPDATE ${this.dialect.quoteTable(e.tableName)} SET `+s;if(r)return n+=" WHERE "+r;throw new Error("No WHERE clause exists for UPDATE "+e.tableName)}delete(e,t){var r,e=Meta.assertMeta(e);let s=e.props.filter(e=>e.column).map(e=>e.column).filter(e=>e.primaryKey).map(e=>this.dialect.quoteColumn(e.name)+" = $"+e.name).join(" AND "),n=(t?.where&&(r=s?" AND ":" WHERE ",t=Array.isArray(t.where)?t.where:[t.where],s+=r+t.join(" AND ")),"DELETE FROM "+this.dialect.quoteTable(e.tableName));if(s)return n+=" WHERE "+s;throw new Error("No WHERE clause exists for DELETE "+e.tableName)}toDbBindings(r){let s=[];return Meta.assertMeta(r.constructor).props.filter(e=>e.column).forEach(e=>{var t=r[e.column.name],e=this.converters[e.column.type];e?(e=e.toDb(t),s.push(e)):s.push(t)}),s}toDbObject(e,t){var r,s,n,i={};for(r of Meta.assertMeta(e.constructor).props.filter(e=>e.column))t?.onlyProps&&!t.onlyProps.includes(r.name)||(s=e[r.name],(n=this.converters[r.column.type])?(n=n.toDb(s),i[r.column.name]=n):i[r.column.name]=s);return i}}class DbConnection{connection;driver;$;schema;constructor(e){this.connection=e,this.$=e.$,this.driver=e.driver,this.schema=this.$.schema=e.driver.schema}get sync(){if(null==this.driver.sync)throw new Error(this.$.name+" does not support sync APIs");return this.driver.sync}quote(e){return this.$.quote(e)}insert(e,t){return Promise.resolve(this.sync.insert(e,t))}insertAll(e,t){return Promise.resolve(this.sync.insertAll(e,t))}listTables(){return Promise.resolve(this.sync.listTables())}dropTable(e){return Promise.resolve(this.sync.dropTable(e))}createTable(e){return Promise.resolve(this.sync.createTable(e))}all(e,...t){return Promise.resolve(this.sync.all(e,...t))}one(e,...t){return Promise.resolve(this.sync.one(e,...t))}column(e,...t){return Promise.resolve(this.sync.column(e,...t))}value(e,...t){return Promise.resolve(this.sync.value(e,...t))}arrays(e,...t){return Promise.resolve(this.sync.arrays(e,...t))}array(e,...t){return Promise.resolve(this.sync.array(e,...t))}exec(e,...t){return Promise.resolve(this.sync.exec(e,...t))}run(e,...t){return Promise.resolve(this.sync.run(e,...t))}prepare(e,...t){if(isTemplateStrings(e))return[this.connection.prepare(e,...t),t];if("object"==typeof e){if("build"in e)return t=e.build(),[this.connection.prepare(t.sql),t.params];if("sql"in e)return[this.connection.prepare(e.sql),e.params??{}]}throw new Error("Invalid argument: "+toStr(e))}}class SyncDbConnection{connection;driver;$;schema;constructor(e){this.connection=e,this.$=e.$,this.driver=e.driver,this.schema=this.$.schema=e.driver.schema}quote(e){return this.$.quote(e)}insert(e,t){var r,s;return e?(r=e.constructor,t?.onlyProps||t?.onlyWithValues?(t={onlyProps:t?.onlyProps??propsWithValues(e)},s=this.connection.prepareSync(this.schema.insert(r,t)),t=this.schema.toDbObject(e,t),s.execSync(t)):(s=this.connection.prepareSync(this.schema.insert(r)),t=this.schema.toDbObject(e),s.execSync(t))):{changes:0,lastInsertRowid:0}}insertAll(e,t){var r={changes:0,lastInsertRowid:0};if(0!=e.length){var s=e[0].constructor;if(t?.onlyProps||t?.onlyWithValues)for(var n of e){n=this.insert(n,t);r.changes+=n.changes,r.lastInsertRowid=n.lastInsertRowid}else{var i,a=this.connection.prepareSync(this.schema.insert(s));for(i of e){var o=this.schema.toDbObject(i),o=a.execSync(o);r.changes+=o.changes,r.lastInsertRowid=o.lastInsertRowid}}}return r}update(e,t){var r,s;return e?(r=e.constructor,t?.onlyProps||t?.onlyWithValues?(s=r.$props.filter(e=>e.column?.primaryKey).map(e=>e.column.name),t={onlyProps:Array.from(new Set([...t?.onlyProps??propsWithValues(e),...s]))},s=this.connection.prepareSync(this.schema.update(r,t)),t=this.schema.toDbObject(e,t),s.execSync(t)):(s=this.connection.prepareSync(this.schema.update(r)),t=this.schema.toDbObject(e),s.execSync(t))):{changes:0,lastInsertRowid:0}}delete(e,t){var r;return e?(r=e.constructor,t=this.connection.prepareSync(this.schema.delete(r,t)),r=Meta.assertMeta(r).props.filter(e=>e.column?.primaryKey).map(e=>e.name),e=this.schema.toDbObject(e,{onlyProps:r}),t.execSync(e)):{changes:0,lastInsertRowid:0}}listTables(){return this.column({sql:this.schema.sqlTableNames(),params:{}})}dropTable(e){return this.connection.prepareSync(this.schema.dropTable(e)).execSync()}createTable(e){return this.connection.prepareSync(this.schema.createTable(e)).execSync()}prepareSync(e,...t){var r;if(isTemplateStrings(e))return[this.connection.prepareSync(e,...t),t,void 0];if("object"==typeof e){if("build"in e)return t=e.build(),[this.connection.prepareSync(t.sql),t.params??{},t.into];if("sql"in e)return t=e.sql,r=e.params??{},[this.connection.prepareSync(t),r,e.into]}throw new Error("Invalid argument: "+toStr(e))}all(e,...t){var[e,t,r]=this.prepareSync(e,...t);return r?(r=e.as(r),Array.isArray(t)?r.allSync(...t):r.allSync(t)):Array.isArray(t)?e.allSync(...t):e.allSync(t)}one(e,...t){var[e,t,r]=this.prepareSync(e,...t);return r?(r=e.as(r),Array.isArray(t)?r.oneSync(...t):r.oneSync(t)):Array.isArray(t)?e.oneSync(...t):e.oneSync(t)}column(e,...t){var[e,t]=this.prepareSync(e,...t);return Array.isArray(t)?e.arraysSync(...t).map(e=>e[0]):e.arraysSync(t).map(e=>e[0])}value(e,...t){var[e,t,r]=this.prepareSync(e,...t),e=Array.isArray(t)?e.valueSync(...t):e.valueSync(t);return r&&r===Boolean?!!e:e}arrays(e,...t){var[e,t]=this.prepareSync(e,...t);return Array.isArray(t)?e.arraysSync(...t):e.arraysSync(t)}array(e,...t){var[e,t]=this.prepareSync(e,...t);return Array.isArray(t)?e.arraySync(...t):e.arraySync(t)}exec(e,...t){var[e,t]=this.prepareSync(e,...t);return Array.isArray(t)?e.execSync(...t):e.execSync(t)}run(e,...t){var[e,t]=this.prepareSync(e,...t);Array.isArray(t)?e.runSync(...t):e.runSync(t)}}class ConnectionBase{driver;$;async;sync;schema;dialect;constructor(e){this.driver=e,this.$=e.$,this.schema=this.$.schema=e.schema,this.dialect=e.dialect,this.async=new DbConnection(this),this.sync=new SyncDbConnection(this)}prepare(e){throw new Error(DriverRequired)}prepareSync(e){throw new Error(DriverRequired)}}class DefaultStrategy{tableName(e){return e}columnName(e){return e}tableFromDef(e){return e.alias??e.name}}class SnakeCaseStrategy{tableName(e){return snakeCase(e)}columnName(e){return snakeCase(e)}tableFromDef(e){return snakeCase(e.alias??e.name)}}class FilterConnection{db;fn;$;orig;constructor(e,t){this.db=e,this.fn=t,this.orig=e.connection,(e.connection=this).$=e.$}get driver(){return this.db.driver}prepareSync(e,...t){return this.fn(e,t),this.orig.prepareSync(e,...t)}release(){this.db.connection=this.orig}}function useFilter(e,t){return new FilterConnection(e,t)}function alignLeft(e,t,r=" "){return t<0?"":t+1-e.length<=0?e:r+e+r.repeat(t+1-e.length)}function alignCenter(e,t,r=" "){var s,n;return t<0?"":(n=(e=e||"").length,s=Math.floor(t/2-n/2),n=Math.abs(n%2-t%2),r.repeat(s+1)+e+r.repeat(s+1+n))}function alignRight(e,t,r=" "){return t<0?"":t+1-e.length<=0?e:r.repeat(t+1-e.length)+e+r}function alignAuto(e,t,r=" "){var s=""+e;return s.length<=t?("number"==typeof e?alignRight:alignLeft)(s,t,r):s}class Inspect{static dump(e){return"object"==typeof e&&"sql"in(e="function"==typeof e.build?e.build():e)&&"params"in e?[e.sql,"PARAMS "+Inspect.dump(e.params)].join("\n")+"\n":JSON.stringify(e,null,4).replace(/\\"/g,"")}static printDump(e){console.log(Inspect.dump(e))}static dumpTable(e){let s=e,n=uniqueKeys(s),i={};n.forEach(t=>{let r=t.length;s.forEach(e=>{var e=e[t];null!=e&&(e=(""+e).length)>r&&(r=e)}),i[t]=r});e=Object.keys(i).length,e=Object.keys(i).map(e=>i[e]).reduce((e,t)=>e+t,0)+2*e+(e+1);let a=[],t=(a.push(`+${"-".repeat(e-2)}+`),"|");return n.forEach(e=>t+=alignCenter(e,i[e])+"|"),a.push(t),a.push(`|${"-".repeat(e-2)}|`),s.forEach(t=>{let r="|";n.forEach(e=>r+=alignAuto(t[e],i[e])+"|"),a.push(r)}),a.push(`+${"-".repeat(e-2)}+`),a.join("\n")}static printDumpTable(e){console.log(Inspect.dumpTable(e))}}function Watch(e){try{var t=e();if(t)for(var r in t){console.log(r+":");var s=t[r];Array.isArray(s)?console.table(s):"object"!=typeof s?console.log(toStr(s).trim()):console.log(Inspect.dump(s)),console.log()}}catch(e){console.error(""+e)}}class Sql{static ops={equals:"=","=":"=",notEquals:"<>","!=":"!=",like:"LIKE",startsWith:"LIKE",endsWith:"LIKE",contains:"LIKE",notLike:"NOT LIKE",in:"IN",notIn:"NOT IN",isNull:"IS NULL",notNull:"IS NOT NULL"};static opKeys=Object.keys(Sql.ops);static create(o){function s(r,...s){if(isTemplateStrings(r)){let t="";var n,i,a={};for(let e=0;e<r.length;e++)t+=r[e],e>=s.length||("symbol"==typeof(n=s[e])?t+=n.description??"":"object"==typeof n&&n.$ref?t+=o.quoteTable(Meta.assertMeta(n.$ref.cls).tableName):"object"==typeof n&&"function"==typeof n.build?(i=n.build(),t+=mergeParams(a,i).replaceAll("\n","\n ")):"object"==typeof n&&"string"==typeof n.sql?t+=mergeParams(a,n).replaceAll("\n","\n "):n&&(i="_"+(Object.keys(a).length+1),t+="$"+i,a[i]=n));return{sql:t,params:a}}if("string"==typeof r)return{sql:r,params:s[0]};throw new Error(`sql(${typeof r}) is invalid`)}return s.schema=new Schema(o),s.dialect=o,s.quote=o.quote.bind(o),s.quoteColumn=o.quoteColumn.bind(o),s.quoteTable=o.quoteTable.bind(o),s.ref=function(r,s){let n=Meta.assertMeta(r);null==s&&(s=o.quoteTable(n.tableName));return new Proxy({prefix:s?s+".":"",meta:n},{get:(e,t)=>"$ref"==t?{cls:r,as:s}:Symbol(e.prefix+((e,t)=>{var r=e.props.find(e=>e.name==t)?.column;if(r)return o.quoteColumn(r.name);throw new Error(e.name+" does not have a column property "+t)})(n,"string"==typeof t?t:t.description))})},s.refs=function(...e){return e.map(e=>s.ref(e))},s.fragment=function(e,t={}){return"object"==typeof e?{sql:mergeParams(t,e),params:t}:{sql:e,params:t}},s.from=function(e,t){var r=asType(e),e=asRef(e)??s.ref(e,t??"");return new SelectQuery(s,[r],[Meta.assertMeta(r)],[e])},s.update=function(e){return new UpdateQuery(s,[e],[Meta.assertMeta(e)],[s.ref(e,"")])},s.deleteFrom=function(e){return new DeleteQuery(s,[e],[Meta.assertMeta(e)],[s.ref(e,"")])},s.join=function(...e){return new SqlJoinBuilder(s,...e)},s.groupBy=function(...e){return new SqlGroupByBuilder(s,...e)},s.having=function(...e){return new SqlHavingBuilder(s,...e)},s.orderBy=function(...e){return new SqlOrderByBuilder(s,...e)},s.idEquals=function(t){return e=>s.fragment(s`${e.id} = $id`,{id:t})},s.log=function(e){console.log(Inspect.dump(e))},s.dump=function(e){console.log(Inspect.dumpTable(e))},s}}class SqlJoinBuilder{$;get table(){return this.tables[0]}tables;refs;exprs=[];params={};alias="";buildOn;constructor(e,...t){this.$=e,this.tables=t,this.refs=this.tables.map(e=>this.$.ref(e))}join(e,...t){return this.add("JOIN",e,...t)}leftJoin(e,...t){return this.add("LEFT JOIN",e,...t)}rightJoin(e,...t){return this.add("RIGHT JOIN",e,...t)}fullJoin(e,...t){return this.add("FULL JOIN",e,...t)}crossJoin(e,...t){return this.add("CROSS JOIN",e,...t)}add(e,t,...r){return Array.isArray(t)?this.exprs.push({type:e,expr:e=>this.$(t,...r)}):"function"==typeof t&&this.exprs.push({type:e,expr:e=>t.call(this,...e)}),this}as(e){return this.alias=e,this}build(e){null!=this.alias&&(e[0].$ref.as=this.$.ref(e[0].$ref.cls,this.alias));var t,r={},s=[];for(t of this.exprs){var n=t.expr(e),i=s.length?""+alignRight(t.type,5):"";s.push(i+" "+mergeParams(r,n))}var a=s.join("");return{type:this.exprs[0].type,on:a,params:r}}}class SqlBuilderBase{$;tables;params={};exprs=[];delimiter=", ";constructor(e,...t){this.$=e,this.tables=t}add(t,...r){return Array.isArray(t)?this.exprs.push(e=>this.$(t,...r)):"function"==typeof t&&this.exprs.push(e=>t.call(this,...e)),this}build(e){var t,r={},s=[];for(t of this.exprs){var n=t(e);s.push(mergeParams(r,n))}return{sql:s.join(this.delimiter),params:r}}}class SqlGroupByBuilder extends SqlBuilderBase{}class SqlOrderByBuilder extends SqlBuilderBase{}class SqlHavingBuilder extends SqlBuilderBase{constructor(e,...t){super(e,...t),this.delimiter="\n AND "}}function joinOptions(e,t,r,s){var n,i;if("object"==typeof r)return r?.sql?({sql:n,params:i}=r,{type:e,cls:t,ref:s,on:n,params:i}):{type:e,cls:t,ref:s,as:r?.as,on:r?.on,params:r?.params};if("function"==typeof r)return{sql:n,params:i}=r.build(),{type:e,cls:t,on:n,params:i};throw new Error("Invalid Join Option: "+typeof r)}class WhereQuery{$;tables;metas;refs;get[type](){return clsName("WhereQuery",...this.tables)}constructor(e,t,r,s){this.$=e,this.tables=t,this.metas=r,this.refs=s}log(e){return console.log(this.toString(e)),this}_where=[];_joins=[];params={};get ref(){return this.refs[0]}get meta(){return this.metas[0]}get hasWhere(){return 0<this._where.length}refOf(e){for(var t of this.refs)if(e==t.$ref.cls)return t;return null}refsOf(...e){return e.map(e=>{var t=this.refOf(e);if(null==t)throw new Error(`Could not find ref for '${e.name}'`);return t})}createInstance(e,t){var r=Meta.assertMeta(e);return t=t??this.$.ref(e),new this.constructor(this.$,[...this.tables,e],[...this.metas,r],[...this.refs,t])}copyInto(e){return e.params=Object.assign({},this.params),e._where=Array.from(this._where),e._joins=Array.from(this._joins),e}clone(){var e=new this.constructor(this.$,[...this.tables],[...this.metas],[...this.refs]);return this.copyInto(e),e}addJoin(e){var t=e.cls,r=e?.ref??(e.as?this.$.ref(t,e.as):void 0),r=this.createInstance(t,r),s=(this.copyInto(r),r);s.refs[0].$ref.as||(s.refs[0]=s.$.ref(s.meta.cls,s.quoteTable(s.meta.tableName)));let n="";var i,a=s;return"string"==typeof e.on?n=e.params?a.mergeParams({sql:e.on,params:e.params}):e.on:"function"==typeof e.on&&(i=s.refs.slice(-2).concat([s.ref]),s=assertSql(e.on.call(s,...i)),n=a.mergeParams(s)),a._joins.push({type:e.type,table:t,on:n,params:e.params}),r}joinBuilder(e,t="JOIN"){var r=e.tables[0],r=this.createInstance(r),s=(this.copyInto(r),e.tables.map(e=>this.refOf(e)??this.$.ref(e)));let{type:n,on:i,params:a}=e.build(s,t);return i&&a&&(i=this.mergeParams({sql:i,params:a})),r._joins.push({type:n,on:i,params:a}),r}join(e,t){if("object"!=typeof e&&"function"!=typeof e)throw new Error("invalid argument: "+typeof e);return!e?.$ref&&e.tables?this.joinBuilder(e,"JOIN"):this.addJoin(joinOptions("JOIN",asType(e),t,asRef(e)))}leftJoin(e,t){if("object"!=typeof e&&"function"!=typeof e)throw new Error("invalid argument: "+typeof e);return this.addJoin(joinOptions("LEFT JOIN",asType(e),t,asRef(e)))}rightJoin(e,t){if("object"!=typeof e&&"function"!=typeof e)throw new Error("invalid argument: "+typeof e);return this.addJoin(joinOptions("RIGHT JOIN",asType(e),t,asRef(e)))}fullJoin(e,t){if("object"!=typeof e&&"function"!=typeof e)throw new Error("invalid argument: "+typeof e);return this.addJoin(joinOptions("FULL JOIN",asType(e),t,asRef(e)))}crossJoin(e,t){if("object"!=typeof e&&"function"!=typeof e)throw new Error("invalid argument: "+typeof e);return this.addJoin(joinOptions("CROSS JOIN",asType(e),t,asRef(e)))}where(e,...t){return this.and(e,...t)}and(e,...t){return e||0!=t.length?isTemplateStrings(e)?this.condition("AND",this.$(e,...t)):"function"==typeof e?(t=assertSql(e.call(this,...this.refs)),this.condition("AND",t)):this.condition("AND",e):(this._where.length=0,this)}or(e,...t){return e||0!=t.length?Array.isArray(e)?this.condition("OR",this.$(e,...t)):"function"==typeof e?(t=assertSql(e.call(this,...this.refs)),this.condition("OR",t)):this.condition("OR",e):(this._where.length=0,this)}condition(e,t){if("sql"in t&&"params"in t)this._where.push({condition:e,sql:this.mergeParams(t)});else if(t.rawSql){var r;for(r of Array.isArray(t.rawSql)?t.rawSql:[t.rawSql])this._where.push({condition:e,sql:r});this.addParams(t.params)}for(var[s,n]of Object.entries(t))Sql.opKeys.includes(s)?this.addWhere(e,Sql.ops[s],n,s):"op"===s&&Array.isArray(n)&&2<=n.length&&([s,n]=n,this.addWhere(e,s,n));return this}quote(e){return this.$.quote(e)}quoteTable(e){return this.$.quoteTable(e)}quoteColumn(e){var t=this.ref.$ref.as;return(t?t+".":"")+this.$.quoteColumn(e)}as(e){return this.refs[0]=this.$.ref(this.refs[0].$ref.cls,e),this}addParams(e){if(e&&"object"==typeof e)for(var[t,r]of Object.entries(e))this.params[t]=r}mergeParams(e){let t=e.sql;if(e.params&&"object"==typeof e.params)for(var[r,s]of Object.entries(e.params)){var n;r in this.params&&"_"===r[0]&&!isNaN(parseInt(r.substring(1)))?(n=nextParam(this.params),t=t.replaceAll("$"+r,"$"+n),this.params[n]=s):this.params[r]=s}return t}addWhere(s,e,n,i){if(!s)throw new Error("condition is required");if(!e)throw new Error("sqlOp is required");if(!n)throw new Error("values is required");if("isNull"===i||"notNull"===i){if(!Array.isArray(n))throw new Error(i+" requires an array of property names, but was: "+toStr(n));var r=[];for(let t of n){var a=this.meta.props.find(e=>e.name===t);if(!a)throw new Error(`Property ${t} not found in `+this.meta.name);if(!a.column)throw new Error(`Property ${t} is not a column`);r.push(a.column.name)}var t=r.map(e=>this.$.quoteColumn(e)+" "+Sql.ops[i]).join(` ${s} `);this._where.push({condition:s,sql:t})}else{if("object"!=typeof n)throw new Error(`Unsupported ${s} value: `+n);for(let[t,r]of Object.entries(n)){var o=this.meta.props.find(e=>e.name===t);if(!o)throw new Error(`Property ${t} not found in `+this.meta.name);if(!o.column)throw new Error(`Property ${t} is not a column`);var l=this.$.quoteColumn(o.column.name)+" "+e;if(Array.isArray(r)){let e="";for(var c in r){e&&(e+=",");var u=nextParam(this.params);e+="$"+u,this.params[u]=c}this._where.push({condition:s,sql:l+` (${e})`})}else{this._where.push({condition:s,sql:l+" $"+o.name});l="startsWith"===i?r+"%":"endsWith"===i?"%"+r:"contains"===i?`%${r}%`:r;this.params[o.name]=l}}}}buildWhere(){if(0===this._where.length)return"";let e="\n WHERE ";for(var[t,{condition:r,sql:s}]of this._where.entries())0<t&&(e+=` | ||
`+alignRight(r,5)),e+=s;return e}buildJoins(){if(0==this._joins.length)return"";let t="";for(let e=0;e<this._joins.length;e++){var{type:r,on:s}=this._joins[e],n=this.refs[e+1],i=this.metas[e+1],i=this.$.quoteTable(i.tableName),n=n.$ref.as,n=n&&n!==i?" "+n:"",s="string"==typeof s?" ON "+s:"",a=leftPart(r??"JOIN"," ").length<=4?" ":" ";t+=` | ||
${a}${r??"JOIN"} `+i+n+s}return t}into(e){var{sql:t,params:r}=this.build();return{sql:t,params:r,into:e}}build(){return{sql:this.buildWhere(),params:this.params}}toString(){var e=this.build(),t=e.into,t=t&&(t.name||t.$type&&t.$type.name||t.constructor.name)||"";return[Inspect.dump(e).trim(),[this[type]??"",t&&"["!=t[0]?" => "+t:""].join(""),""].join("\n")}}class SelectQuery extends WhereQuery{get[type](){return clsName("SelectQuery",...this.tables)}_select=[];_groupBy=[];_having=[];_orderBy=[];_skip;_take;_limit;copyInto(e){return super.copyInto(e),e._select=Array.from(this._select),e._groupBy=Array.from(this._groupBy),e._having=Array.from(this._having),e._skip=this._skip,e._take=this._take,e}clone(){return super.clone()}groupBy(e,...t){if(e||0!=t.length)if(Array.isArray(e)){t=this.$(e,...t);this._groupBy.push(this.mergeParams(t))}else if("object"==typeof e){t="function"==typeof e.build?e.build(this.refs):assertSql(e);this._groupBy.push(this.mergeParams(t))}else{if("function"!=typeof e)throw new Error("Invalid Argument: "+typeof e);t=assertSql(e.call(this,...this.refs));this._groupBy.push(this.mergeParams(t))}else this._groupBy.length=0;return this}having(e,...t){if(e||0!=t.length)if(Array.isArray(e)){t=this.$(e,...t);this._having.push(this.mergeParams(t))}else if("object"==typeof e){t="function"==typeof e.build?e.build(this.refs):assertSql(e);this._having.push(this.mergeParams(t))}else{if("function"!=typeof e)throw new Error("Invalid Argument: "+typeof e);t=assertSql(e.call(this,...this.refs));this._having.push(this.mergeParams(t))}else this._having.length=0;return this}orderBy(e,...t){if(e||0!=t.length)if(Array.isArray(e)){t=this.$(e,...t);this._orderBy.push(this.mergeParams(t))}else if("object"==typeof e){t="function"==typeof e.build?e.build(this.refs):assertSql(e);this._orderBy.push(this.mergeParams(t))}else{if("function"!=typeof e)throw new Error("Invalid Argument: "+typeof e);t=assertSql(e.call(this,...this.refs));this._orderBy.push(this.mergeParams(t))}else this._orderBy.length=0;return this}select(e,...r){if(e||0!==r.length)if("string"==typeof e)this._select.push(e),1<=r.length&&this.addParams(r[0]);else if(Array.isArray(e))this._select.push(this.mergeParams(this.$(e,...r)));else if("object"==typeof e){r=e;if(r.sql&&(n=r.sql,this._select.push(n.sql),this.addParams(n.params)),r.props)for(let t of r.props){var s=this.meta.props.find(e=>e.name==t)?.column;s&&this._select.push(this.quoteColumn(s.name))}if(r.columns)for(var t of r.columns)this._select.push(this.quoteColumn(t))}else{if("function"!=typeof e)throw new Error(`Invalid select(${typeof e})`);var n=assertSql(e.call(this,...this.refs));this._select.push(this.mergeParams(n))}else this._select.length=0;return this}get hasSelect(){return 0<this._select.length}skip(e){return this.limit(this._take,e)}take(e){return this.limit(e,this._skip)}limit(e,t){return this._take=null==e?void 0:e,this._skip=null==t?void 0:t,null==e&&null==t?this._limit=void 0:(e=this.$.dialect.sqlLimit(this._skip,this._take),this._limit=this.mergeParams(e)),this}exists(){var e=this.clone();return e._select=["TRUE"],e._limit="LIMIT 1",e.into(Boolean)}rowCount(){var{sql:e,params:t}=this.build();return{sql:`SELECT COUNT(*) FROM (${e}) AS COUNT`,params:t,into:Number}}buildSelect(){return"SELECT "+(0<this._select.length?this._select:this.meta.columns.map(e=>this.quoteColumn(e.name))).join(", ")}buildFrom(){var e=this.quoteTable(this.meta.tableName);let t=` | ||
${a}${r??"JOIN"} `+i+n+s}return t}into(e){var{sql:t,params:r}=this.build();return{sql:t,params:r,into:e}}build(){return{sql:this.buildWhere(),params:this.params}}toString(e){var t=this.build();if("debug"!=e&&"verbose"!=e)return Inspect.dump(t);var r=t.into,r=r&&(r.name||r.$type&&r.$type.name||r.constructor.name)||"",t=[Inspect.dump(t).trim(),[this[type]??"",r&&"["!=r[0]?" => "+r:""].join(""),""].join("\n");if("verbose"!==e)return t;var s,n,i={refs:this.refs.map(e=>e.$ref).map(e=>[Meta.assertMeta(e.cls).tableName,e.as!=this.quote(Meta.assertMeta(e.cls).tableName)?e.as:""].filter(e=>!!e).join(" "))};for([s,n]of Object.entries(this))"_"==s[0]&&Array.isArray(n)&&n.length&&(i[s.substring(1)]=n);return[t.trimEnd(),Inspect.dump(i).replaceAll('"',""),""].join("\n")}}class SelectQuery extends WhereQuery{get[type](){return clsName("SelectQuery",...this.tables)}_select=[];_groupBy=[];_having=[];_orderBy=[];_skip;_take;_limit;copyInto(e){return super.copyInto(e),e._select=Array.from(this._select),e._groupBy=Array.from(this._groupBy),e._having=Array.from(this._having),e._skip=this._skip,e._take=this._take,e}clone(){return super.clone()}groupBy(e,...t){if(e||0!=t.length)if(Array.isArray(e)){t=this.$(e,...t);this._groupBy.push(this.mergeParams(t))}else if("object"==typeof e){t="function"==typeof e.build?e.build(this.refs):assertSql(e);this._groupBy.push(this.mergeParams(t))}else{if("function"!=typeof e)throw new Error("Invalid Argument: "+typeof e);t=assertSql(e.call(this,...this.refs));this._groupBy.push(this.mergeParams(t))}else this._groupBy.length=0;return this}having(e,...t){if(e||0!=t.length)if(Array.isArray(e)){t=this.$(e,...t);this._having.push(this.mergeParams(t))}else if("object"==typeof e){t="function"==typeof e.build?e.build(this.refs):assertSql(e);this._having.push(this.mergeParams(t))}else{if("function"!=typeof e)throw new Error("Invalid Argument: "+typeof e);t=assertSql(e.call(this,...this.refs));this._having.push(this.mergeParams(t))}else this._having.length=0;return this}orderBy(e,...t){if(e||0!=t.length)if(Array.isArray(e)){t=this.$(e,...t);this._orderBy.push(this.mergeParams(t))}else if("object"==typeof e){t="function"==typeof e.build?e.build(this.refs):assertSql(e);this._orderBy.push(this.mergeParams(t))}else{if("function"!=typeof e)throw new Error("Invalid Argument: "+typeof e);t=assertSql(e.call(this,...this.refs));this._orderBy.push(this.mergeParams(t))}else this._orderBy.length=0;return this}select(e,...r){if(e||0!==r.length)if("string"==typeof e)this._select.push(e),1<=r.length&&this.addParams(r[0]);else if(Array.isArray(e))this._select.push(this.mergeParams(this.$(e,...r)));else if("object"==typeof e){r=e;if(r.sql&&(n=r.sql,this._select.push(n.sql),this.addParams(n.params)),r.props)for(let t of r.props){var s=this.meta.props.find(e=>e.name==t)?.column;s&&this._select.push(this.quoteColumn(s.name))}if(r.columns)for(var t of r.columns)this._select.push(this.quoteColumn(t))}else{if("function"!=typeof e)throw new Error(`Invalid select(${typeof e})`);var n=assertSql(e.call(this,...this.refs));this._select.push(this.mergeParams(n))}else this._select.length=0;return this}get hasSelect(){return 0<this._select.length}skip(e){return this.limit(this._take,e)}take(e){return this.limit(e,this._skip)}limit(e,t){return this._take=null==e?void 0:e,this._skip=null==t?void 0:t,null==e&&null==t?this._limit=void 0:(e=this.$.dialect.sqlLimit(this._skip,this._take),this._limit=this.mergeParams(e)),this}exists(){var e=this.clone();return e._select=["TRUE"],e._limit="LIMIT 1",e.into(Boolean)}rowCount(){var{sql:e,params:t}=this.build();return{sql:`SELECT COUNT(*) FROM (${e}) AS COUNT`,params:t,into:Number}}buildSelect(){return"SELECT "+(0<this._select.length?this._select:this.meta.columns.map(e=>this.quoteColumn(e.name))).join(", ")}buildFrom(){var e=this.quoteTable(this.meta.tableName);let t=` | ||
FROM `+e;var r=this.refs[0].$ref.as;return r&&r!=e&&(t+=" "+r),t}buildGroupBy(){return 0==this._groupBy.length?"":` | ||
@@ -11,2 +11,2 @@ GROUP BY `+this._groupBy.join(", ")}buildHaving(){return 0==this._having.length?"":` | ||
ORDER BY `+this._orderBy.join(", ")}buildLimit(){return this._limit?` | ||
`+this._limit:""}build(){return{sql:this.buildSelect()+this.buildFrom()+this.buildJoins()+this.buildWhere()+this.buildGroupBy()+this.buildHaving()+this.buildOrderBy()+this.buildLimit(),params:this.params,into:0==this._select.length?this.tables[0]:void 0}}}class UpdateQuery extends WhereQuery{get name(){return clsName("UpdateQuery",...this.tables)}_set=[];set(r,...e){if(r||(this._set.length=0),isTemplateStrings(r)){e=this.$(r,...e);this._set.push(this.mergeParams(e))}else if("object"==typeof r)if("sql"in r)this._set.push(this.mergeParams(r));else for(let[t,e]of Object.entries(r)){var s=this.meta.props.find(e=>e.name===t);if(!s)throw new Error(`Property ${t} not found in `+this.meta.name);if(!s.column)throw new Error(`Property ${t} is not a column`);this.params[s.name]=e,this._set.push(this.$.quote(s.column.name)+" = $"+s.name)}else{if("function"!=typeof r)throw new Error("invalid argument: "+typeof r);e=assertSql(r.call(this,...this.refs));this._set.push(this.mergeParams(e))}return this}get hasSet(){return 0<this._set.length}buildUpdate(){var e=this._set.join(", ");return`UPDATE ${this.quoteTable(this.meta.tableName)} SET `+e+this.buildWhere()}build(){return{sql:this.buildUpdate(),params:this.params}}}class DeleteQuery extends WhereQuery{get[type](){return clsName("DeleteQuery",...this.tables)}buildDelete(){return"DELETE FROM "+this.quoteTable(this.meta.tableName)+this.buildWhere()}build(){return{sql:this.buildDelete(),params:this.params}}}function table(r){return function(e){var t=Object.assign({},r,{name:r?.alias??e.name});e.$id||(e.$id=Symbol(e.name)),e.$type??={name:e.name},e.$type.table=t}}function column(n,i){return function(e,t){var r=Object.assign({},i,{type:n,name:i?.alias??t}),e=("id"===t&&(r.primaryKey=!0),e.constructor.$id||(e.constructor.$id=Symbol(e.constructor.name)),e.constructor.$props??(e.constructor.$props=[]));let s=e.find(e=>e.name===t);s||(s={name:t},e.push(s)),s.column=r,"symbol"==typeof s.column.type&&(s.column.type=s.column.type.description)}}function Table(e,s){if(!s)throw new Error("Table definition is required");var t=e;t.$id||(t.$id=Symbol(e.name)),t.$type??={name:e.name},t.$type.table=s.table??{},t.$type.table.name??=e.name;let n=t.$props??(t.$props=[]);return Object.keys(s.columns).forEach(t=>{var e=s.columns[t];if(!e)throw new Error(`Column definition for ${t} is missing`);if(!e.type)throw new Error(`Column type for ${t} is missing`);let r=n.find(e=>e.name===t);r||(r={name:t},n.push(r)),r.column=e,r.column.name??=e.alias??t,"symbol"==typeof r.column.type&&(r.column.type=r.column.type.description)}),e}(e=>{e.INTEGER="INTEGER",e.SMALLINT="SMALLINT",e.BIGINT="BIGINT",e.DECIMAL="DECIMAL",e.NUMERIC="NUMERIC",e.REAL="REAL",e.FLOAT="FLOAT",e.DOUBLE="DOUBLE",e.MONEY="MONEY",e.DATE="DATE",e.DATETIME="DATETIME",e.TIME="TIME",e.TIMEZ="TIMEZ",e.TIMESTAMP="TIMESTAMP",e.TIMESTAMPZ="TIMESTAMPZ",e.INTERVAL="INTERVAL",e.BOOLEAN="BOOLEAN",e.UUID="UUID",e.BLOB="BLOB",e.BYTES="BYTES",e.BIT="BIT",e.TEXT="TEXT",e.VARCHAR="VARCHAR",e.NVARCHAR="NVARCHAR",e.CHAR="CHAR",e.NCHAR="NCHAR",e.JSON="JSON",e.JSONB="JSONB",e.XML="XML"})(DataType||={});var DefaultValues={NOW:"{NOW}",MAX_TEXT:"{MAX_TEXT}",MAX_TEXT_UNICODE:"{MAX_TEXT_UNICODE}",TRUE:"{TRUE}",FALSE:"{FALSE}"};class SqliteDialect{$;strategy=new DefaultStrategy;constructor(){this.$=Sql.create(this)}quote(e){return`"${e}"`}quoteTable(e){return this.quote(this.strategy.tableName(e))}quoteColumn(e){return this.quote(this.strategy.columnName(e))}sqlLimit(e,t){if(null==e&&null==t)throw new Error(`Invalid argument sqlLimit(${e}, ${t})`);return e?this.$.fragment("LIMIT $limit OFFSET $offset",{offset:e,limit:t??-1}):this.$.fragment("LIMIT $limit",{limit:t})}}class SqliteSchema extends Schema{driver;constructor(e){super(e.dialect),this.driver=e}sqlTableNames(){return"SELECT name FROM sqlite_master WHERE type ='table' AND name NOT LIKE 'sqlite_%'"}sqlIndexDefinition(e,t){return`CREATE ${t.unique?"UNIQUE INDEX":"INDEX"} idx_${e.name}_${t.name} ON ${this.dialect.quoteTable(e.name)} (${this.dialect.quoteColumn(t.name)})`}sqlColumnDefinition(e){var t=e.type;let r=this.driver.types.native.includes(t)?t:void 0;if(!r)for(var[s,n]of Object.entries(this.driver.types.map))if(n.includes(t)){r=s;break}r=r||t;let i=this.dialect.quoteColumn(e.name)+" "+r;return e.primaryKey&&(i+=" PRIMARY KEY"),e.autoIncrement&&(i+=" AUTOINCREMENT"),e.required&&(i+=" NOT NULL"),e.unique&&!e.index&&(i+=" UNIQUE"),e.defaultValue&&(e=this.driver.variables[e.defaultValue]??e.defaultValue,i+=" DEFAULT "+e),i}sqlLimit(e,t){if(null==e&&null==t)throw new Error(`Invalid argument sqlLimit(${e}, ${t})`);return e?this.driver.$.fragment("LIMIT $limit OFFSET $offset",{offset:e,limit:t??-1}):this.driver.$.fragment("LIMIT $limit",{limit:t})}}class SqliteTypes{native=["INTEGER","SMALLINT","BIGINT","REAL","DOUBLE","FLOAT","NUMERIC","DECIMAL","BOOLEAN","DATE","DATETIME"];map={INTEGER:["INTERVAL"],REAL:["REAL"],NUMERIC:["DECIMAL","NUMERIC","MONEY"],BLOB:["BLOB","BYTES","BIT"],TEXT:["UUID","JSON","JSONB","XML","TIME","TIMEZ","TIMESTAMP","TIMESTAMPZ"]}}class Sqlite{static connection;static driver;static schema;static init(){var e=Sqlite.connection=new SqliteConnection(new Sqlite),{driver:t,schema:r}=e;return Object.assign(Sqlite,{driver:t,schema:r}),e}name;dialect;schema;strategy=new DefaultStrategy;$;variables={[DefaultValues.NOW]:"CURRENT_TIMESTAMP",[DefaultValues.MAX_TEXT]:"TEXT",[DefaultValues.MAX_TEXT_UNICODE]:"TEXT",[DefaultValues.TRUE]:"1",[DefaultValues.FALSE]:"0"};types;converters={...converterFor(DateTimeConverter.instance,"DATE","DATETIME","TIMESTAMP","TIMESTAMPZ")};constructor(){this.name=this.constructor.name,this.dialect=new SqliteDialect,this.$=this.dialect.$,this.types=new SqliteTypes,this.schema=new SqliteSchema(this)}}class SqliteConnection extends ConnectionBase{}class MySqlDialect{$;strategy=new DefaultStrategy;constructor(){this.$=Sql.create(this)}quote(e){return"`"+e+"`"}quoteTable(e){return this.quote(this.strategy.tableName(e))}quoteColumn(e){return this.quote(this.strategy.columnName(e))}sqlLimit(e,t){if(null==e&&null==t)throw new Error(`Invalid argument sqlLimit(${e}, ${t})`);return e?t?this.$.fragment("LIMIT $offset, $limit",{offset:e,limit:t}):this.$.fragment("LIMIT $offset, 18446744073709551615",{offset:e}):this.$.fragment("LIMIT $limit",{limit:t})}}class MySqlSchema extends SqliteSchema{}class MySqlTypes{native=["INTEGER","SMALLINT","BIGINT","REAL","DOUBLE","FLOAT","DECIMAL","NUMERIC","DECIMAL","MONEY","BOOLEAN","DATE","DATETIME","TIME","TIMEZ","TIMESTAMP","TIMESTAMPZ","INTERVAL","UUID","JSON","JSONB","XML","BLOB","BYTES","BIT"];map={DOUBLE:["REAL"],MONEY:["DECIMAL"],TIME:["TIMEZ"],TIMESTAMP:["TIMESTAMPZ"],INTEGER:["INTERVAL"],JSON:["JSONB"],TEXT:["XML"],BINARY:["BYTES"],"BINARY(1)":["BIT"]}}class MySql extends Sqlite{static connection;static driver;static schema;static init(){var e=MySql.connection=new MySqlConnection(new MySql),{driver:t,schema:r}=e;return Object.assign(MySql,{driver:t,schema:r}),e}constructor(){super(),this.dialect=new MySqlDialect,this.$=this.dialect.$,this.types=new MySqlTypes,this.schema=new MySqlSchema(this)}}class MySqlConnection extends ConnectionBase{}class PostgreSqlDialect{$;strategy=new DefaultStrategy;constructor(){this.$=Sql.create(this)}quote(e){return`"${e}"`}quoteTable(e){return this.quote(this.strategy.tableName(e))}quoteColumn(e){return this.quote(this.strategy.columnName(e))}sqlLimit(e,t){if(null==e&&null==t)throw new Error(`Invalid argument sqlLimit(${e}, ${t})`);return e?t?this.$.fragment("LIMIT $limit OFFSET $offset",{offset:e,limit:t}):this.$.fragment("OFFSET $offset",{offset:e}):this.$.fragment("LIMIT $limit",{limit:t})}}class PostgreSqlSchema extends SqliteSchema{}class PostgreSqlTypes{native=["INTEGER","SMALLINT","BIGINT","REAL","DOUBLE","FLOAT","DECIMAL","NUMERIC","DECIMAL","MONEY","BOOLEAN","DATE","DATETIME","TIME","TIMEZ","TIMESTAMP","TIMESTAMPZ","INTERVAL","UUID","JSON","JSONB","XML","BLOB","BYTES","BIT"];map={}}class PostgreSql extends Sqlite{static connection;static driver;static schema;static init(){var e=PostgreSql.connection=new PostgreSqlConnection(new PostgreSql),{driver:t,schema:r}=e;return Object.assign(PostgreSql,{driver:t,schema:r}),e}constructor(){super(),this.dialect=new PostgreSqlDialect,this.$=this.dialect.$,this.types=new PostgreSqlTypes,this.schema=new PostgreSqlSchema(this)}}class PostgreSqlConnection extends ConnectionBase{}var sqlite=Sqlite.init().$,mysql=MySql.init().$,postgres=PostgreSql.init().$;export{useFilter,toStr,table,sqlite,snakeCase,postgres,pick,omit,nextParam,mysql,mergeParams,isTemplateStrings,converterFor,column,WhereQuery,UpdateQuery,Table,SyncDbConnection,SqliteSchema,SqliteDialect,Sqlite,Sql,SnakeCaseStrategy,SelectQuery,Schema,PostgreSqlSchema,PostgreSqlDialect,PostgreSql,MySqlSchema,MySqlDialect,MySql,Meta,Inspect,DeleteQuery,DefaultValues,DefaultStrategy,DbConnection,DateTimeConverter,DataType}; | ||
`+this._limit:""}build(){return{sql:this.buildSelect()+this.buildFrom()+this.buildJoins()+this.buildWhere()+this.buildGroupBy()+this.buildHaving()+this.buildOrderBy()+this.buildLimit(),params:this.params,into:0==this._select.length?this.tables[0]:void 0}}}class UpdateQuery extends WhereQuery{get name(){return clsName("UpdateQuery",...this.tables)}_set=[];set(r,...e){if(r||(this._set.length=0),isTemplateStrings(r)){e=this.$(r,...e);this._set.push(this.mergeParams(e))}else if("object"==typeof r)if("sql"in r)this._set.push(this.mergeParams(r));else for(let[t,e]of Object.entries(r)){var s=this.meta.props.find(e=>e.name===t);if(!s)throw new Error(`Property ${t} not found in `+this.meta.name);if(!s.column)throw new Error(`Property ${t} is not a column`);this.params[s.name]=e,this._set.push(this.$.quote(s.column.name)+" = $"+s.name)}else{if("function"!=typeof r)throw new Error("invalid argument: "+typeof r);e=assertSql(r.call(this,...this.refs));this._set.push(this.mergeParams(e))}return this}get hasSet(){return 0<this._set.length}buildUpdate(){var e=this._set.join(", ");return`UPDATE ${this.quoteTable(this.meta.tableName)} SET `+e+this.buildWhere()}build(){return{sql:this.buildUpdate(),params:this.params}}}class DeleteQuery extends WhereQuery{get[type](){return clsName("DeleteQuery",...this.tables)}buildDelete(){return"DELETE FROM "+this.quoteTable(this.meta.tableName)+this.buildWhere()}build(){return{sql:this.buildDelete(),params:this.params}}}function table(r){return function(e){var t=Object.assign({},r,{name:r?.alias??e.name});e.$id||(e.$id=Symbol(e.name)),e.$type??={name:e.name},e.$type.table=t}}function column(n,i){return function(e,t){var r=Object.assign({},i,{type:n,name:i?.alias??t}),e=("id"===t&&(r.primaryKey=!0),e.constructor.$id||(e.constructor.$id=Symbol(e.constructor.name)),e.constructor.$props??(e.constructor.$props=[]));let s=e.find(e=>e.name===t);s||(s={name:t},e.push(s)),s.column=r,"symbol"==typeof s.column.type&&(s.column.type=s.column.type.description)}}function Table(e,s){if(!s)throw new Error("Table definition is required");var t=e;t.$id||(t.$id=Symbol(e.name)),t.$type??={name:e.name},t.$type.table=s.table??{},t.$type.table.name??=e.name;let n=t.$props??(t.$props=[]);return Object.keys(s.columns).forEach(t=>{var e=s.columns[t];if(!e)throw new Error(`Column definition for ${t} is missing`);if(!e.type)throw new Error(`Column type for ${t} is missing`);let r=n.find(e=>e.name===t);r||(r={name:t},n.push(r)),r.column=e,r.column.name??=e.alias??t,"symbol"==typeof r.column.type&&(r.column.type=r.column.type.description)}),e}(e=>{e.INTEGER="INTEGER",e.SMALLINT="SMALLINT",e.BIGINT="BIGINT",e.DECIMAL="DECIMAL",e.NUMERIC="NUMERIC",e.REAL="REAL",e.FLOAT="FLOAT",e.DOUBLE="DOUBLE",e.MONEY="MONEY",e.DATE="DATE",e.DATETIME="DATETIME",e.TIME="TIME",e.TIMEZ="TIMEZ",e.TIMESTAMP="TIMESTAMP",e.TIMESTAMPZ="TIMESTAMPZ",e.INTERVAL="INTERVAL",e.BOOLEAN="BOOLEAN",e.UUID="UUID",e.BLOB="BLOB",e.BYTES="BYTES",e.BIT="BIT",e.TEXT="TEXT",e.VARCHAR="VARCHAR",e.NVARCHAR="NVARCHAR",e.CHAR="CHAR",e.NCHAR="NCHAR",e.JSON="JSON",e.JSONB="JSONB",e.XML="XML"})(DataType||={});var DefaultValues={NOW:"{NOW}",MAX_TEXT:"{MAX_TEXT}",MAX_TEXT_UNICODE:"{MAX_TEXT_UNICODE}",TRUE:"{TRUE}",FALSE:"{FALSE}"};class SqliteDialect{$;strategy=new DefaultStrategy;constructor(){this.$=Sql.create(this)}quote(e){return`"${e}"`}quoteTable(e){return this.quote(this.strategy.tableName(e))}quoteColumn(e){return this.quote(this.strategy.columnName(e))}sqlLimit(e,t){if(null==e&&null==t)throw new Error(`Invalid argument sqlLimit(${e}, ${t})`);return e?this.$.fragment("LIMIT $limit OFFSET $offset",{offset:e,limit:t??-1}):this.$.fragment("LIMIT $limit",{limit:t})}}class SqliteSchema extends Schema{driver;constructor(e){super(e.dialect),this.driver=e}sqlTableNames(){return"SELECT name FROM sqlite_master WHERE type ='table' AND name NOT LIKE 'sqlite_%'"}sqlIndexDefinition(e,t){return`CREATE ${t.unique?"UNIQUE INDEX":"INDEX"} ${(`idx_${e.name}_`+t.name).toLowerCase()} ON ${this.dialect.quoteTable(e.name)} (${this.dialect.quoteColumn(t.name)})`}sqlColumnDefinition(e){var t=e.type;let r=this.driver.types.native.includes(t)?t:void 0;if(!r)for(var[s,n]of Object.entries(this.driver.types.map))if(n.includes(t)){r=s;break}r=r||t;let i=this.dialect.quoteColumn(e.name)+" "+r;return e.primaryKey&&(i+=" PRIMARY KEY"),e.autoIncrement&&(i+=" AUTOINCREMENT"),e.required&&(i+=" NOT NULL"),e.unique&&!e.index&&(i+=" UNIQUE"),e.defaultValue&&(e=this.driver.variables[e.defaultValue]??e.defaultValue,i+=" DEFAULT "+e),i}sqlLimit(e,t){if(null==e&&null==t)throw new Error(`Invalid argument sqlLimit(${e}, ${t})`);return e?this.driver.$.fragment("LIMIT $limit OFFSET $offset",{offset:e,limit:t??-1}):this.driver.$.fragment("LIMIT $limit",{limit:t})}}class SqliteTypes{native=["INTEGER","SMALLINT","BIGINT","REAL","DOUBLE","FLOAT","NUMERIC","DECIMAL","BOOLEAN","DATE","DATETIME"];map={INTEGER:["INTERVAL"],REAL:["REAL"],NUMERIC:["DECIMAL","NUMERIC","MONEY"],BLOB:["BLOB","BYTES","BIT"],TEXT:["UUID","JSON","JSONB","XML","TIME","TIMEZ","TIMESTAMP","TIMESTAMPZ"]}}class Sqlite{static connection;static driver;static schema;static init(){var e=Sqlite.connection=new SqliteConnection(new Sqlite),{driver:t,schema:r}=e;return Object.assign(Sqlite,{driver:t,schema:r}),e}name;dialect;schema;strategy=new DefaultStrategy;$;variables={[DefaultValues.NOW]:"CURRENT_TIMESTAMP",[DefaultValues.MAX_TEXT]:"TEXT",[DefaultValues.MAX_TEXT_UNICODE]:"TEXT",[DefaultValues.TRUE]:"1",[DefaultValues.FALSE]:"0"};types;converters={...converterFor(DateTimeConverter.instance,"DATE","DATETIME","TIMESTAMP","TIMESTAMPZ")};constructor(){this.name=this.constructor.name,this.dialect=new SqliteDialect,this.$=this.dialect.$,this.types=new SqliteTypes,this.schema=this.$.schema=new SqliteSchema(this)}}class SqliteConnection extends ConnectionBase{}class MySqlDialect{$;strategy=new DefaultStrategy;constructor(){this.$=Sql.create(this)}quote(e){return"`"+e+"`"}quoteTable(e){return this.quote(this.strategy.tableName(e))}quoteColumn(e){return this.quote(this.strategy.columnName(e))}sqlLimit(e,t){if(null==e&&null==t)throw new Error(`Invalid argument sqlLimit(${e}, ${t})`);return e?t?this.$.fragment("LIMIT $offset, $limit",{offset:e,limit:t}):this.$.fragment("LIMIT $offset, 18446744073709551615",{offset:e}):this.$.fragment("LIMIT $limit",{limit:t})}}class MySqlSchema extends SqliteSchema{}class MySqlTypes{native=["INTEGER","SMALLINT","BIGINT","REAL","DOUBLE","FLOAT","DECIMAL","NUMERIC","DECIMAL","MONEY","BOOLEAN","DATE","DATETIME","TIME","TIMEZ","TIMESTAMP","TIMESTAMPZ","INTERVAL","UUID","JSON","JSONB","XML","BLOB","BYTES","BIT"];map={DOUBLE:["REAL"],MONEY:["DECIMAL"],TIME:["TIMEZ"],TIMESTAMP:["TIMESTAMPZ"],INTEGER:["INTERVAL"],JSON:["JSONB"],TEXT:["XML"],BINARY:["BYTES"],"BINARY(1)":["BIT"]}}class MySql extends Sqlite{static connection;static driver;static schema;static init(){var e=MySql.connection=new MySqlConnection(new MySql),{driver:t,schema:r}=e;return Object.assign(MySql,{driver:t,schema:r}),e}constructor(){super(),this.dialect=new MySqlDialect,this.$=this.dialect.$,this.types=new MySqlTypes,this.schema=this.$.schema=new MySqlSchema(this)}}class MySqlConnection extends ConnectionBase{}class PostgreSqlDialect{$;strategy=new DefaultStrategy;constructor(){this.$=Sql.create(this)}quote(e){return`"${e}"`}quoteTable(e){return this.quote(this.strategy.tableName(e))}quoteColumn(e){return this.quote(this.strategy.columnName(e))}sqlLimit(e,t){if(null==e&&null==t)throw new Error(`Invalid argument sqlLimit(${e}, ${t})`);return e?t?this.$.fragment("LIMIT $limit OFFSET $offset",{offset:e,limit:t}):this.$.fragment("OFFSET $offset",{offset:e}):this.$.fragment("LIMIT $limit",{limit:t})}}class PostgreSqlSchema extends SqliteSchema{}class PostgreSqlTypes{native=["INTEGER","SMALLINT","BIGINT","REAL","DOUBLE","FLOAT","DECIMAL","NUMERIC","DECIMAL","MONEY","BOOLEAN","DATE","DATETIME","TIME","TIMEZ","TIMESTAMP","TIMESTAMPZ","INTERVAL","UUID","JSON","JSONB","XML","BLOB","BYTES","BIT"];map={}}class PostgreSql extends Sqlite{static connection;static driver;static schema;static init(){var e=PostgreSql.connection=new PostgreSqlConnection(new PostgreSql),{driver:t,schema:r}=e;return Object.assign(PostgreSql,{driver:t,schema:r}),e}constructor(){super(),this.dialect=new PostgreSqlDialect,this.$=this.dialect.$,this.types=new PostgreSqlTypes,this.schema=this.$.schema=new PostgreSqlSchema(this)}}class PostgreSqlConnection extends ConnectionBase{}var sqlite=Sqlite.init().$,mysql=MySql.init().$,postgres=PostgreSql.init().$;export{useFilter,toStr,table,sqlite,snakeCase,postgres,pick,omit,nextParam,mysql,mergeParams,isTemplateStrings,converterFor,column,WhereQuery,Watch,UpdateQuery,Table,SyncDbConnection,SqliteSchema,SqliteDialect,Sqlite,Sql,SnakeCaseStrategy,SelectQuery,Schema,PostgreSqlSchema,PostgreSqlDialect,PostgreSql,MySqlSchema,MySqlDialect,MySql,Meta,Inspect,DeleteQuery,DefaultValues,DefaultStrategy,DbConnection,DateTimeConverter,DataType}; |
{ | ||
"name": "litdb", | ||
"type": "module", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"main": "./dist/index.cjs", | ||
@@ -6,0 +6,0 @@ "module": "./dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
133339
2968