meadow-connection-sqlite 1.0.14 → 1.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meadow-connection-sqlite",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "Meadow SQLite Plugin",
5
5
  "main": "source/Meadow-Connection-SQLite.js",
6
6
  "scripts": {
@@ -43,7 +43,7 @@
43
43
  "homepage": "https://github.com/stevenvelozo/meadow-connection-sqlite",
44
44
  "devDependencies": {
45
45
  "quackage": "^1.0.59",
46
- "retold-harness": "^1.1.0"
46
+ "retold-harness": "^1.1.2"
47
47
  },
48
48
  "dependencies": {
49
49
  "better-sqlite3": "^12.6.2",
@@ -6,6 +6,8 @@ const libFableServiceProviderBase = require('fable-serviceproviderbase');
6
6
 
7
7
  const libSQLite = require('better-sqlite3');
8
8
 
9
+ const libMeadowSchemaSQLite = require('./Meadow-Schema-SQLite.js');
10
+
9
11
  /*
10
12
  Das alt muster:
11
13
 
@@ -25,6 +27,9 @@ class MeadowConnectionSQLite extends libFableServiceProviderBase
25
27
  this.connected = false;
26
28
  this._database = false;
27
29
 
30
+ // Schema provider handles DDL operations (create, drop, index, etc.)
31
+ this._SchemaProvider = new libMeadowSchemaSQLite(this.fable, this.options, `${this.Hash}-Schema`);
32
+
28
33
  if (this.fable.settings.hasOwnProperty('SQLite'))
29
34
  {
30
35
  if (this.fable.settings.SQLite.hasOwnProperty('SQLiteFilePath'))
@@ -34,102 +39,96 @@ class MeadowConnectionSQLite extends libFableServiceProviderBase
34
39
  }
35
40
  }
36
41
 
42
+ get schemaProvider()
43
+ {
44
+ return this._SchemaProvider;
45
+ }
46
+
37
47
  generateDropTableStatement(pTableName)
38
48
  {
39
- return `DROP TABLE IF EXISTS ${pTableName};`;
49
+ return this._SchemaProvider.generateDropTableStatement(pTableName);
40
50
  }
41
51
 
42
52
  generateCreateTableStatement(pMeadowTableSchema)
43
53
  {
44
- this.log.info(`--> Building the table create string for ${pMeadowTableSchema.TableName} ...`);
54
+ return this._SchemaProvider.generateCreateTableStatement(pMeadowTableSchema);
55
+ }
45
56
 
46
- let tmpPrimaryKey = false;
47
- let tmpCreateTableStatement = `-- [ ${pMeadowTableSchema.TableName} ]`;
48
- tmpCreateTableStatement += `\nCREATE TABLE IF NOT EXISTS ${pMeadowTableSchema.TableName}\n (`;
49
- for (let j = 0; j < pMeadowTableSchema.Columns.length; j++)
50
- {
51
- let tmpColumn = pMeadowTableSchema.Columns[j];
57
+ createTables(pMeadowSchema, fCallback)
58
+ {
59
+ return this._SchemaProvider.createTables(pMeadowSchema, fCallback);
60
+ }
52
61
 
53
- // If we aren't the first column, append a comma.
54
- if (j > 0)
55
- {
56
- tmpCreateTableStatement += `,`;
57
- }
62
+ createTable(pMeadowTableSchema, fCallback)
63
+ {
64
+ return this._SchemaProvider.createTable(pMeadowTableSchema, fCallback);
65
+ }
58
66
 
59
- tmpCreateTableStatement += `\n`;
60
- switch (tmpColumn.DataType)
61
- {
62
- case 'ID':
63
- tmpCreateTableStatement += ` ${tmpColumn.Column} INTEGER PRIMARY KEY AUTOINCREMENT`;
64
- tmpPrimaryKey = tmpColumn.Column;
65
- break;
66
- case 'GUID':
67
- tmpCreateTableStatement += ` ${tmpColumn.Column} TEXT DEFAULT '00000000-0000-0000-0000-000000000000'`;
68
- break;
69
- case 'ForeignKey':
70
- tmpCreateTableStatement += ` ${tmpColumn.Column} INTEGER NOT NULL DEFAULT 0`;
71
- break;
72
- case 'Numeric':
73
- tmpCreateTableStatement += ` ${tmpColumn.Column} INTEGER NOT NULL DEFAULT 0`;
74
- break;
75
- case 'Decimal':
76
- tmpCreateTableStatement += ` ${tmpColumn.Column} REAL`;
77
- break;
78
- case 'String':
79
- tmpCreateTableStatement += ` ${tmpColumn.Column} TEXT NOT NULL DEFAULT ''`;
80
- break;
81
- case 'Text':
82
- tmpCreateTableStatement += ` ${tmpColumn.Column} TEXT`;
83
- break;
84
- case 'DateTime':
85
- tmpCreateTableStatement += ` ${tmpColumn.Column} TEXT`;
86
- break;
87
- case 'Boolean':
88
- tmpCreateTableStatement += ` ${tmpColumn.Column} INTEGER NOT NULL DEFAULT 0`;
89
- break;
90
- default:
91
- break;
92
- }
93
- }
94
- tmpCreateTableStatement += `\n );`;
67
+ getIndexDefinitionsFromSchema(pMeadowTableSchema)
68
+ {
69
+ return this._SchemaProvider.getIndexDefinitionsFromSchema(pMeadowTableSchema);
70
+ }
95
71
 
96
- this.log.info(`Generated Create Table Statement: ${tmpCreateTableStatement}`);
72
+ generateCreateIndexScript(pMeadowTableSchema)
73
+ {
74
+ return this._SchemaProvider.generateCreateIndexScript(pMeadowTableSchema);
75
+ }
97
76
 
98
- return tmpCreateTableStatement;
77
+ generateCreateIndexStatements(pMeadowTableSchema)
78
+ {
79
+ return this._SchemaProvider.generateCreateIndexStatements(pMeadowTableSchema);
99
80
  }
100
81
 
101
- createTables(pMeadowSchema, fCallback)
82
+ createIndex(pIndexStatement, fCallback)
102
83
  {
103
- this.fable.Utility.eachLimit(pMeadowSchema.Tables, 1,
104
- (pTable, fCreateComplete) =>
105
- {
106
- return this.createTable(pTable, fCreateComplete)
107
- },
108
- (pCreateError) =>
109
- {
110
- if (pCreateError)
111
- {
112
- this.log.error(`Meadow-SQLite Error creating tables from Schema: ${pCreateError}`,pCreateError);
113
- }
114
- this.log.info('Done creating tables!');
115
- return fCallback(pCreateError);
116
- });
84
+ return this._SchemaProvider.createIndex(pIndexStatement, fCallback);
117
85
  }
118
86
 
119
- createTable(pMeadowTableSchema, fCallback)
87
+ createIndices(pMeadowTableSchema, fCallback)
120
88
  {
121
- let tmpCreateTableStatement = this.generateCreateTableStatement(pMeadowTableSchema);
122
- try
123
- {
124
- this._database.exec(tmpCreateTableStatement);
125
- this.log.info(`Meadow-SQLite CREATE TABLE ${pMeadowTableSchema.TableName} Success`);
126
- return fCallback();
127
- }
128
- catch (pError)
129
- {
130
- this.log.error(`Meadow-SQLite CREATE TABLE ${pMeadowTableSchema.TableName} failed!`, pError);
131
- return fCallback(pError);
132
- }
89
+ return this._SchemaProvider.createIndices(pMeadowTableSchema, fCallback);
90
+ }
91
+
92
+ createAllIndices(pMeadowSchema, fCallback)
93
+ {
94
+ return this._SchemaProvider.createAllIndices(pMeadowSchema, fCallback);
95
+ }
96
+
97
+ // Database Introspection delegation
98
+
99
+ listTables(fCallback)
100
+ {
101
+ return this._SchemaProvider.listTables(fCallback);
102
+ }
103
+
104
+ introspectTableColumns(pTableName, fCallback)
105
+ {
106
+ return this._SchemaProvider.introspectTableColumns(pTableName, fCallback);
107
+ }
108
+
109
+ introspectTableIndices(pTableName, fCallback)
110
+ {
111
+ return this._SchemaProvider.introspectTableIndices(pTableName, fCallback);
112
+ }
113
+
114
+ introspectTableForeignKeys(pTableName, fCallback)
115
+ {
116
+ return this._SchemaProvider.introspectTableForeignKeys(pTableName, fCallback);
117
+ }
118
+
119
+ introspectTableSchema(pTableName, fCallback)
120
+ {
121
+ return this._SchemaProvider.introspectTableSchema(pTableName, fCallback);
122
+ }
123
+
124
+ introspectDatabaseSchema(fCallback)
125
+ {
126
+ return this._SchemaProvider.introspectDatabaseSchema(fCallback);
127
+ }
128
+
129
+ generateMeadowPackageFromTable(pTableName, fCallback)
130
+ {
131
+ return this._SchemaProvider.generateMeadowPackageFromTable(pTableName, fCallback);
133
132
  }
134
133
 
135
134
  connect()
@@ -174,6 +173,7 @@ class MeadowConnectionSQLite extends libFableServiceProviderBase
174
173
  // According to the documentation, setting this journal mode is very important for performance.
175
174
  // > Though not required, [it is generally important to set the WAL pragma for performance reasons](https://github.com/WiseLibs/better-sqlite3/blob/master/docs/performance.md).
176
175
  this._database.pragma('journal_mode = WAL');
176
+ this._SchemaProvider.setDatabase(this._database);
177
177
  this.log.info(`Meadow-Connection-SQLite successfully connected to SQLite file [${tmpConnectionSettings.SQLiteFilePath}].`);
178
178
  this.connected = true;
179
179
  return tmpCallback(null, this._database);