@egi/smart-db 2.4.0 → 2.4.2

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.
@@ -1 +1 @@
1
- import fs from"fs";import _ from"lodash";import process from"process";import{SmartDbBetterSqlite3}from"../drivers/smart-db-better-sqlite3";import{SmartDbCoreTableModel}from"../models/smart-db-core-table-model";import{SqliteMasterModel}from"../models/sqlite-master-model";import{IN,NE}from"../smart-db-globals";function getType(e){let t;return t=e?e.match(/varchar/i)||e.match(/text/i)?"string":e.match(/integer\(1\)/i)?"boolean":e.match(/date/i)?"Date":e.match(/integer/i)||e.match(/number/i)?"number":e||"SqlValueType":"SqlValueType",t}function extractDbApi(e){console.log(`extract interface from '${e.db.getDbConnector()}' to '${e.modelDirectory}'`),fs.existsSync(e.modelDirectory)||fs.mkdirSync(e.modelDirectory,{recursive:!0});const t=e.db.getAllSync(SqliteMasterModel,{type:IN(["table","view"]),name:NE("sqlite_sequence")});if(!1===t)console.error(e.db.getLastError()),process.abort();else{let n=[];if(!e.includeCoreTables&&e.db.existsSync(SmartDbCoreTableModel)){const t=e.db.getAllSync(SmartDbCoreTableModel);if(!1===t)throw e.db.getLastError();t.forEach(e=>{n.push(e.name)})}const r=[];t.forEach(t=>{if(!n.includes(t.name)){const n=t.name[0].toUpperCase()+_.camelCase(t.name.substr(1))+"Model";r.push(n);const a=[];e.db.getTableInfo(t.name).then(r=>{const s=r.fields;let i=!1,o="",l="/* eslint-disable @typescript-eslint/member-ordering */\n";if(l+="// noinspection JSUnusedGlobalSymbols\n\n",s){l+=`import {AbstractModel, GenericModelData, ModelAttributeMap} from "${e.abstractModelModule}";\n`,o+=`export interface ${n}Data extends GenericModelData {\n`;let r,c="",m="",b=!1;const p=[];s.forEach(e=>{const t=e.name.match(/([a-z0-9]{1,4})_/i);e.isPk&&(c=e.name,t&&(m=t[1])),t?p.includes(t[1])||p.push(t[1]):b=!0}),m||b||1!=p.length||(m=p[0]),m&&(r=new RegExp(`^${m}_(.*)$`));const d={};s.forEach(n=>{const s=getType(n.type);let c;i||"SqlValueType"!=s||(l+=`import {SqlValueType} from "${e.smartDbInterfaces}";\n`,i=!0);const m=r&&n.name.match(r);c=m?_.camelCase(m[1]):_.camelCase(n.name);let b=!0;c!=n.name&&(a.push({name:c,attribute:c,type:s,typeScriptStyle:b,alias:n.name}),b=!1),a.push({name:n.name,attribute:c,type:s,physical:void 0!==n.cid,typeScriptStyle:b}),d[c]=s,"user"==t.name&&"name"==c&&(o+=" // @ts-ignore"),o+=` ${c}?: ${s};\n`}),o+="}\n\n",o+=`export class ${n} extends AbstractModel<${n}, ${n}Data> {\n`,_.forEach(d,(e,t)=>{o+=` private _${t}?: ${e};\n`}),"user"==t.name&&(o+=" private _hash?: string;\n",o+=" private _privileges?: string[];\n"),o+="\n",o+=" static readonly attributeMap: ModelAttributeMap = {\n",a.forEach((e,t)=>{t>0&&(o+=",\n"),o+=` ${e.name}: {\n`,e.physical&&(o+=" physical: true,\n"),e.alias&&(o+=` alias: "${e.alias}",\n`),e.virtual&&(o+=" virtual: true,\n"),e.typeScriptStyle&&(o+=" typeScriptStyle: true,\n"),o+=` type: "${e.type}",\n`,o+=` attribute: "_${e.attribute}"\n`,o+=" }"}),o+="\n",o+=" };\n",o+="\n",o+=" static getClassName(): string {\n",o+=` return "${n}";\n`,o+=" }\n",o+="\n",o+=" static getTableName(): string {\n",o+=` return "${t.name}";\n`,o+=" }\n",o+="\n",o+=" static getPrimaryKey(): string {\n",o+=` return "${c}";\n`,o+=" }\n",o+="\n",o+=` static from(other: ${n} | ${n}Data): ${n} {\n`,o+=` let value: ${n} = null;\n`,o+=" if (other) {\n",o+=` value = new ${n}();\n`,o+=` if (other instanceof ${n}) {\n`,o+=" Object.assign(value, other);\n",o+=" } else {\n",o+=" value.assign(other);\n",o+=" }\n",o+=" }\n",o+=" return value;\n",o+=" }\n",o+="\n",o+=` constructor(data?: ${n} | ${n}Data) {\n`,o+=" super();\n",o+=" if (data) {\n",o+=" this.assign(data);\n",o+=" }\n",o+=" }\n",o+="\n",o+=` public clone(): ${n} {\n`,o+=` return ${n}.from(this);\n`,o+=" }\n",o+="\n",o+=" public getClassName(): string {\n",o+=` return "${n}";\n`,o+=" }\n",o+="\n",o+=" public getTableName(): string {\n",o+=` return "${t.name}";\n`,o+=" }\n",o+="\n",o+=" public getPrimaryKey(): string {\n",o+=` return "${c}";\n`,o+=" }\n",o+="\n",o+=" public getAttributeMap(): ModelAttributeMap {\n",o+=` return ${n}.attributeMap;\n`,o+=" }\n",a.forEach(e=>{let t;o+="\n",t=e.name.length<3||e.name.match(/_/)?"FunctionNamingConventionJS":"",""!==t&&(o+=` // noinspection ${t}\n`),o+=` get ${e.name}(): ${e.type} {\n`,o+=` return this._${e.attribute};\n`,o+=" }\n\n",""!==t&&(o+=` // noinspection ${t}\n`),o+=` set ${e.name}(${e.attribute}: ${e.type}) {\n`,o+=` this._${e.attribute} = ${e.attribute};\n`,o+=" }\n"}),"user"==t.name&&(o+="\n",o+=" get hash(): string {\n",o+=" return this._hash;\n",o+=" }\n\n",o+=" set hash(hash: string) {\n",o+=" this._hash = hash;\n",o+=" }\n",o+="\n",o+=" get privileges(): string[] {\n",o+=" return this._privileges;\n",o+=" }\n\n",o+=" set privileges(p: string[]) {\n",o+=" this._privileges = p;\n",o+=" }\n"),o+="}\n",o=l+"\n"+o;const u=t.name.replace(/[^[a-z0-9]/g,"-")+"-model.ts";fs.writeFileSync(`${e.modelDirectory}/${u}`,o)}else console.log("error: table has no fields")}).catch(e=>{console.error(e),process.abort()})}});let a=`import {AbstractModel} from "${e.abstractModelModule}";\n`;_.forEach(r,e=>{a+=`import {${e}} from "./${_.kebabCase(e)}";\n`}),a+="\n",a+="interface SmartDbDictionaryEntry {\n",a+=" cls: "+r.map(e=>"typeof "+e).join(" |\n "),a+=";\n",a+="}\n\n",a+="export class SmartDbDictionary {\n",a+=" static models: { [relation: string]: SmartDbDictionaryEntry; } = {\n",_.forEach(r,e=>{a+=` ${e}: {\n`,a+=` cls: ${e}\n`,a+=" },\n"}),a=a.substring(0,a.length-2)+"\n",a+=" };\n",a+="}\n",fs.writeFileSync(e.modelDirectory+"/smart-db-dictionary.ts",a)}e.db.closeSync()}(()=>{if(4==process.argv.length){extractDbApi({modelDirectory:process.argv[3],smartDbInterfaces:"@egi/smart-db",abstractModelModule:"@egi/smart-db",db:new SmartDbBetterSqlite3(process.argv[2],{verbose:(e,...t)=>{console.log("DB LOG",e,...t)}})})}else if(2==process.argv.length&&fs.existsSync("src/helpers/extract-db-api.ts")){const e=`/tmp/smart-db-core.${process.pid}.sqlite3`,t={includeCoreTables:!0,modelDirectory:"src/models",smartDbInterfaces:"../smart-db-interfaces",abstractModelModule:"./abstract-models",db:new SmartDbBetterSqlite3(e,{verbose:(e,...t)=>{console.log("DB LOG",e,...t)}})};t.db.initDb({module:"smart-db-core",sqlFilesDirectory:"assets/sqlite3"}).then(()=>{extractDbApi(t),fs.unlinkSync(e),t.db.closeSync()})}else console.log("usage: extract-db-api {db-connector|path-to-db} {target-models-directory}")})();
1
+ import fs from"fs";import _ from"lodash";import process from"process";import{SmartDbBetterSqlite3}from"../drivers/smart-db-better-sqlite3";import{SmartDbCoreTableModel}from"../models/smart-db-core-table-model";import{SqliteMasterModel}from"../models/sqlite-master-model";import{IN,NE}from"../smart-db-globals";function getType(e){let t;return t=e?e.match(/varchar/i)||e.match(/text/i)?"string":e.match(/integer\(1\)/i)?"boolean":e.match(/date/i)?"Date":e.match(/integer/i)||e.match(/number/i)?"number":e||"SqlValueType":"SqlValueType",t}function extractDbApi(e){console.log(`extract interface from '${e.db.getDbConnector()}' to '${e.modelDirectory}'`),fs.existsSync(e.modelDirectory)||fs.mkdirSync(e.modelDirectory,{recursive:!0});const t=e.db.getAllSync(SqliteMasterModel,{type:IN(["table","view"]),name:NE("sqlite_sequence")});if(!1===t)console.error(e.db.getLastError()),process.abort();else{let r=[];if(!e.includeCoreTables&&e.db.existsSync(SmartDbCoreTableModel)){const t=e.db.getAllSync(SmartDbCoreTableModel);if(!1===t)throw e.db.getLastError();t.forEach(e=>{r.push(e.name)})}const n=[];t.forEach(t=>{if(!r.includes(t.name)){const r=t.name[0].toUpperCase()+_.camelCase(t.name.substr(1))+"Model";n.push(r);const a=[];e.db.getTableInfo(t.name).then(n=>{const s=n.fields;let o=!1,i="",l="",c="",m="",p="";const b=t.name.replace(/[^[a-z0-9]/g,"-")+"-model";if(i+="/* eslint-disable @typescript-eslint/member-ordering */\n",i+="// noinspection JSUnusedGlobalSymbols\n",s){e.abstractModelModule==e.smartDbInterfaces?e.separateApi?(c+=`import {GenericModelData} from "${e.abstractModelModule}";\n`,p+=`import {AbstractModel, ModelAttributeMap} from "${e.abstractModelModule}";\n`,p+=`import {${r}Data} from "./${b}-api";\n`):p+=`import {AbstractModel, GenericModelData, ModelAttributeMap} from "${e.abstractModelModule}";\n`:e.separateApi?(c+=`import {GenericModelData} from "${e.smartDbInterfaces}";\n`,p+=`import {ModelAttributeMap} from "${e.smartDbInterfaces}";\n`,p+=`import {AbstractModel} from "${e.abstractModelModule}";\n`,p+=`import {${r}Data} from "./${b}-api";\n`):(p+=`import {GenericModelData, ModelAttributeMap} from "${e.smartDbInterfaces}";\n`,p+=`import {AbstractModel} from "${e.abstractModelModule}";\n`),l+=`export interface ${r}Data extends GenericModelData {\n`;let n,d="",u="",f=!1;const h=[];s.forEach(e=>{const t=e.name.match(/([a-z0-9]{1,4})_/i);e.isPk&&(d=e.name,t&&(u=t[1])),t?h.includes(t[1])||h.push(t[1]):f=!0}),u||f||1!=h.length||(u=h[0]),u&&(n=new RegExp(`^${u}_(.*)$`));const g={};s.forEach(r=>{const s=getType(r.type);let i;o||"SqlValueType"!=s||(p+=`import {SqlValueType} from "${e.smartDbInterfaces}";\n`,o=!0);const c=n&&r.name.match(n);i=c?_.camelCase(c[1]):_.camelCase(r.name);let m=!0;i!=r.name&&(a.push({name:i,attribute:i,type:s,typeScriptStyle:m,alias:r.name}),m=!1),a.push({name:r.name,attribute:i,type:s,physical:void 0!==r.cid,typeScriptStyle:m}),g[i]=s,"user"==t.name&&"name"==i&&(l+=" // @ts-ignore"),l+=` ${i}?: ${s};\n`}),l+="}\n",m+=`export class ${r} extends AbstractModel<${r}, ${r}Data> {\n`,_.forEach(g,(e,t)=>{m+=` private _${t}?: ${e};\n`}),"user"==t.name&&(m+=" private _hash?: string;\n",m+=" private _privileges?: string[];\n"),m+="\n",m+=" static readonly attributeMap: ModelAttributeMap = {\n",a.forEach((e,t)=>{t>0&&(m+=",\n"),m+=` ${e.name}: {\n`,e.physical&&(m+=" physical: true,\n"),e.alias&&(m+=` alias: "${e.alias}",\n`),e.virtual&&(m+=" virtual: true,\n"),e.typeScriptStyle&&(m+=" typeScriptStyle: true,\n"),m+=` type: "${e.type}",\n`,m+=` attribute: "_${e.attribute}"\n`,m+=" }"}),m+="\n",m+=" };\n",m+="\n",m+=" static getClassName(): string {\n",m+=` return "${r}";\n`,m+=" }\n",m+="\n",m+=" static getTableName(): string {\n",m+=` return "${t.name}";\n`,m+=" }\n",m+="\n",m+=" static getPrimaryKey(): string {\n",m+=` return "${d}";\n`,m+=" }\n",m+="\n",m+=` static from(other: ${r} | ${r}Data): ${r} {\n`,m+=` let value: ${r} = null;\n`,m+=" if (other) {\n",m+=` value = new ${r}();\n`,m+=` if (other instanceof ${r}) {\n`,m+=" Object.assign(value, other);\n",m+=" } else {\n",m+=" value.assign(other);\n",m+=" }\n",m+=" }\n",m+=" return value;\n",m+=" }\n",m+="\n",m+=` constructor(data?: ${r} | ${r}Data) {\n`,m+=" super();\n",m+=" if (data) {\n",m+=" this.assign(data);\n",m+=" }\n",m+=" }\n",m+="\n",m+=` public clone(): ${r} {\n`,m+=` return ${r}.from(this);\n`,m+=" }\n",m+="\n",m+=" public getClassName(): string {\n",m+=` return "${r}";\n`,m+=" }\n",m+="\n",m+=" public getTableName(): string {\n",m+=` return "${t.name}";\n`,m+=" }\n",m+="\n",m+=" public getPrimaryKey(): string {\n",m+=` return "${d}";\n`,m+=" }\n",m+="\n",m+=" public getAttributeMap(): ModelAttributeMap {\n",m+=` return ${r}.attributeMap;\n`,m+=" }\n",a.forEach(e=>{let t;m+="\n",t=e.name.length<3||e.name.match(/_/)?"FunctionNamingConventionJS":"",""!==t&&(m+=` // noinspection ${t}\n`),m+=` get ${e.name}(): ${e.type} {\n`,m+=` return this._${e.attribute};\n`,m+=" }\n\n",""!==t&&(m+=` // noinspection ${t}\n`),m+=` set ${e.name}(${e.attribute}: ${e.type}) {\n`,m+=` this._${e.attribute} = ${e.attribute};\n`,m+=" }\n"}),"user"==t.name&&(m+="\n",m+=" get hash(): string {\n",m+=" return this._hash;\n",m+=" }\n\n",m+=" set hash(hash: string) {\n",m+=" this._hash = hash;\n",m+=" }\n",m+="\n",m+=" get privileges(): string[] {\n",m+=" return this._privileges;\n",m+=" }\n\n",m+=" set privileges(p: string[]) {\n",m+=" this._privileges = p;\n",m+=" }\n"),m+="}\n",e.separateApi?(l=i+"\n"+c+"\n"+l,fs.writeFileSync(`${e.modelDirectory}/${b+"-api.ts"}`,l),m=i+"\n"+p+"\n"+m):m=i+"\n"+p+"\n"+l+"\n"+m,fs.writeFileSync(`${e.modelDirectory}/${b+".ts"}`,m)}else console.log("error: table has no fields")}).catch(e=>{console.error(e),process.abort()})}});let a=`import {AbstractModel} from "${e.abstractModelModule}";\n`;_.forEach(n,e=>{a+=`import {${e}} from "./${_.kebabCase(e)}";\n`}),a+="\n",a+="interface SmartDbDictionaryEntry {\n",a+=" cls: "+n.map(e=>"typeof "+e).join(" |\n "),a+=";\n",a+="}\n\n",a+="export class SmartDbDictionary {\n",a+=" static models: { [relation: string]: SmartDbDictionaryEntry; } = {\n",_.forEach(n,e=>{a+=` ${e}: {\n`,a+=` cls: ${e}\n`,a+=" },\n"}),a=a.substring(0,a.length-2)+"\n",a+=" };\n",a+="}\n",fs.writeFileSync(e.modelDirectory+"/smart-db-dictionary.ts",a)}e.db.closeSync()}(()=>{let e=!1;const t=Array.from(process.argv);if(console.log(t),"--separate-api"==t[2]&&(e=!0,t.splice(2,1)),console.log(t),4==t.length){extractDbApi({modelDirectory:t[3],smartDbInterfaces:"@egi/smart-db",abstractModelModule:"@egi/smart-db",separateApi:e,db:new SmartDbBetterSqlite3(t[2],{verbose:(e,...t)=>{console.log("DB LOG",e,...t)}})})}else if(2==t.length&&fs.existsSync("src/helpers/extract-db-api.ts")){const t=`/tmp/smart-db-core.${process.pid}.sqlite3`,r={includeCoreTables:!0,modelDirectory:"src/models",smartDbInterfaces:"../smart-db-interfaces",abstractModelModule:"./abstract-model",separateApi:e,db:new SmartDbBetterSqlite3(t,{verbose:(e,...t)=>{console.log("DB LOG",e,...t)}})};r.db.initDb({module:"smart-db-core",sqlFilesDirectory:"assets/sqlite3"}).then(()=>{extractDbApi(r),fs.unlinkSync(t),r.db.closeSync()})}else console.log("usage: extract-db-api {db-connector|path-to-db} {target-models-directory}")})();
@@ -10,26 +10,26 @@ export declare class SmartDbCoreTableModel extends AbstractModel<SmartDbCoreTabl
10
10
  private _name?;
11
11
  private _type?;
12
12
  static readonly attributeMap: ModelAttributeMap;
13
- constructor(data?: SmartDbCoreTableModel | SmartDbCoreTableModelData);
14
13
  static getClassName(): string;
15
14
  static getTableName(): string;
16
15
  static getPrimaryKey(): string;
17
16
  static from(other: SmartDbCoreTableModel | SmartDbCoreTableModelData): SmartDbCoreTableModel;
17
+ constructor(data?: SmartDbCoreTableModel | SmartDbCoreTableModelData);
18
18
  clone(): SmartDbCoreTableModel;
19
19
  getClassName(): string;
20
20
  getTableName(): string;
21
21
  getPrimaryKey(): string;
22
22
  getAttributeMap(): ModelAttributeMap;
23
- get ctb_id(): number;
24
- set ctb_id(id: number);
25
- get ctb_name(): string;
26
- set ctb_name(name: string);
27
- get ctb_type(): string;
28
- set ctb_type(type: string);
29
23
  get id(): number;
30
24
  set id(id: number);
25
+ get ctb_id(): number;
26
+ set ctb_id(id: number);
31
27
  get name(): string;
32
28
  set name(name: string);
29
+ get ctb_name(): string;
30
+ set ctb_name(name: string);
33
31
  get type(): string;
34
32
  set type(type: string);
33
+ get ctb_type(): string;
34
+ set ctb_type(type: string);
35
35
  }
@@ -1 +1 @@
1
- import{AbstractModel}from"./abstract-model";export class SmartDbCoreTableModel extends AbstractModel{constructor(t){super(),t&&this.assign(t)}static getClassName(){return"SmartDbCoreTableModel"}static getTableName(){return"smart_db_core_table"}static getPrimaryKey(){return"ctb_id"}static from(t){let e=null;return t&&(e=new SmartDbCoreTableModel,t instanceof SmartDbCoreTableModel?Object.assign(e,t):e.assign(t)),e}clone(){return SmartDbCoreTableModel.from(this)}getClassName(){return"SmartDbCoreTableModel"}getTableName(){return"smart_db_core_table"}getPrimaryKey(){return"ctb_id"}getAttributeMap(){return SmartDbCoreTableModel.attributeMap}get ctb_id(){return this._id}set ctb_id(t){this._id=t}get ctb_name(){return this._name}set ctb_name(t){this._name=t}get ctb_type(){return this._type}set ctb_type(t){this._type=t}get id(){return this._id}set id(t){this._id=t}get name(){return this._name}set name(t){this._name=t}get type(){return this._type}set type(t){this._type=t}}SmartDbCoreTableModel.attributeMap={id:{alias:"ctb_id",typeScriptStyle:!0,type:"number",attribute:"_id"},ctb_id:{physical:!0,type:"number",attribute:"_id"},name:{alias:"ctb_name",typeScriptStyle:!0,type:"string",attribute:"_name"},ctb_name:{physical:!0,type:"string",attribute:"_name"},type:{alias:"ctb_type",typeScriptStyle:!0,type:"string",attribute:"_type"},ctb_type:{physical:!0,type:"string",attribute:"_type"}};
1
+ import{AbstractModel}from"./abstract-model";export class SmartDbCoreTableModel extends AbstractModel{constructor(t){super(),t&&this.assign(t)}static getClassName(){return"SmartDbCoreTableModel"}static getTableName(){return"smart_db_core_table"}static getPrimaryKey(){return"ctb_id"}static from(t){let e=null;return t&&(e=new SmartDbCoreTableModel,t instanceof SmartDbCoreTableModel?Object.assign(e,t):e.assign(t)),e}clone(){return SmartDbCoreTableModel.from(this)}getClassName(){return"SmartDbCoreTableModel"}getTableName(){return"smart_db_core_table"}getPrimaryKey(){return"ctb_id"}getAttributeMap(){return SmartDbCoreTableModel.attributeMap}get id(){return this._id}set id(t){this._id=t}get ctb_id(){return this._id}set ctb_id(t){this._id=t}get name(){return this._name}set name(t){this._name=t}get ctb_name(){return this._name}set ctb_name(t){this._name=t}get type(){return this._type}set type(t){this._type=t}get ctb_type(){return this._type}set ctb_type(t){this._type=t}}SmartDbCoreTableModel.attributeMap={id:{alias:"ctb_id",typeScriptStyle:!0,type:"number",attribute:"_id"},ctb_id:{physical:!0,type:"number",attribute:"_id"},name:{alias:"ctb_name",typeScriptStyle:!0,type:"string",attribute:"_name"},ctb_name:{physical:!0,type:"string",attribute:"_name"},type:{alias:"ctb_type",typeScriptStyle:!0,type:"string",attribute:"_type"},ctb_type:{physical:!0,type:"string",attribute:"_type"}};
@@ -20,46 +20,46 @@ export declare class SmartDbLogModel extends AbstractModel<SmartDbLogModel, Smar
20
20
  private _user?;
21
21
  private _timestamp?;
22
22
  static readonly attributeMap: ModelAttributeMap;
23
- constructor(data?: SmartDbLogModel | SmartDbLogModelData);
24
23
  static getClassName(): string;
25
24
  static getTableName(): string;
26
25
  static getPrimaryKey(): string;
27
26
  static from(other: SmartDbLogModel | SmartDbLogModelData): SmartDbLogModel;
27
+ constructor(data?: SmartDbLogModel | SmartDbLogModelData);
28
28
  clone(): SmartDbLogModel;
29
29
  getClassName(): string;
30
30
  getTableName(): string;
31
31
  getPrimaryKey(): string;
32
32
  getAttributeMap(): ModelAttributeMap;
33
- get data(): string;
34
- set data(data: string);
35
33
  get id(): number;
36
34
  set id(id: number);
37
- get info(): string;
38
- set info(info: string);
39
- get location(): string;
40
- set location(location: string);
41
- get log_data(): string;
42
- set log_data(data: string);
43
35
  get log_id(): number;
44
36
  set log_id(id: number);
45
- get log_info(): string;
46
- set log_info(info: string);
47
- get log_location(): string;
48
- set log_location(location: string);
37
+ get severity(): string;
38
+ set severity(severity: string);
49
39
  get log_severity(): string;
50
40
  set log_severity(severity: string);
51
- get log_timestamp(): Date;
52
- set log_timestamp(timestamp: Date);
41
+ get type(): string;
42
+ set type(type: string);
53
43
  get log_type(): string;
54
44
  set log_type(type: string);
45
+ get location(): string;
46
+ set location(location: string);
47
+ get log_location(): string;
48
+ set log_location(location: string);
49
+ get info(): string;
50
+ set info(info: string);
51
+ get log_info(): string;
52
+ set log_info(info: string);
53
+ get data(): string;
54
+ set data(data: string);
55
+ get log_data(): string;
56
+ set log_data(data: string);
57
+ get user(): string;
58
+ set user(user: string);
55
59
  get log_user(): string;
56
60
  set log_user(user: string);
57
- get severity(): string;
58
- set severity(severity: string);
59
61
  get timestamp(): Date;
60
62
  set timestamp(timestamp: Date);
61
- get type(): string;
62
- set type(type: string);
63
- get user(): string;
64
- set user(user: string);
63
+ get log_timestamp(): Date;
64
+ set log_timestamp(timestamp: Date);
65
65
  }
@@ -1 +1 @@
1
- import{AbstractModel}from"./abstract-model";export class SmartDbLogModel extends AbstractModel{constructor(t){super(),t&&this.assign(t)}static getClassName(){return"SmartDbLogModel"}static getTableName(){return"smart_db_log"}static getPrimaryKey(){return"log_id"}static from(t){let e=null;return t&&(e=new SmartDbLogModel,t instanceof SmartDbLogModel?Object.assign(e,t):e.assign(t)),e}clone(){return SmartDbLogModel.from(this)}getClassName(){return"SmartDbLogModel"}getTableName(){return"smart_db_log"}getPrimaryKey(){return"log_id"}getAttributeMap(){return SmartDbLogModel.attributeMap}get data(){return this._data}set data(t){this._data=t}get id(){return this._id}set id(t){this._id=t}get info(){return this._info}set info(t){this._info=t}get location(){return this._location}set location(t){this._location=t}get log_data(){return this._data}set log_data(t){this._data=t}get log_id(){return this._id}set log_id(t){this._id=t}get log_info(){return this._info}set log_info(t){this._info=t}get log_location(){return this._location}set log_location(t){this._location=t}get log_severity(){return this._severity}set log_severity(t){this._severity=t}get log_timestamp(){return this._timestamp}set log_timestamp(t){this._timestamp=t}get log_type(){return this._type}set log_type(t){this._type=t}get log_user(){return this._user}set log_user(t){this._user=t}get severity(){return this._severity}set severity(t){this._severity=t}get timestamp(){return this._timestamp}set timestamp(t){this._timestamp=t}get type(){return this._type}set type(t){this._type=t}get user(){return this._user}set user(t){this._user=t}}SmartDbLogModel.attributeMap={id:{alias:"log_id",typeScriptStyle:!0,type:"number",attribute:"_id"},log_id:{physical:!0,type:"number",attribute:"_id"},severity:{alias:"log_severity",typeScriptStyle:!0,type:"string",attribute:"_severity"},log_severity:{physical:!0,type:"string",attribute:"_severity"},type:{alias:"log_type",typeScriptStyle:!0,type:"string",attribute:"_type"},log_type:{physical:!0,type:"string",attribute:"_type"},location:{alias:"log_location",typeScriptStyle:!0,type:"string",attribute:"_location"},log_location:{physical:!0,type:"string",attribute:"_location"},info:{alias:"log_info",typeScriptStyle:!0,type:"string",attribute:"_info"},log_info:{physical:!0,type:"string",attribute:"_info"},data:{alias:"log_data",typeScriptStyle:!0,type:"string",attribute:"_data"},log_data:{physical:!0,type:"string",attribute:"_data"},user:{alias:"log_user",typeScriptStyle:!0,type:"string",attribute:"_user"},log_user:{physical:!0,type:"string",attribute:"_user"},timestamp:{alias:"log_timestamp",typeScriptStyle:!0,type:"Date",attribute:"_timestamp"},log_timestamp:{physical:!0,type:"Date",attribute:"_timestamp"}};
1
+ import{AbstractModel}from"./abstract-model";export class SmartDbLogModel extends AbstractModel{constructor(t){super(),t&&this.assign(t)}static getClassName(){return"SmartDbLogModel"}static getTableName(){return"smart_db_log"}static getPrimaryKey(){return"log_id"}static from(t){let e=null;return t&&(e=new SmartDbLogModel,t instanceof SmartDbLogModel?Object.assign(e,t):e.assign(t)),e}clone(){return SmartDbLogModel.from(this)}getClassName(){return"SmartDbLogModel"}getTableName(){return"smart_db_log"}getPrimaryKey(){return"log_id"}getAttributeMap(){return SmartDbLogModel.attributeMap}get id(){return this._id}set id(t){this._id=t}get log_id(){return this._id}set log_id(t){this._id=t}get severity(){return this._severity}set severity(t){this._severity=t}get log_severity(){return this._severity}set log_severity(t){this._severity=t}get type(){return this._type}set type(t){this._type=t}get log_type(){return this._type}set log_type(t){this._type=t}get location(){return this._location}set location(t){this._location=t}get log_location(){return this._location}set log_location(t){this._location=t}get info(){return this._info}set info(t){this._info=t}get log_info(){return this._info}set log_info(t){this._info=t}get data(){return this._data}set data(t){this._data=t}get log_data(){return this._data}set log_data(t){this._data=t}get user(){return this._user}set user(t){this._user=t}get log_user(){return this._user}set log_user(t){this._user=t}get timestamp(){return this._timestamp}set timestamp(t){this._timestamp=t}get log_timestamp(){return this._timestamp}set log_timestamp(t){this._timestamp=t}}SmartDbLogModel.attributeMap={id:{alias:"log_id",typeScriptStyle:!0,type:"number",attribute:"_id"},log_id:{physical:!0,type:"number",attribute:"_id"},severity:{alias:"log_severity",typeScriptStyle:!0,type:"string",attribute:"_severity"},log_severity:{physical:!0,type:"string",attribute:"_severity"},type:{alias:"log_type",typeScriptStyle:!0,type:"string",attribute:"_type"},log_type:{physical:!0,type:"string",attribute:"_type"},location:{alias:"log_location",typeScriptStyle:!0,type:"string",attribute:"_location"},log_location:{physical:!0,type:"string",attribute:"_location"},info:{alias:"log_info",typeScriptStyle:!0,type:"string",attribute:"_info"},log_info:{physical:!0,type:"string",attribute:"_info"},data:{alias:"log_data",typeScriptStyle:!0,type:"string",attribute:"_data"},log_data:{physical:!0,type:"string",attribute:"_data"},user:{alias:"log_user",typeScriptStyle:!0,type:"string",attribute:"_user"},log_user:{physical:!0,type:"string",attribute:"_user"},timestamp:{alias:"log_timestamp",typeScriptStyle:!0,type:"Date",attribute:"_timestamp"},log_timestamp:{physical:!0,type:"Date",attribute:"_timestamp"}};
@@ -20,11 +20,11 @@ export declare class SmartDbVersionModel extends AbstractModel<SmartDbVersionMod
20
20
  private _releaseType?;
21
21
  private _installDate?;
22
22
  static readonly attributeMap: ModelAttributeMap;
23
- constructor(data?: SmartDbVersionModel | SmartDbVersionModelData);
24
23
  static getClassName(): string;
25
24
  static getTableName(): string;
26
25
  static getPrimaryKey(): string;
27
26
  static from(other: SmartDbVersionModel | SmartDbVersionModelData): SmartDbVersionModel;
27
+ constructor(data?: SmartDbVersionModel | SmartDbVersionModelData);
28
28
  clone(): SmartDbVersionModel;
29
29
  getClassName(): string;
30
30
  getTableName(): string;
@@ -32,34 +32,34 @@ export declare class SmartDbVersionModel extends AbstractModel<SmartDbVersionMod
32
32
  getAttributeMap(): ModelAttributeMap;
33
33
  get id(): number;
34
34
  set id(id: number);
35
- get installDate(): Date;
36
- set installDate(installDate: Date);
37
- get module(): string;
38
- set module(module: string);
39
- get releaseType(): string;
40
- set releaseType(releaseType: string);
41
- get revision(): string;
42
- set revision(revision: string);
43
- get sequence(): number;
44
- set sequence(sequence: number);
45
- get subVersion(): string;
46
- set subVersion(subVersion: string);
47
35
  get ver_id(): number;
48
36
  set ver_id(id: number);
49
- get ver_install_date(): Date;
50
- set ver_install_date(installDate: Date);
37
+ get module(): string;
38
+ set module(module: string);
51
39
  get ver_module(): string;
52
40
  set ver_module(module: string);
53
- get ver_release_type(): string;
54
- set ver_release_type(releaseType: string);
55
- get ver_revision(): string;
56
- set ver_revision(revision: string);
41
+ get sequence(): number;
42
+ set sequence(sequence: number);
57
43
  get ver_sequence(): number;
58
44
  set ver_sequence(sequence: number);
59
- get ver_sub_version(): string;
60
- set ver_sub_version(subVersion: string);
61
- get ver_version(): string;
62
- set ver_version(version: string);
63
45
  get version(): string;
64
46
  set version(version: string);
47
+ get ver_version(): string;
48
+ set ver_version(version: string);
49
+ get subVersion(): string;
50
+ set subVersion(subVersion: string);
51
+ get ver_sub_version(): string;
52
+ set ver_sub_version(subVersion: string);
53
+ get revision(): string;
54
+ set revision(revision: string);
55
+ get ver_revision(): string;
56
+ set ver_revision(revision: string);
57
+ get releaseType(): string;
58
+ set releaseType(releaseType: string);
59
+ get ver_release_type(): string;
60
+ set ver_release_type(releaseType: string);
61
+ get installDate(): Date;
62
+ set installDate(installDate: Date);
63
+ get ver_install_date(): Date;
64
+ set ver_install_date(installDate: Date);
65
65
  }
@@ -1 +1 @@
1
- import{AbstractModel}from"./abstract-model";export class SmartDbVersionModel extends AbstractModel{constructor(e){super(),e&&this.assign(e)}static getClassName(){return"SmartDbVersionModel"}static getTableName(){return"smart_db_version"}static getPrimaryKey(){return"ver_id"}static from(e){let t=null;return e&&(t=new SmartDbVersionModel,e instanceof SmartDbVersionModel?Object.assign(t,e):t.assign(e)),t}clone(){return SmartDbVersionModel.from(this)}getClassName(){return"SmartDbVersionModel"}getTableName(){return"smart_db_version"}getPrimaryKey(){return"ver_id"}getAttributeMap(){return SmartDbVersionModel.attributeMap}get id(){return this._id}set id(e){this._id=e}get installDate(){return this._installDate}set installDate(e){this._installDate=e}get module(){return this._module}set module(e){this._module=e}get releaseType(){return this._releaseType}set releaseType(e){this._releaseType=e}get revision(){return this._revision}set revision(e){this._revision=e}get sequence(){return this._sequence}set sequence(e){this._sequence=e}get subVersion(){return this._subVersion}set subVersion(e){this._subVersion=e}get ver_id(){return this._id}set ver_id(e){this._id=e}get ver_install_date(){return this._installDate}set ver_install_date(e){this._installDate=e}get ver_module(){return this._module}set ver_module(e){this._module=e}get ver_release_type(){return this._releaseType}set ver_release_type(e){this._releaseType=e}get ver_revision(){return this._revision}set ver_revision(e){this._revision=e}get ver_sequence(){return this._sequence}set ver_sequence(e){this._sequence=e}get ver_sub_version(){return this._subVersion}set ver_sub_version(e){this._subVersion=e}get ver_version(){return this._version}set ver_version(e){this._version=e}get version(){return this._version}set version(e){this._version=e}}SmartDbVersionModel.attributeMap={id:{alias:"ver_id",typeScriptStyle:!0,type:"number",attribute:"_id"},ver_id:{physical:!0,type:"number",attribute:"_id"},module:{alias:"ver_module",typeScriptStyle:!0,type:"string",attribute:"_module"},ver_module:{physical:!0,type:"string",attribute:"_module"},sequence:{alias:"ver_sequence",typeScriptStyle:!0,type:"number",attribute:"_sequence"},ver_sequence:{physical:!0,type:"number",attribute:"_sequence"},version:{alias:"ver_version",typeScriptStyle:!0,type:"string",attribute:"_version"},ver_version:{physical:!0,type:"string",attribute:"_version"},subVersion:{alias:"ver_sub_version",typeScriptStyle:!0,type:"string",attribute:"_subVersion"},ver_sub_version:{physical:!0,type:"string",attribute:"_subVersion"},revision:{alias:"ver_revision",typeScriptStyle:!0,type:"string",attribute:"_revision"},ver_revision:{physical:!0,type:"string",attribute:"_revision"},releaseType:{alias:"ver_release_type",typeScriptStyle:!0,type:"string",attribute:"_releaseType"},ver_release_type:{physical:!0,type:"string",attribute:"_releaseType"},installDate:{alias:"ver_install_date",typeScriptStyle:!0,type:"Date",attribute:"_installDate"},ver_install_date:{physical:!0,type:"Date",attribute:"_installDate"}};
1
+ import{AbstractModel}from"./abstract-model";export class SmartDbVersionModel extends AbstractModel{constructor(e){super(),e&&this.assign(e)}static getClassName(){return"SmartDbVersionModel"}static getTableName(){return"smart_db_version"}static getPrimaryKey(){return"ver_id"}static from(e){let t=null;return e&&(t=new SmartDbVersionModel,e instanceof SmartDbVersionModel?Object.assign(t,e):t.assign(e)),t}clone(){return SmartDbVersionModel.from(this)}getClassName(){return"SmartDbVersionModel"}getTableName(){return"smart_db_version"}getPrimaryKey(){return"ver_id"}getAttributeMap(){return SmartDbVersionModel.attributeMap}get id(){return this._id}set id(e){this._id=e}get ver_id(){return this._id}set ver_id(e){this._id=e}get module(){return this._module}set module(e){this._module=e}get ver_module(){return this._module}set ver_module(e){this._module=e}get sequence(){return this._sequence}set sequence(e){this._sequence=e}get ver_sequence(){return this._sequence}set ver_sequence(e){this._sequence=e}get version(){return this._version}set version(e){this._version=e}get ver_version(){return this._version}set ver_version(e){this._version=e}get subVersion(){return this._subVersion}set subVersion(e){this._subVersion=e}get ver_sub_version(){return this._subVersion}set ver_sub_version(e){this._subVersion=e}get revision(){return this._revision}set revision(e){this._revision=e}get ver_revision(){return this._revision}set ver_revision(e){this._revision=e}get releaseType(){return this._releaseType}set releaseType(e){this._releaseType=e}get ver_release_type(){return this._releaseType}set ver_release_type(e){this._releaseType=e}get installDate(){return this._installDate}set installDate(e){this._installDate=e}get ver_install_date(){return this._installDate}set ver_install_date(e){this._installDate=e}}SmartDbVersionModel.attributeMap={id:{alias:"ver_id",typeScriptStyle:!0,type:"number",attribute:"_id"},ver_id:{physical:!0,type:"number",attribute:"_id"},module:{alias:"ver_module",typeScriptStyle:!0,type:"string",attribute:"_module"},ver_module:{physical:!0,type:"string",attribute:"_module"},sequence:{alias:"ver_sequence",typeScriptStyle:!0,type:"number",attribute:"_sequence"},ver_sequence:{physical:!0,type:"number",attribute:"_sequence"},version:{alias:"ver_version",typeScriptStyle:!0,type:"string",attribute:"_version"},ver_version:{physical:!0,type:"string",attribute:"_version"},subVersion:{alias:"ver_sub_version",typeScriptStyle:!0,type:"string",attribute:"_subVersion"},ver_sub_version:{physical:!0,type:"string",attribute:"_subVersion"},revision:{alias:"ver_revision",typeScriptStyle:!0,type:"string",attribute:"_revision"},ver_revision:{physical:!0,type:"string",attribute:"_revision"},releaseType:{alias:"ver_release_type",typeScriptStyle:!0,type:"string",attribute:"_releaseType"},ver_release_type:{physical:!0,type:"string",attribute:"_releaseType"},installDate:{alias:"ver_install_date",typeScriptStyle:!0,type:"Date",attribute:"_installDate"},ver_install_date:{physical:!0,type:"Date",attribute:"_installDate"}};
@@ -1,5 +1,6 @@
1
- import { GenericModelData, ModelAttributeMap, SqlValueType } from "../smart-db-interfaces";
1
+ import { GenericModelData, ModelAttributeMap } from "../smart-db-interfaces";
2
2
  import { AbstractModel } from "./abstract-model";
3
+ import { SqlValueType } from "../smart-db-interfaces";
3
4
  export interface SmartDbVersionViewModelData extends GenericModelData {
4
5
  id?: number;
5
6
  module?: string;
@@ -22,11 +23,11 @@ export declare class SmartDbVersionViewModel extends AbstractModel<SmartDbVersio
22
23
  private _installDate?;
23
24
  private _versionString?;
24
25
  static readonly attributeMap: ModelAttributeMap;
25
- constructor(data?: SmartDbVersionViewModel | SmartDbVersionViewModelData);
26
26
  static getClassName(): string;
27
27
  static getTableName(): string;
28
28
  static getPrimaryKey(): string;
29
29
  static from(other: SmartDbVersionViewModel | SmartDbVersionViewModelData): SmartDbVersionViewModel;
30
+ constructor(data?: SmartDbVersionViewModel | SmartDbVersionViewModelData);
30
31
  clone(): SmartDbVersionViewModel;
31
32
  getClassName(): string;
32
33
  getTableName(): string;
@@ -34,38 +35,38 @@ export declare class SmartDbVersionViewModel extends AbstractModel<SmartDbVersio
34
35
  getAttributeMap(): ModelAttributeMap;
35
36
  get id(): number;
36
37
  set id(id: number);
37
- get installDate(): Date;
38
- set installDate(installDate: Date);
39
- get module(): string;
40
- set module(module: string);
41
- get releaseType(): string;
42
- set releaseType(releaseType: string);
43
- get revision(): string;
44
- set revision(revision: string);
45
- get sequence(): number;
46
- set sequence(sequence: number);
47
- get subVersion(): string;
48
- set subVersion(subVersion: string);
49
38
  get ver_id(): number;
50
39
  set ver_id(id: number);
51
- get ver_install_date(): Date;
52
- set ver_install_date(installDate: Date);
40
+ get module(): string;
41
+ set module(module: string);
53
42
  get ver_module(): string;
54
43
  set ver_module(module: string);
55
- get ver_release_type(): string;
56
- set ver_release_type(releaseType: string);
57
- get ver_revision(): string;
58
- set ver_revision(revision: string);
44
+ get sequence(): number;
45
+ set sequence(sequence: number);
59
46
  get ver_sequence(): number;
60
47
  set ver_sequence(sequence: number);
61
- get ver_sub_version(): string;
62
- set ver_sub_version(subVersion: string);
63
- get ver_version(): string;
64
- set ver_version(version: string);
65
- get ver_version_string(): SqlValueType;
66
- set ver_version_string(versionString: SqlValueType);
67
48
  get version(): string;
68
49
  set version(version: string);
50
+ get ver_version(): string;
51
+ set ver_version(version: string);
52
+ get subVersion(): string;
53
+ set subVersion(subVersion: string);
54
+ get ver_sub_version(): string;
55
+ set ver_sub_version(subVersion: string);
56
+ get revision(): string;
57
+ set revision(revision: string);
58
+ get ver_revision(): string;
59
+ set ver_revision(revision: string);
60
+ get releaseType(): string;
61
+ set releaseType(releaseType: string);
62
+ get ver_release_type(): string;
63
+ set ver_release_type(releaseType: string);
64
+ get installDate(): Date;
65
+ set installDate(installDate: Date);
66
+ get ver_install_date(): Date;
67
+ set ver_install_date(installDate: Date);
69
68
  get versionString(): SqlValueType;
70
69
  set versionString(versionString: SqlValueType);
70
+ get ver_version_string(): SqlValueType;
71
+ set ver_version_string(versionString: SqlValueType);
71
72
  }
@@ -1 +1 @@
1
- import{AbstractModel}from"./abstract-model";export class SmartDbVersionViewModel extends AbstractModel{constructor(e){super(),e&&this.assign(e)}static getClassName(){return"SmartDbVersionViewModel"}static getTableName(){return"smart_db_version_view"}static getPrimaryKey(){return""}static from(e){let t=null;return e&&(t=new SmartDbVersionViewModel,e instanceof SmartDbVersionViewModel?Object.assign(t,e):t.assign(e)),t}clone(){return SmartDbVersionViewModel.from(this)}getClassName(){return"SmartDbVersionViewModel"}getTableName(){return"smart_db_version_view"}getPrimaryKey(){return""}getAttributeMap(){return SmartDbVersionViewModel.attributeMap}get id(){return this._id}set id(e){this._id=e}get installDate(){return this._installDate}set installDate(e){this._installDate=e}get module(){return this._module}set module(e){this._module=e}get releaseType(){return this._releaseType}set releaseType(e){this._releaseType=e}get revision(){return this._revision}set revision(e){this._revision=e}get sequence(){return this._sequence}set sequence(e){this._sequence=e}get subVersion(){return this._subVersion}set subVersion(e){this._subVersion=e}get ver_id(){return this._id}set ver_id(e){this._id=e}get ver_install_date(){return this._installDate}set ver_install_date(e){this._installDate=e}get ver_module(){return this._module}set ver_module(e){this._module=e}get ver_release_type(){return this._releaseType}set ver_release_type(e){this._releaseType=e}get ver_revision(){return this._revision}set ver_revision(e){this._revision=e}get ver_sequence(){return this._sequence}set ver_sequence(e){this._sequence=e}get ver_sub_version(){return this._subVersion}set ver_sub_version(e){this._subVersion=e}get ver_version(){return this._version}set ver_version(e){this._version=e}get ver_version_string(){return this._versionString}set ver_version_string(e){this._versionString=e}get version(){return this._version}set version(e){this._version=e}get versionString(){return this._versionString}set versionString(e){this._versionString=e}}SmartDbVersionViewModel.attributeMap={id:{alias:"ver_id",typeScriptStyle:!0,type:"number",attribute:"_id"},ver_id:{physical:!0,type:"number",attribute:"_id"},module:{alias:"ver_module",typeScriptStyle:!0,type:"string",attribute:"_module"},ver_module:{physical:!0,type:"string",attribute:"_module"},sequence:{alias:"ver_sequence",typeScriptStyle:!0,type:"number",attribute:"_sequence"},ver_sequence:{physical:!0,type:"number",attribute:"_sequence"},version:{alias:"ver_version",typeScriptStyle:!0,type:"string",attribute:"_version"},ver_version:{physical:!0,type:"string",attribute:"_version"},subVersion:{alias:"ver_sub_version",typeScriptStyle:!0,type:"string",attribute:"_subVersion"},ver_sub_version:{physical:!0,type:"string",attribute:"_subVersion"},revision:{alias:"ver_revision",typeScriptStyle:!0,type:"string",attribute:"_revision"},ver_revision:{physical:!0,type:"string",attribute:"_revision"},releaseType:{alias:"ver_release_type",typeScriptStyle:!0,type:"string",attribute:"_releaseType"},ver_release_type:{physical:!0,type:"string",attribute:"_releaseType"},installDate:{alias:"ver_install_date",typeScriptStyle:!0,type:"Date",attribute:"_installDate"},ver_install_date:{physical:!0,type:"Date",attribute:"_installDate"},versionString:{alias:"ver_version_string",typeScriptStyle:!0,type:"SqlValueType",attribute:"_versionString"},ver_version_string:{physical:!0,type:"SqlValueType",attribute:"_versionString"}};
1
+ import{AbstractModel}from"./abstract-model";export class SmartDbVersionViewModel extends AbstractModel{constructor(e){super(),e&&this.assign(e)}static getClassName(){return"SmartDbVersionViewModel"}static getTableName(){return"smart_db_version_view"}static getPrimaryKey(){return""}static from(e){let t=null;return e&&(t=new SmartDbVersionViewModel,e instanceof SmartDbVersionViewModel?Object.assign(t,e):t.assign(e)),t}clone(){return SmartDbVersionViewModel.from(this)}getClassName(){return"SmartDbVersionViewModel"}getTableName(){return"smart_db_version_view"}getPrimaryKey(){return""}getAttributeMap(){return SmartDbVersionViewModel.attributeMap}get id(){return this._id}set id(e){this._id=e}get ver_id(){return this._id}set ver_id(e){this._id=e}get module(){return this._module}set module(e){this._module=e}get ver_module(){return this._module}set ver_module(e){this._module=e}get sequence(){return this._sequence}set sequence(e){this._sequence=e}get ver_sequence(){return this._sequence}set ver_sequence(e){this._sequence=e}get version(){return this._version}set version(e){this._version=e}get ver_version(){return this._version}set ver_version(e){this._version=e}get subVersion(){return this._subVersion}set subVersion(e){this._subVersion=e}get ver_sub_version(){return this._subVersion}set ver_sub_version(e){this._subVersion=e}get revision(){return this._revision}set revision(e){this._revision=e}get ver_revision(){return this._revision}set ver_revision(e){this._revision=e}get releaseType(){return this._releaseType}set releaseType(e){this._releaseType=e}get ver_release_type(){return this._releaseType}set ver_release_type(e){this._releaseType=e}get installDate(){return this._installDate}set installDate(e){this._installDate=e}get ver_install_date(){return this._installDate}set ver_install_date(e){this._installDate=e}get versionString(){return this._versionString}set versionString(e){this._versionString=e}get ver_version_string(){return this._versionString}set ver_version_string(e){this._versionString=e}}SmartDbVersionViewModel.attributeMap={id:{alias:"ver_id",typeScriptStyle:!0,type:"number",attribute:"_id"},ver_id:{physical:!0,type:"number",attribute:"_id"},module:{alias:"ver_module",typeScriptStyle:!0,type:"string",attribute:"_module"},ver_module:{physical:!0,type:"string",attribute:"_module"},sequence:{alias:"ver_sequence",typeScriptStyle:!0,type:"number",attribute:"_sequence"},ver_sequence:{physical:!0,type:"number",attribute:"_sequence"},version:{alias:"ver_version",typeScriptStyle:!0,type:"string",attribute:"_version"},ver_version:{physical:!0,type:"string",attribute:"_version"},subVersion:{alias:"ver_sub_version",typeScriptStyle:!0,type:"string",attribute:"_subVersion"},ver_sub_version:{physical:!0,type:"string",attribute:"_subVersion"},revision:{alias:"ver_revision",typeScriptStyle:!0,type:"string",attribute:"_revision"},ver_revision:{physical:!0,type:"string",attribute:"_revision"},releaseType:{alias:"ver_release_type",typeScriptStyle:!0,type:"string",attribute:"_releaseType"},ver_release_type:{physical:!0,type:"string",attribute:"_releaseType"},installDate:{alias:"ver_install_date",typeScriptStyle:!0,type:"Date",attribute:"_installDate"},ver_install_date:{physical:!0,type:"Date",attribute:"_installDate"},versionString:{alias:"ver_version_string",typeScriptStyle:!0,type:"SqlValueType",attribute:"_versionString"},ver_version_string:{physical:!0,type:"SqlValueType",attribute:"_versionString"}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egi/smart-db",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "Unified Smart DB Access",
5
5
  "author": "Marcel Egloff",
6
6
  "type": "module",
@@ -72,8 +72,8 @@
72
72
  "glob": "^7.1.7",
73
73
  "mocha": "^8.4.0",
74
74
  "npm-run-all": "^4.1.5",
75
- "uglify-js": "^3.13.10",
76
- "terser": "^4.8.0"
75
+ "terser": "^4.8.0",
76
+ "uglify-js": "^3.13.10"
77
77
  },
78
78
  "optionalDependencies": {
79
79
  "better-sqlite3": "^7.1.0",
@@ -89,6 +89,7 @@ export interface SmartDbSqlOptions<T extends AbstractModel<T, D>, D extends Gene
89
89
  union?: SectionDescription<T, D> | SectionDescription<T, D>[];
90
90
  minus?: SectionDescription<T, D> | SectionDescription<T, D>[];
91
91
  intersect?: SectionDescription<T, D> | SectionDescription<T, D>[];
92
+ style?: FieldNamingStyle;
92
93
  }
93
94
  export declare enum SqlOperationType {
94
95
  GT = ">",
package/smart-db.js CHANGED
@@ -1 +1 @@
1
- import _ from"lodash";import{AbstractModel}from"./models/abstract-model";import{SmartDbDictionary}from"./models/smart-db-dictionary";import{SmartDbLogModel}from"./models/smart-db-log-model";import{IN,smartDbToDate,toSmartDbDate,toSmartDbTimestamp}from"./smart-db-globals";import{FieldNamingStyle,SqlFieldOperationType,SqlOperationType}from"./smart-db-interfaces";import{SmartDbLog,SmartDbLogLocation}from"./smart-db-log";import{SmartDbSqlBuildData}from"./smart-db-sql-build-data";import{SmartDbUpgradeManager}from"./smart-db-upgrade-manager";export class SmartDb{constructor(e){this.dictionaries=[],this.dbConnector=e,this.smartDbLog=new SmartDbLog(this)}initDb(e){return new Promise((t,a)=>{this.dictionaries.push(SmartDbDictionary);const r=new SmartDbUpgradeManager(this);let i;i=import.meta&&import.meta.url?import.meta.url.replace(/file:\/\//,"").replace(/\/[^/]*$/,""):__dirname;const s={module:"smart-db-core",sqlFilesDirectory:i+"/assets/"+this.getDatabaseType()};r.prepareDatabase(s).then(i=>{this.exists(SmartDbLogModel).then(s=>{this.smartDbLog.setDbLogging(s),r.prepareDatabase(e).then(e=>{t([i,e])},e=>{a(e)})})}).catch(e=>{a(e)})})}getLogger(){return this.smartDbLog}getDb(){return this.db}getLastBuildData(){return this.lastBuildData}get(e,t){return new Promise((a,r)=>{t||(t={});const i=this.buildSelectStatement(e,t);t.firstOnly||t.count?this.statementGet(i).then(r=>{a(this.prepareResultRow(e,r,t))}).catch(e=>{r(e)}):this.statementGetAll(i).then(r=>{a(this.prepareResultRows(e,r,t))}).catch(e=>{r(e)})})}getSync(e,t){return this.saveExecute(()=>{t||(t={});const a=this.buildSelectStatement(e,t);let r;if(t.firstOnly||t.count){const i=this.statementGetSync(a);r=this.prepareResultRow(e,i,t)}else{const i=this.statementGetAllSync(a);r=this.prepareResultRows(e,i,t)}return r})}getFirst(e,t,a,r){return this.get(e,{firstOnly:!0,where:t,fields:a,orderBy:r})}getFirstSync(e,t,a,r){return this.getSync(e,{firstOnly:!0,where:t,fields:a,orderBy:r})}getAll(e,t,a,r,i){return this.get(e,{where:t,fields:a,orderBy:r,limit:i})}getAllSync(e,t,a,r,i){return this.getSync(e,{where:t,fields:a,orderBy:r,limit:i})}delete(e,t){return new Promise((a,r)=>{const i=this.buildDeleteStatement(e,t);this.statementRun(i).then(e=>{e?a(e.changes):r(this.getLastError())}).catch(e=>{r(e)})})}deleteSync(e,t){return this.saveExecute(()=>{const a=this.buildDeleteStatement(e,t);return this.statementRunSync(a).changes})}update(e,t,a){return new Promise((r,i)=>{const s=this.buildUpdateStatement(e,t,a);this.statementRun(s).then(e=>{e?r(e.changes):i(this.getLastError())}).catch(e=>{i(e)})})}updateSync(e,t,a){return this.saveExecute(()=>{const r=this.buildUpdateStatement(e,t,a);return this.statementRunSync(r).changes})}insert(e,t){return new Promise((a,r)=>{const i=this.buildInsertStatement(e,t);this.statementRun(i).then(e=>{e?a(e.lastId):r(this.getLastError())}).catch(e=>{r(e)})})}insertSync(e,t){return this.saveExecute(()=>{const a=this.buildInsertStatement(e,t);return this.statementRunSync(a).lastId})}getLastError(){return this.lastError}buildSelectStatement(e,t){t||(t={});const a=this.buildSelectSectionStatement(e,t);if(_.forEach(["union","minus","intersect"],e=>{let r=_.get(t,e);r&&(_.isArray(r)||(r=[r]),_.forEach(r,t=>{const r=this.buildSelectSectionStatement(t.model,t);a.sql+=" "+e.toUpperCase()+" ",a.append(r)}))}),t.orderBy){a.sql+=" ORDER BY ";const r=_.isString(t.orderBy)?t.orderBy.split(/ *, */):t.orderBy;a.sql+=r.map(t=>{let a="";const r=t.match(/^(\w*) (asc|desc)$/i);return r&&(t=r[1],a=r[2].toUpperCase()),t=this.translateFieldName(e,t),a&&(t+=" "+a),t}).join(", ")}return t.limit&&(t.limit.limit&&(a.sql+=" LIMIT "+t.limit.limit.toString()),t.limit.offset&&(a.sql+=" OFFSET "+t.limit.offset.toString())),this.lastBuildData=a,a}toDate(e){return smartDbToDate(e)}toDbTimestamp(e){return toSmartDbTimestamp(e)}toDbDate(e){return toSmartDbDate(e)}buildWhere(e,t,a){const r=new SmartDbSqlBuildData;return t&&_.keys(t).length>0&&(a||(a="AND",r.sql+=" WHERE "),r.sql+=_.map(t,(t,i)=>{const s=i.toUpperCase();if("AND"==s||"OR"==s){let a="";return(_.isArray(t)?t:[t]).forEach((t,i)=>{const l=this.buildWhere(e,t,s);i>0&&(a+=" "+s+" "),a+=l.sql,r.values=_.concat(r.values,l.values)}),a="("+a+")",a}if("EXPRESSION"==s){let i=[];return _.forEach(t,t=>{const a=this.prepareField(e,t.compare,r.values),s=this.prepareField(e,t.with,r.values);let l;l=_.isString(t.operation)&&SqlOperationType[t.operation]?SqlOperationType[t.operation]:t.operation||SqlOperationType.EQ,i.push(`${a} ${l} ${s}`)}),i.join(" "+a+" ")}{let a,s,l=!0;if(_.isArray(t)&&(t=IN(t)),_.isObject(t)){const e=t;switch(_.isString(e.operation)&&SqlOperationType[e.operation]&&(e.operation=SqlOperationType[e.operation]),e.operation){case SqlOperationType.IN:const t=new Array(e.value.length);t.fill("?"),a=SqlOperationType.IN+" ("+t.join(", ")+")",r.values=_.concat(r.values,e.value);break;case SqlOperationType.IS_NULL:case SqlOperationType.IS_NOT_NULL:a=e.operation;break;case SqlOperationType.LITERAL:i=e.key;const s=e.literalOperation||SqlOperationType.EQ;if(s==SqlOperationType.IN){const t=new Array(e.value.length);t.fill("?"),a=SqlOperationType.IN+" ("+t.join(", ")+")",r.values=_.concat(r.values,e.value)}else _.isUndefined(e.value)?a=s:(a=s+" ?",r.values.push(this.makeDbValue(e.value)));l=!1;break;default:a=e.operation+" ?",r.values.push(this.makeDbValue(e.value))}}else null===t?a=SqlOperationType.IS_NULL:void 0===t?(i="1",a="= 1",l=!1):(a=_.isString(t)&&t.match(/[%_]/)?SqlOperationType.LIKE+" ?":SqlOperationType.EQ+" ?",r.values.push(this.makeDbValue(t)));return s=l?this.translateFieldName(e,i)+" "+a:i+" "+a,s}}).join(" "+a+" ")),r}buildDeleteStatement(e,t){const a=this.getTableName(e),r=new SmartDbSqlBuildData("DELETE FROM");return r.sql+=" "+a,t&&r.append(this.buildWhere(e,t)),this.lastBuildData=r,r}buildUpdateStatement(e,t,a){const r=this.getTableName(e),i=new SmartDbSqlBuildData("UPDATE");i.sql+=" "+r+" SET ";const s=[];return t instanceof AbstractModel&&(t=t.getPlainObject(FieldNamingStyle.Database)),_.forOwn(t,(t,a)=>{s.push(this.translateFieldName(e,a)+" = ?"),i.values.push(this.makeDbValue(t))}),i.sql+=s.join(", "),a&&i.append(this.buildWhere(e,a)),this.lastBuildData=i,i}buildInsertStatement(e,t){const a=this.getTableName(e),r=new SmartDbSqlBuildData("INSERT");r.sql+=" INTO "+a;const i=[];t instanceof AbstractModel&&(t=t.getPlainObject(FieldNamingStyle.Database)),_.forOwn(t,(t,a)=>{a=this.translateFieldName(e,a),i.push(a),r.values.push(this.makeDbValue(t))});const s=new Array(i.length);return s.fill("?"),r.sql+=" ("+i.join(", ")+") VALUES ("+s.join(", ")+")",this.lastBuildData=r,r}prepareFieldValue(e,t){let a="<undefined>";switch(t.operation){case SqlFieldOperationType.FIELD:a=this.translateFieldName(e,t.value);break;case SqlFieldOperationType.VALUE:null===t.value?a="NULL":t.literal?a=t.value:_.isString(t.value)?!isNaN(parseFloat(t.value))&&isFinite(t.value)||(a="'"+t.value+"'"):_.isNumber(t.value)?a=t.value.toString():_.isBoolean(t.value)?a=t.value?"1":"0":_.isDate(t.value)?a="'"+t.value.toISOString().substr(0,23).replace("T"," ")+"'":console.error("unhandled field data type",typeof t.value,t.value);break;case SqlFieldOperationType.COUNT:a=_.isArray(t.value)?"COUNT("+t.value.join(",")+")":"COUNT("+(t.value||"")+")";break;case SqlFieldOperationType.COALESCE:const r=_.isArray(t.value)?t.value:[t.value];a="COALESCE("+this.buildFieldList(e,r).join(",")+")"}if(t.alias){const e=this.getDbQuote();a+=` as ${e}${t.alias}${e}`}return a}prepareField(e,t,a){let r;if(null===t)r="NULL";else if(_.isString(t)){const i=t.match(/^'(.*)'$/);i?a?(r="?",a.push(i[1])):r=t:r=this.translateFieldName(e,t)}else t.operation?r=this.prepareFieldValue(e,t):a?(r="?",a.push(t)):r=this.makeArgumentDbValue(t).toString();return r}buildFieldList(e,t){const a=[];return _.forEach(t,t=>{a.push(this.prepareField(e,t))}),a}buildSelectSectionStatement(e,t){const a=this.getTableName(e);let r,i;if(_.isArray(t.fields))r=t.fields;else if(_.isString(t.fields)){const e=t.fields.trim();r=""===e||"*"==e?[]:e.split(/,/)}else r=t.fields&&t.fields.operation?[t.fields]:[];if(r.length>0){i=this.buildFieldList(e,r).join(", ")}else i="*";t.distinct&&(i="DISTINCT "+i),t.count&&(i=`COUNT(${i})`);const s=new SmartDbSqlBuildData(`SELECT ${i} FROM ${a}`);if(t.where&&s.append(this.buildWhere(e,t.where)),t.groupBy){s.sql+=" GROUP BY ";const a=_.isArray(t.groupBy)?t.groupBy:[t.groupBy];s.sql+=a.map(t=>this.translateFieldName(e,t)).join(", ")}return s}translateFieldName(e,t){if(_.isString(e)){const t=e;let a=!1;_.forEach(this.dictionaries,r=>(r.models&&r.models[t]&&(e=r.models[t].cls,a=!0),!a))}if(!_.isString(e)){const a=e.attributeMap[t];if(a)a.alias&&(t=a.alias);else{const a=e.getTableName();this.lastError=new Error(`unknown field '${t}' in table '${a}'`),this.smartDbLog.logError(SmartDbLogLocation.Database,"translateFieldName",this.lastError)}}return t}makeDbValue(e){return _.isBoolean(e)?e=e?1:0:_.isDate(e)&&(e=toSmartDbDate(e)),e}makeArgumentDbValue(e){return _.isBoolean(e)?e=e?1:0:_.isDate(e)?e=`'${toSmartDbDate(e)}'`:_.isString(e)&&(e=`'${e.replace(/'/,"''").replace(/\\/,"\\\\")}'`),e}saveExecute(e){let t;try{t=e()}catch(e){this.lastError=e instanceof Error?e:new Error(e||"Unknown error"),this.smartDbLog.logFatal(SmartDbLogLocation.Database,"saveExecute-catch",this.lastError),t=!1}return t}prepareResultRow(e,t,a){let r;if(a.indexedBy&&this.smartDbLog.logWarning(SmartDbLogLocation.Database,"AbstractModel.get","option 'indexedBy' not supported without 'all'"),t)if(a.count)r=parseInt(_.values(t)[0],10);else if(a.collapseRow)r=_.values(t).join(",");else{r=e.from(t)}return r}prepareResultRows(e,t,a){let r;if(a.indexedBy||a.collapseRow||!_.isString(e)){const i=e;r=a.indexedBy?{}:new Array(t.length),_.forEach(t,(e,t)=>{const s=i.from?i.from(e):null;let l=null;if(a.indexedBy&&(l=s?s.getValue(a.indexedBy):e[a.indexedBy]),a.collapseRow){const a=_.values(e).join(",");l?r[l]=a:r[t]=a}else l?r[l]=s||e:r[t]=s||e})}else r=t;return r}getTableName(e){let t;if(_.isString(e)){let a=e;_.forEach(this.dictionaries,e=>(e.models&&e.models[a]&&(t=e.models[a].cls.getTableName()),!t)),t||(t=a)}else{if(!e||!e.getTableName)throw new Error("unknown model: "+e);t=e.getTableName()}return t}}
1
+ import _ from"lodash";import{AbstractModel}from"./models/abstract-model";import{SmartDbDictionary}from"./models/smart-db-dictionary";import{SmartDbLogModel}from"./models/smart-db-log-model";import{IN,smartDbToDate,toSmartDbDate,toSmartDbTimestamp}from"./smart-db-globals";import{FieldNamingStyle,SqlFieldOperationType,SqlOperationType}from"./smart-db-interfaces";import{SmartDbLog,SmartDbLogLocation}from"./smart-db-log";import{SmartDbSqlBuildData}from"./smart-db-sql-build-data";import{SmartDbUpgradeManager}from"./smart-db-upgrade-manager";export class SmartDb{constructor(e){this.dictionaries=[],this.dbConnector=e,this.smartDbLog=new SmartDbLog(this)}initDb(e){return new Promise((t,a)=>{this.dictionaries.push(SmartDbDictionary);const r=new SmartDbUpgradeManager(this);let i;i=import.meta&&import.meta.url?import.meta.url.replace(/file:\/\//,"").replace(/\/[^/]*$/,""):__dirname;const s={module:"smart-db-core",sqlFilesDirectory:i+"/assets/"+this.getDatabaseType()};r.prepareDatabase(s).then(i=>{this.exists(SmartDbLogModel).then(s=>{this.smartDbLog.setDbLogging(s),r.prepareDatabase(e).then(e=>{t([i,e])},e=>{a(e)})})}).catch(e=>{a(e)})})}getLogger(){return this.smartDbLog}getDb(){return this.db}getLastBuildData(){return this.lastBuildData}get(e,t){return new Promise((a,r)=>{t||(t={});const i=this.buildSelectStatement(e,t);t.firstOnly||t.count?this.statementGet(i).then(r=>{a(this.prepareResultRow(e,r,t))}).catch(e=>{r(e)}):this.statementGetAll(i).then(r=>{a(this.prepareResultRows(e,r,t))}).catch(e=>{r(e)})})}getSync(e,t){return this.saveExecute(()=>{t||(t={});const a=this.buildSelectStatement(e,t);let r;if(t.firstOnly||t.count){const i=this.statementGetSync(a);r=this.prepareResultRow(e,i,t)}else{const i=this.statementGetAllSync(a);r=this.prepareResultRows(e,i,t)}return r})}getFirst(e,t,a,r){return this.get(e,{firstOnly:!0,where:t,fields:a,orderBy:r})}getFirstSync(e,t,a,r){return this.getSync(e,{firstOnly:!0,where:t,fields:a,orderBy:r})}getAll(e,t,a,r,i){return this.get(e,{where:t,fields:a,orderBy:r,limit:i})}getAllSync(e,t,a,r,i){return this.getSync(e,{where:t,fields:a,orderBy:r,limit:i})}delete(e,t){return new Promise((a,r)=>{const i=this.buildDeleteStatement(e,t);this.statementRun(i).then(e=>{e?a(e.changes):r(this.getLastError())}).catch(e=>{r(e)})})}deleteSync(e,t){return this.saveExecute(()=>{const a=this.buildDeleteStatement(e,t);return this.statementRunSync(a).changes})}update(e,t,a){return new Promise((r,i)=>{const s=this.buildUpdateStatement(e,t,a);this.statementRun(s).then(e=>{e?r(e.changes):i(this.getLastError())}).catch(e=>{i(e)})})}updateSync(e,t,a){return this.saveExecute(()=>{const r=this.buildUpdateStatement(e,t,a);return this.statementRunSync(r).changes})}insert(e,t){return new Promise((a,r)=>{const i=this.buildInsertStatement(e,t);this.statementRun(i).then(e=>{e?a(e.lastId):r(this.getLastError())}).catch(e=>{r(e)})})}insertSync(e,t){return this.saveExecute(()=>{const a=this.buildInsertStatement(e,t);return this.statementRunSync(a).lastId})}getLastError(){return this.lastError}buildSelectStatement(e,t){t||(t={});const a=this.buildSelectSectionStatement(e,t);if(_.forEach(["union","minus","intersect"],e=>{let r=_.get(t,e);r&&(_.isArray(r)||(r=[r]),_.forEach(r,t=>{const r=this.buildSelectSectionStatement(t.model,t);a.sql+=" "+e.toUpperCase()+" ",a.append(r)}))}),t.orderBy){a.sql+=" ORDER BY ";const r=_.isString(t.orderBy)?t.orderBy.split(/ *, */):t.orderBy;a.sql+=r.map(t=>{let a="";const r=t.match(/^(\w*) (asc|desc)$/i);return r&&(t=r[1],a=r[2].toUpperCase()),t=this.translateFieldName(e,t),a&&(t+=" "+a),t}).join(", ")}return t.limit&&(t.limit.limit&&(a.sql+=" LIMIT "+t.limit.limit.toString()),t.limit.offset&&(a.sql+=" OFFSET "+t.limit.offset.toString())),this.lastBuildData=a,a}toDate(e){return smartDbToDate(e)}toDbTimestamp(e){return toSmartDbTimestamp(e)}toDbDate(e){return toSmartDbDate(e)}buildWhere(e,t,a){const r=new SmartDbSqlBuildData;return t&&_.keys(t).length>0&&(a||(a="AND",r.sql+=" WHERE "),r.sql+=_.map(t,(t,i)=>{const s=i.toUpperCase();if("AND"==s||"OR"==s){let a="";return(_.isArray(t)?t:[t]).forEach((t,i)=>{const l=this.buildWhere(e,t,s);i>0&&(a+=" "+s+" "),a+=l.sql,r.values=_.concat(r.values,l.values)}),a="("+a+")",a}if("EXPRESSION"==s){let i=[];return _.forEach(t,t=>{const a=this.prepareField(e,t.compare,r.values),s=this.prepareField(e,t.with,r.values);let l;l=_.isString(t.operation)&&SqlOperationType[t.operation]?SqlOperationType[t.operation]:t.operation||SqlOperationType.EQ,i.push(`${a} ${l} ${s}`)}),i.join(" "+a+" ")}{let a,s,l=!0;if(_.isArray(t)&&(t=IN(t)),_.isObject(t)){const e=t;switch(_.isString(e.operation)&&SqlOperationType[e.operation]&&(e.operation=SqlOperationType[e.operation]),e.operation){case SqlOperationType.IN:const t=new Array(e.value.length);t.fill("?"),a=SqlOperationType.IN+" ("+t.join(", ")+")",r.values=_.concat(r.values,e.value);break;case SqlOperationType.IS_NULL:case SqlOperationType.IS_NOT_NULL:a=e.operation;break;case SqlOperationType.LITERAL:i=e.key;const s=e.literalOperation||SqlOperationType.EQ;if(s==SqlOperationType.IN){const t=new Array(e.value.length);t.fill("?"),a=SqlOperationType.IN+" ("+t.join(", ")+")",r.values=_.concat(r.values,e.value)}else _.isUndefined(e.value)?a=s:(a=s+" ?",r.values.push(this.makeDbValue(e.value)));l=!1;break;default:a=e.operation+" ?",r.values.push(this.makeDbValue(e.value))}}else null===t?a=SqlOperationType.IS_NULL:void 0===t?(i="1",a="= 1",l=!1):(a=_.isString(t)&&t.match(/[%_]/)?SqlOperationType.LIKE+" ?":SqlOperationType.EQ+" ?",r.values.push(this.makeDbValue(t)));return s=l?this.translateFieldName(e,i)+" "+a:i+" "+a,s}}).join(" "+a+" ")),r}buildDeleteStatement(e,t){const a=this.getTableName(e),r=new SmartDbSqlBuildData("DELETE FROM");return r.sql+=" "+a,t&&r.append(this.buildWhere(e,t)),this.lastBuildData=r,r}buildUpdateStatement(e,t,a){const r=this.getTableName(e),i=new SmartDbSqlBuildData("UPDATE");i.sql+=" "+r+" SET ";const s=[];return t instanceof AbstractModel&&(t=t.getPlainObject(FieldNamingStyle.Database)),_.forOwn(t,(t,a)=>{s.push(this.translateFieldName(e,a)+" = ?"),i.values.push(this.makeDbValue(t))}),i.sql+=s.join(", "),a&&i.append(this.buildWhere(e,a)),this.lastBuildData=i,i}buildInsertStatement(e,t){const a=this.getTableName(e),r=new SmartDbSqlBuildData("INSERT");r.sql+=" INTO "+a;const i=[];t instanceof AbstractModel&&(t=t.getPlainObject(FieldNamingStyle.Database)),_.forOwn(t,(t,a)=>{a=this.translateFieldName(e,a),i.push(a),r.values.push(this.makeDbValue(t))});const s=new Array(i.length);return s.fill("?"),r.sql+=" ("+i.join(", ")+") VALUES ("+s.join(", ")+")",this.lastBuildData=r,r}prepareFieldValue(e,t){let a="<undefined>";switch(t.operation){case SqlFieldOperationType.FIELD:a=this.translateFieldName(e,t.value);break;case SqlFieldOperationType.VALUE:null===t.value?a="NULL":t.literal?a=t.value:_.isString(t.value)?!isNaN(parseFloat(t.value))&&isFinite(t.value)||(a="'"+t.value+"'"):_.isNumber(t.value)?a=t.value.toString():_.isBoolean(t.value)?a=t.value?"1":"0":_.isDate(t.value)?a="'"+t.value.toISOString().substr(0,23).replace("T"," ")+"'":console.error("unhandled field data type",typeof t.value,t.value);break;case SqlFieldOperationType.COUNT:a=_.isArray(t.value)?"COUNT("+t.value.join(",")+")":"COUNT("+(t.value||"")+")";break;case SqlFieldOperationType.COALESCE:const r=_.isArray(t.value)?t.value:[t.value];a="COALESCE("+this.buildFieldList(e,r).join(",")+")"}if(t.alias){const e=this.getDbQuote();a+=` as ${e}${t.alias}${e}`}return a}prepareField(e,t,a){let r;if(null===t)r="NULL";else if(_.isString(t)){const i=t.match(/^'(.*)'$/);i?a?(r="?",a.push(i[1])):r=t:r=this.translateFieldName(e,t)}else t.operation?r=this.prepareFieldValue(e,t):a?(r="?",a.push(t)):r=this.makeArgumentDbValue(t).toString();return r}buildFieldList(e,t){const a=[];return _.forEach(t,t=>{a.push(this.prepareField(e,t))}),a}buildSelectSectionStatement(e,t){const a=this.getTableName(e);let r,i;if(_.isArray(t.fields))r=t.fields;else if(_.isString(t.fields)){const e=t.fields.trim();r=""===e||"*"==e?[]:e.split(/,/)}else r=t.fields&&t.fields.operation?[t.fields]:[];if(r.length>0){i=this.buildFieldList(e,r).join(", ")}else i="*";t.distinct&&(i="DISTINCT "+i),t.count&&(i=`COUNT(${i})`);const s=new SmartDbSqlBuildData(`SELECT ${i} FROM ${a}`);if(t.where&&s.append(this.buildWhere(e,t.where)),t.groupBy){s.sql+=" GROUP BY ";const a=_.isArray(t.groupBy)?t.groupBy:[t.groupBy];s.sql+=a.map(t=>this.translateFieldName(e,t)).join(", ")}return s}translateFieldName(e,t){if(_.isString(e)){const t=e;let a=!1;_.forEach(this.dictionaries,r=>(r.models&&r.models[t]&&(e=r.models[t].cls,a=!0),!a))}if(!_.isString(e)){const a=e.attributeMap[t];if(a)a.alias&&(t=a.alias);else{const a=e.getTableName();this.lastError=new Error(`unknown field '${t}' in table '${a}'`),this.smartDbLog.logError(SmartDbLogLocation.Database,"translateFieldName",this.lastError)}}return t}makeDbValue(e){return _.isBoolean(e)?e=e?1:0:_.isDate(e)&&(e=toSmartDbDate(e)),e}makeArgumentDbValue(e){return _.isBoolean(e)?e=e?1:0:_.isDate(e)?e=`'${toSmartDbDate(e)}'`:_.isString(e)&&(e=`'${e.replace(/'/,"''").replace(/\\/,"\\\\")}'`),e}saveExecute(e){let t;try{t=e()}catch(e){this.lastError=e instanceof Error?e:new Error(e||"Unknown error"),this.smartDbLog.logFatal(SmartDbLogLocation.Database,"saveExecute-catch",this.lastError),t=!1}return t}prepareResultRow(e,t,a){let r;if(a.indexedBy&&this.smartDbLog.logWarning(SmartDbLogLocation.Database,"AbstractModel.get","option 'indexedBy' not supported without 'all'"),t)if(a.count)r=parseInt(_.values(t)[0],10);else if(a.collapseRow)r=_.values(t).join(",");else{r=e.from(t),a.style==FieldNamingStyle.TypeScript&&(r=r.getPlainObject(FieldNamingStyle.TypeScript))}return r}prepareResultRows(e,t,a){let r;if(a.indexedBy||a.collapseRow||!_.isString(e)){const i=e;r=a.indexedBy?{}:new Array(t.length),_.forEach(t,(e,t)=>{let s=i.from?i.from(e):null,l=null;if(a.indexedBy&&(l=s?s.getValue(a.indexedBy):e[a.indexedBy]),a.collapseRow){const a=_.values(e).join(",");l?r[l]=a:r[t]=a}else s&&a.style==FieldNamingStyle.TypeScript&&(s=s.getPlainObject(FieldNamingStyle.TypeScript)),l?r[l]=s||e:r[t]=s||e})}else r=t;return r}getTableName(e){let t;if(_.isString(e)){let a=e;_.forEach(this.dictionaries,e=>(e.models&&e.models[a]&&(t=e.models[a].cls.getTableName()),!t)),t||(t=a)}else{if(!e||!e.getTableName)throw new Error("unknown model: "+e);t=e.getTableName()}return t}}