meadow-connection-sqlite 1.0.13 → 1.0.14

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/docs/schema.md ADDED
@@ -0,0 +1,198 @@
1
+ # Schema & Table Creation
2
+
3
+ Meadow Connection SQLite generates `CREATE TABLE` statements from Meadow table schemas, translating Meadow data types to SQLite column definitions. This page documents the type mapping, DDL generation process, and examples.
4
+
5
+ ---
6
+
7
+ ## Column Type Mapping
8
+
9
+ | Meadow DataType | SQLite Column Definition | Notes |
10
+ |-----------------|--------------------------|-------|
11
+ | `ID` | `INTEGER PRIMARY KEY AUTOINCREMENT` | Auto-incrementing primary key |
12
+ | `GUID` | `TEXT DEFAULT '00000000-0000-0000-0000-000000000000'` | Stored as 36-character UUID string |
13
+ | `ForeignKey` | `INTEGER NOT NULL DEFAULT 0` | Foreign key reference |
14
+ | `Numeric` | `INTEGER NOT NULL DEFAULT 0` | 64-bit signed integer |
15
+ | `Decimal` | `REAL` | 64-bit IEEE floating point |
16
+ | `String` | `TEXT NOT NULL DEFAULT ''` | Variable-length text (SQLite ignores length) |
17
+ | `Text` | `TEXT` | Unlimited text, nullable |
18
+ | `DateTime` | `TEXT` | ISO-8601 string (e.g. `datetime('now')`) |
19
+ | `Boolean` | `INTEGER NOT NULL DEFAULT 0` | 0 = false, 1 = true |
20
+
21
+ ### SQLite Type Affinity
22
+
23
+ SQLite uses a flexible type system called "type affinity." Unlike MySQL or MSSQL, SQLite does not enforce declared column types. A `TEXT` column can store an integer, and an `INTEGER` column can store a string. The type mapping above follows SQLite conventions for predictable behavior:
24
+
25
+ - **INTEGER** -- Used for numeric values, booleans, and foreign keys
26
+ - **REAL** -- Used for decimal/floating-point values
27
+ - **TEXT** -- Used for strings, GUIDs, and dates (ISO-8601 format)
28
+
29
+ The `Size` field on Meadow `String` columns is accepted but has no effect in SQLite — `TEXT` columns have unlimited length.
30
+
31
+ ---
32
+
33
+ ## Schema Object Format
34
+
35
+ A Meadow table schema is a plain JavaScript object:
36
+
37
+ ```javascript
38
+ let tmpSchema =
39
+ {
40
+ TableName: 'Book',
41
+ Columns:
42
+ [
43
+ { Column: 'IDBook', DataType: 'ID' },
44
+ { Column: 'GUIDBook', DataType: 'GUID' },
45
+ { Column: 'Title', DataType: 'String', Size: '256' },
46
+ { Column: 'Author', DataType: 'String', Size: '128' },
47
+ { Column: 'YearPublished', DataType: 'Numeric' },
48
+ { Column: 'Price', DataType: 'Decimal', Size: '10,2' },
49
+ { Column: 'InPrint', DataType: 'Boolean' },
50
+ { Column: 'CreateDate', DataType: 'DateTime' },
51
+ { Column: 'UpdateDate', DataType: 'DateTime' }
52
+ ]
53
+ };
54
+ ```
55
+
56
+ Each entry in the `Columns` array requires:
57
+
58
+ | Property | Type | Required | Description |
59
+ |----------|------|----------|-------------|
60
+ | `Column` | string | Yes | Column name |
61
+ | `DataType` | string | Yes | Meadow data type (see mapping above) |
62
+ | `Size` | string | No | Size specification (ignored by SQLite except for documentation) |
63
+
64
+ ---
65
+
66
+ ## Generating DDL
67
+
68
+ ### generateCreateTableStatement()
69
+
70
+ Pass a schema object to `generateCreateTableStatement()` to get the SQL string:
71
+
72
+ ```javascript
73
+ let tmpDDL = _Fable.MeadowSQLiteProvider.generateCreateTableStatement(tmpSchema);
74
+ console.log(tmpDDL);
75
+ ```
76
+
77
+ Output:
78
+
79
+ ```sql
80
+ CREATE TABLE IF NOT EXISTS Book (IDBook INTEGER PRIMARY KEY AUTOINCREMENT, GUIDBook TEXT DEFAULT '00000000-0000-0000-0000-000000000000', Title TEXT NOT NULL DEFAULT '', Author TEXT NOT NULL DEFAULT '', YearPublished INTEGER NOT NULL DEFAULT 0, Price REAL, InPrint INTEGER NOT NULL DEFAULT 0, CreateDate TEXT, UpdateDate TEXT);
81
+ ```
82
+
83
+ Key behaviors:
84
+
85
+ - Always uses `CREATE TABLE IF NOT EXISTS` — safe to run repeatedly
86
+ - Column names are used as-is (no quoting needed in SQLite)
87
+ - The `ID` column is always `INTEGER PRIMARY KEY AUTOINCREMENT`
88
+
89
+ ### createTable()
90
+
91
+ Execute the DDL directly:
92
+
93
+ ```javascript
94
+ _Fable.MeadowSQLiteProvider.createTable(tmpSchema,
95
+ (pError) =>
96
+ {
97
+ if (pError)
98
+ {
99
+ console.error('Create table failed:', pError);
100
+ return;
101
+ }
102
+ console.log('Table created successfully');
103
+ });
104
+ ```
105
+
106
+ The callback receives an error if the DDL fails, otherwise `undefined`.
107
+
108
+ ### createTables()
109
+
110
+ Create multiple tables from a full Meadow schema:
111
+
112
+ ```javascript
113
+ let tmpFullSchema =
114
+ {
115
+ Tables:
116
+ [
117
+ {
118
+ TableName: 'Book',
119
+ Columns:
120
+ [
121
+ { Column: 'IDBook', DataType: 'ID' },
122
+ { Column: 'Title', DataType: 'String', Size: '256' }
123
+ ]
124
+ },
125
+ {
126
+ TableName: 'Author',
127
+ Columns:
128
+ [
129
+ { Column: 'IDAuthor', DataType: 'ID' },
130
+ { Column: 'Name', DataType: 'String', Size: '128' }
131
+ ]
132
+ }
133
+ ]
134
+ };
135
+
136
+ _Fable.MeadowSQLiteProvider.createTables(tmpFullSchema,
137
+ (pError) =>
138
+ {
139
+ if (pError) { return; }
140
+ console.log('All tables created');
141
+ });
142
+ ```
143
+
144
+ Tables are created sequentially using `fable.Utility.eachLimit` with concurrency 1.
145
+
146
+ ---
147
+
148
+ ## Generating DROP Statements
149
+
150
+ ```javascript
151
+ let tmpDropDDL = _Fable.MeadowSQLiteProvider.generateDropTableStatement('Book');
152
+ console.log(tmpDropDDL);
153
+ ```
154
+
155
+ Output:
156
+
157
+ ```sql
158
+ DROP TABLE IF EXISTS Book;
159
+ ```
160
+
161
+ ---
162
+
163
+ ## Comparison with Other Connectors
164
+
165
+ ### MySQL vs SQLite DDL
166
+
167
+ | Feature | MySQL | SQLite |
168
+ |---------|-------|--------|
169
+ | `ID` type | `INT UNSIGNED NOT NULL AUTO_INCREMENT` | `INTEGER PRIMARY KEY AUTOINCREMENT` |
170
+ | `GUID` type | `CHAR(36)` | `TEXT` |
171
+ | `String` type | `VARCHAR(n)` | `TEXT` |
172
+ | `Decimal` type | `DECIMAL(p,s)` | `REAL` |
173
+ | `Boolean` type | `TINYINT NOT NULL DEFAULT 0` | `INTEGER NOT NULL DEFAULT 0` |
174
+ | `DateTime` type | `DATETIME` | `TEXT` |
175
+ | Table name quoting | Backticks: `` `Book` `` | None: `Book` |
176
+ | Primary key | Separate `PRIMARY KEY (col)` | Inline `PRIMARY KEY AUTOINCREMENT` |
177
+ | Size enforcement | Yes | No |
178
+
179
+ ### MSSQL vs SQLite DDL
180
+
181
+ | Feature | MSSQL | SQLite |
182
+ |---------|-------|--------|
183
+ | `ID` type | `INT IDENTITY(1,1)` | `INTEGER PRIMARY KEY AUTOINCREMENT` |
184
+ | `GUID` type | `CHAR(36)` | `TEXT` |
185
+ | `String` type | `NVARCHAR(n)` | `TEXT` |
186
+ | Schema prefix | `[dbo].[Book]` | None |
187
+ | Column quoting | Square brackets: `[Title]` | None |
188
+ | Drop syntax | `IF OBJECT_ID('..') IS NOT NULL DROP TABLE` | `DROP TABLE IF EXISTS` |
189
+
190
+ ---
191
+
192
+ ## Related
193
+
194
+ - [API Reference](api/reference.md) -- Full API documentation
195
+ - [Full Pipeline Example](examples-pipeline.md) -- CRUD pipeline with table creation
196
+ - [generateCreateTableStatement](api/generateCreateTableStatement.md) -- Function reference
197
+ - [createTable](api/createTable.md) -- Function reference
198
+ - [createTables](api/createTables.md) -- Function reference
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meadow-connection-sqlite",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Meadow SQLite Plugin",
5
5
  "main": "source/Meadow-Connection-SQLite.js",
6
6
  "scripts": {
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "homepage": "https://github.com/stevenvelozo/meadow-connection-sqlite",
44
44
  "devDependencies": {
45
- "quackage": "^1.0.58",
45
+ "quackage": "^1.0.59",
46
46
  "retold-harness": "^1.1.0"
47
47
  },
48
48
  "dependencies": {