meadow-connection-sqlite 1.0.12 → 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/README.md CHANGED
@@ -10,12 +10,13 @@ A SQLite database connection provider for the Meadow ORM. Wraps [better-sqlite3]
10
10
 
11
11
  ## Features
12
12
 
13
- - **Better-SQLite3 Wrapper** - Synchronous, high-performance SQLite access via [better-sqlite3](https://github.com/WiseLibs/better-sqlite3)
14
- - **Fable Service Provider** - Registers with a Fable instance for dependency injection, logging, and configuration
15
- - **WAL Journal Mode** - Automatically enables Write-Ahead Logging for performance on connect
16
- - **Schema-Driven DDL** - Generates `CREATE TABLE` statements from Meadow table schemas with support for ID, GUID, ForeignKey, Numeric, Decimal, String, Text, DateTime, and Boolean column types
17
- - **Connection Safety** - Guards against double-connect and missing file path errors with descriptive logging
18
- - **Direct Database Access** - Exposes the underlying `better-sqlite3` database instance via `db` getter
13
+ - **Better-SQLite3 Wrapper** -- Synchronous, high-performance SQLite access via [better-sqlite3](https://github.com/WiseLibs/better-sqlite3)
14
+ - **Fable Service Provider** -- Registers with a Fable instance for dependency injection, logging, and configuration
15
+ - **WAL Journal Mode** -- Automatically enables Write-Ahead Logging for performance on connect
16
+ - **Schema-Driven DDL** -- Generates `CREATE TABLE` statements from Meadow table schemas with support for ID, GUID, ForeignKey, Numeric, Decimal, String, Text, DateTime, and Boolean column types
17
+ - **In-Memory Mode** -- Use `:memory:` as the file path for ephemeral databases in tests and prototypes
18
+ - **Connection Safety** -- Guards against double-connect and missing file path errors with descriptive logging
19
+ - **Direct Database Access** -- Exposes the underlying `better-sqlite3` database instance and module via getters
19
20
 
20
21
  ## Installation
21
22
 
@@ -167,8 +168,13 @@ npm run coverage
167
168
 
168
169
  ## Related Packages
169
170
 
170
- - [meadow](https://github.com/stevenvelozo/meadow) - Data access and ORM
171
- - [fable](https://github.com/stevenvelozo/fable) - Application services framework
171
+ - [meadow](https://github.com/stevenvelozo/meadow) -- Data access and ORM
172
+ - [foxhound](https://github.com/stevenvelozo/foxhound) -- Query DSL used by Meadow
173
+ - [stricture](https://github.com/stevenvelozo/stricture) -- Schema definition tool
174
+ - [meadow-endpoints](https://github.com/stevenvelozo/meadow-endpoints) -- RESTful endpoint generation
175
+ - [meadow-connection-mysql](https://github.com/stevenvelozo/meadow-connection-mysql) -- MySQL connection provider
176
+ - [meadow-connection-mssql](https://github.com/stevenvelozo/meadow-connection-mssql) -- MSSQL connection provider
177
+ - [fable](https://github.com/stevenvelozo/fable) -- Application services framework
172
178
 
173
179
  ## License
174
180
 
package/docs/README.md CHANGED
@@ -143,6 +143,14 @@ let _Fable = new libFable(
143
143
 
144
144
  The provider manages the connection lifecycle and exposes the raw `better-sqlite3` `Database` object. All queries go through better-sqlite3's synchronous API — there are no promises or callbacks for individual statements.
145
145
 
146
+ ## Learn More
147
+
148
+ - [Quickstart Guide](quickstart.md) -- Five-step walkthrough from install to Meadow ORM integration
149
+ - [Architecture & Design](architecture.md) -- Connection lifecycle, query model, and data flow diagrams
150
+ - [Schema & Table Creation](schema.md) -- Column type mapping and DDL generation
151
+ - [API Reference](api/reference.md) -- Complete reference for every property and method
152
+ - [Full Pipeline Example](examples-pipeline.md) -- End-to-end CRUD pipeline with transactions and aggregates
153
+
146
154
  ## Companion Modules
147
155
 
148
156
  | Module | Purpose |
@@ -151,3 +159,4 @@ The provider manages the connection lifecycle and exposes the raw `better-sqlite
151
159
  | [FoxHound](/meadow/foxhound/) | Query DSL and SQL generation |
152
160
  | [meadow-connection-mysql](/meadow/meadow-connection-mysql/) | MySQL connection provider |
153
161
  | [meadow-connection-mssql](/meadow/meadow-connection-mssql/) | MSSQL connection provider |
162
+ | [meadow-connection-rocksdb](/meadow/meadow-connection-rocksdb/) | RocksDB key-value provider |
@@ -1,5 +1,7 @@
1
1
  # Meadow Connection SQLite
2
2
 
3
+ <small>v1.0.12</small>
4
+
3
5
  > SQLite database provider for the Meadow data layer
4
6
 
5
7
  Connect any Fable application to a local SQLite database through the service provider pattern. Built on better-sqlite3 for fast synchronous access with WAL journaling, automatic file creation, and in-memory database support.
@@ -8,8 +10,10 @@ Connect any Fable application to a local SQLite database through the service pro
8
10
  - **Synchronous API** -- All queries run synchronously through better-sqlite3's native bindings
9
11
  - **WAL Journaling** -- Write-Ahead Logging enabled automatically for concurrent read/write performance
10
12
  - **In-Memory Mode** -- Use `:memory:` as the file path for ephemeral databases in tests and prototypes
13
+ - **Schema-Driven DDL** -- Generate CREATE TABLE statements from Meadow table schemas
11
14
  - **Service Integration** -- Registers as a Fable service with dependency injection and lifecycle logging
12
15
 
13
- [Quick Start](README.md)
14
- [API Reference](api.md)
16
+ [Quick Start](quickstart.md)
17
+ [API Reference](api/reference.md)
18
+ [Architecture](architecture.md)
15
19
  [GitHub](https://github.com/stevenvelozo/meadow-connection-sqlite)
package/docs/_sidebar.md CHANGED
@@ -1,10 +1,25 @@
1
1
  - Getting Started
2
2
 
3
3
  - [Overview](README.md)
4
+ - [Quickstart](quickstart.md)
4
5
 
5
- - Reference
6
+ - Architecture
6
7
 
7
- - [API Reference](api.md)
8
+ - [Design & Data Flow](architecture.md)
9
+ - [Schema & Table Creation](schema.md)
10
+
11
+ - API Reference
12
+
13
+ - [Full Reference](api/reference.md)
14
+ - [connectAsync](api/connectAsync.md)
15
+ - [connect](api/connect.md)
16
+ - [db](api/db.md)
17
+ - [SQLite](api/SQLite.md)
18
+ - [preparedStatement](api/preparedStatement.md)
19
+ - [generateCreateTableStatement](api/generateCreateTableStatement.md)
20
+ - [createTable](api/createTable.md)
21
+ - [createTables](api/createTables.md)
22
+ - [generateDropTableStatement](api/generateDropTableStatement.md)
8
23
 
9
24
  - Examples
10
25
 
@@ -16,5 +31,7 @@
16
31
  - [FoxHound](/meadow/foxhound/)
17
32
  - [MySQL Connector](/meadow/meadow-connection-mysql/)
18
33
  - [MSSQL Connector](/meadow/meadow-connection-mssql/)
34
+ - [RocksDB Connector](/meadow/meadow-connection-rocksdb/)
19
35
  - [Fable](/fable/fable/)
36
+ - [Stricture](/meadow/stricture/)
20
37
  - [Indoctrinate](/utility/indoctrinate/)
package/docs/_topbar.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Meadow Connection SQLite
2
2
 
3
3
  - [Overview](README.md)
4
- - [API Reference](api.md)
4
+ - [Quickstart](quickstart.md)
5
+ - [Architecture](architecture.md)
6
+ - [API Reference](api/reference.md)
7
+ - [Pipeline Example](examples-pipeline.md)
5
8
  - [GitHub](https://github.com/stevenvelozo/meadow-connection-sqlite)
@@ -0,0 +1,55 @@
1
+ # SQLite (getter)
2
+
3
+ Returns the `better-sqlite3` module constructor for direct access to the underlying library.
4
+
5
+ ## Signature
6
+
7
+ ```javascript
8
+ get SQLite()
9
+ ```
10
+
11
+ ## Return Value
12
+
13
+ | Type | Description |
14
+ |------|-------------|
15
+ | `function` | The `better-sqlite3` module (Database constructor) |
16
+
17
+ ## Primary Use
18
+
19
+ The `SQLite` getter provides access to the raw `better-sqlite3` module. This is useful for:
20
+
21
+ - Creating additional database instances outside the provider
22
+ - Accessing `better-sqlite3` constants or utilities
23
+ - Type checking against the constructor
24
+
25
+ ```javascript
26
+ let tmpSQLiteConstructor = _Fable.MeadowSQLiteProvider.SQLite;
27
+ ```
28
+
29
+ ## Creating an Additional Database
30
+
31
+ ```javascript
32
+ let tmpSQLite = _Fable.MeadowSQLiteProvider.SQLite;
33
+
34
+ // Open a second database independently
35
+ let tmpSecondDB = new tmpSQLite('./data/secondary.db');
36
+ tmpSecondDB.pragma('journal_mode = WAL');
37
+
38
+ let tmpRows = tmpSecondDB.prepare('SELECT * FROM Log').all();
39
+
40
+ tmpSecondDB.close();
41
+ ```
42
+
43
+ ## Comparison with db Getter
44
+
45
+ | Getter | Returns | Purpose |
46
+ |--------|---------|---------|
47
+ | `db` | Database instance | The connected database for queries |
48
+ | `SQLite` | Module constructor | The better-sqlite3 library itself |
49
+
50
+ The `db` getter returns the database handle opened by `connectAsync()`. The `SQLite` getter returns the library that creates those handles.
51
+
52
+ ## Related
53
+
54
+ - [db](db.md) -- The connected database instance for queries
55
+ - [connectAsync](connectAsync.md) -- Open the database connection
@@ -0,0 +1,66 @@
1
+ # connect()
2
+
3
+ Synchronous convenience wrapper that calls `connectAsync()` without a callback. Logs a warning about potential race conditions.
4
+
5
+ ## Signature
6
+
7
+ ```javascript
8
+ connect()
9
+ ```
10
+
11
+ ## Parameters
12
+
13
+ None.
14
+
15
+ ## Return Value
16
+
17
+ None.
18
+
19
+ ## Behavior
20
+
21
+ Calls `connectAsync()` internally without passing a callback. The provider logs a warning:
22
+
23
+ ```
24
+ Meadow-Connection-SQLite connect() called without a callback; this could
25
+ result in race conditions — use connectAsync(callback) instead.
26
+ ```
27
+
28
+ ## Why This Exists
29
+
30
+ `connect()` is provided for legacy compatibility and quick prototyping. Because the underlying better-sqlite3 library opens databases synchronously, the connection actually completes immediately — but the method still logs a warning because the Fable service pattern expects asynchronous lifecycle management.
31
+
32
+ ## Usage
33
+
34
+ ```javascript
35
+ _Fable.MeadowSQLiteProvider.connect();
36
+
37
+ // The database is ready immediately (better-sqlite3 is synchronous)
38
+ // but the warning is logged to encourage using connectAsync() instead
39
+ if (_Fable.MeadowSQLiteProvider.connected)
40
+ {
41
+ let tmpDB = _Fable.MeadowSQLiteProvider.db;
42
+ tmpDB.exec('CREATE TABLE IF NOT EXISTS Test (id INTEGER PRIMARY KEY)');
43
+ }
44
+ ```
45
+
46
+ ## Recommended Alternative
47
+
48
+ Always prefer `connectAsync()` for production code:
49
+
50
+ ```javascript
51
+ _Fable.MeadowSQLiteProvider.connectAsync(
52
+ (pError, pDatabase) =>
53
+ {
54
+ if (pError)
55
+ {
56
+ _Fable.log.error(`Connection failed: ${pError}`);
57
+ return;
58
+ }
59
+ // Safe to use the database here
60
+ });
61
+ ```
62
+
63
+ ## Related
64
+
65
+ - [connectAsync](connectAsync.md) -- Recommended connection method
66
+ - [db](db.md) -- Access the database after connecting
@@ -0,0 +1,121 @@
1
+ # connectAsync(fCallback)
2
+
3
+ Opens a connection to the SQLite database file specified in configuration. This is the recommended way to connect.
4
+
5
+ ## Signature
6
+
7
+ ```javascript
8
+ connectAsync(fCallback)
9
+ ```
10
+
11
+ ## Parameters
12
+
13
+ | Parameter | Type | Description |
14
+ |-----------|------|-------------|
15
+ | `fCallback` | `function` | Callback receiving `(error, database)` |
16
+
17
+ ## Return Value
18
+
19
+ None. Results are delivered via the callback.
20
+
21
+ ## Callback Parameters
22
+
23
+ | Parameter | Type | Description |
24
+ |-----------|------|-------------|
25
+ | `pError` | `Error \| null` | Error object if connection failed, `null` on success |
26
+ | `pDatabase` | `Database` | The better-sqlite3 Database instance |
27
+
28
+ ## Behavior
29
+
30
+ 1. If `SQLiteFilePath` is not configured, calls back with an error immediately
31
+ 2. If already connected, logs an error and calls back with the existing database (idempotent)
32
+ 3. Creates a new `better-sqlite3` Database instance at the configured file path
33
+ 4. The database file is created automatically if it does not exist
34
+ 5. Enables WAL (Write-Ahead Logging) journal mode for performance
35
+ 6. Sets `this.connected = true` on success
36
+
37
+ ## Basic Usage
38
+
39
+ ```javascript
40
+ _Fable.MeadowSQLiteProvider.connectAsync(
41
+ (pError, pDatabase) =>
42
+ {
43
+ if (pError)
44
+ {
45
+ _Fable.log.error(`Connection failed: ${pError}`);
46
+ return;
47
+ }
48
+
49
+ // pDatabase is the same as _Fable.MeadowSQLiteProvider.db
50
+ let tmpBooks = pDatabase.prepare('SELECT * FROM Book').all();
51
+ console.log(`Found ${tmpBooks.length} books`);
52
+ });
53
+ ```
54
+
55
+ ## Double-Connect Guard
56
+
57
+ Calling `connectAsync()` on an already-connected provider logs an error but does not throw. It returns the existing database:
58
+
59
+ ```javascript
60
+ _Fable.MeadowSQLiteProvider.connectAsync(
61
+ (pError, pDatabase) =>
62
+ {
63
+ // First connection — succeeds normally
64
+
65
+ _Fable.MeadowSQLiteProvider.connectAsync(
66
+ (pError, pDatabase2) =>
67
+ {
68
+ // Logs: "...is already connected - skipping the second connect call."
69
+ // pDatabase2 is the same instance as pDatabase
70
+ });
71
+ });
72
+ ```
73
+
74
+ ## Missing File Path
75
+
76
+ If `SQLiteFilePath` is not set in either the constructor options or Fable settings:
77
+
78
+ ```javascript
79
+ _Fable.MeadowSQLiteProvider.connectAsync(
80
+ (pError) =>
81
+ {
82
+ // pError contains: "...database file path is invalid;
83
+ // SQLiteFilePath must be in either fable.settings.SQLite
84
+ // or passed as an option to the service provider."
85
+ });
86
+ ```
87
+
88
+ ## In-Memory Database
89
+
90
+ Use `:memory:` for ephemeral databases that exist only in RAM:
91
+
92
+ ```javascript
93
+ let _Fable = new libFable(
94
+ {
95
+ "SQLite": { "SQLiteFilePath": ":memory:" }
96
+ });
97
+
98
+ // ... register and instantiate provider ...
99
+
100
+ _Fable.MeadowSQLiteProvider.connectAsync(
101
+ (pError, pDatabase) =>
102
+ {
103
+ // Database exists only in memory
104
+ // Discarded when the connection closes or process exits
105
+ });
106
+ ```
107
+
108
+ ## Missing Callback Warning
109
+
110
+ If `connectAsync()` is called without a callback, the provider logs an error:
111
+
112
+ ```
113
+ Meadow-Connection-SQLite connect() called without a callback; this could
114
+ result in race conditions — use connectAsync(callback) instead.
115
+ ```
116
+
117
+ ## Related
118
+
119
+ - [connect](connect.md) -- Synchronous wrapper (not recommended)
120
+ - [db](db.md) -- Access the database after connecting
121
+ - [pool](../api/reference.md) -- Full API reference
@@ -0,0 +1,96 @@
1
+ # createTable(pMeadowTableSchema, fCallback)
2
+
3
+ Generates a `CREATE TABLE IF NOT EXISTS` statement from a Meadow table schema and executes it against the connected database.
4
+
5
+ ## Signature
6
+
7
+ ```javascript
8
+ createTable(pMeadowTableSchema, fCallback)
9
+ ```
10
+
11
+ ## Parameters
12
+
13
+ | Parameter | Type | Description |
14
+ |-----------|------|-------------|
15
+ | `pMeadowTableSchema` | `object` | Meadow table schema with `TableName` and `Columns` array |
16
+ | `fCallback` | `function` | Callback receiving `(error)` |
17
+
18
+ ## Return Value
19
+
20
+ None. Results are delivered via the callback.
21
+
22
+ ## Behavior
23
+
24
+ 1. Calls `generateCreateTableStatement(pMeadowTableSchema)` to build the DDL
25
+ 2. Executes the DDL using `db.exec()`
26
+ 3. Calls back with `undefined` on success, or an error if the DDL fails
27
+
28
+ Because the generated DDL uses `CREATE TABLE IF NOT EXISTS`, calling `createTable()` for an already-existing table is a no-op — it does not error.
29
+
30
+ ## Basic Usage
31
+
32
+ ```javascript
33
+ let tmpBookSchema =
34
+ {
35
+ TableName: 'Book',
36
+ Columns:
37
+ [
38
+ { Column: 'IDBook', DataType: 'ID' },
39
+ { Column: 'GUIDBook', DataType: 'GUID' },
40
+ { Column: 'Title', DataType: 'String', Size: '256' },
41
+ { Column: 'Author', DataType: 'String', Size: '128' },
42
+ { Column: 'Price', DataType: 'Decimal', Size: '10,2' }
43
+ ]
44
+ };
45
+
46
+ _Fable.MeadowSQLiteProvider.createTable(tmpBookSchema,
47
+ (pError) =>
48
+ {
49
+ if (pError)
50
+ {
51
+ _Fable.log.error(`Create table failed: ${pError}`);
52
+ return;
53
+ }
54
+ _Fable.log.info('Book table created');
55
+ });
56
+ ```
57
+
58
+ ## Idempotent
59
+
60
+ Safe to call multiple times. The second call is a no-op:
61
+
62
+ ```javascript
63
+ _Fable.MeadowSQLiteProvider.createTable(tmpBookSchema,
64
+ (pError) =>
65
+ {
66
+ // Table created
67
+
68
+ _Fable.MeadowSQLiteProvider.createTable(tmpBookSchema,
69
+ (pError) =>
70
+ {
71
+ // No error — "IF NOT EXISTS" handles it
72
+ });
73
+ });
74
+ ```
75
+
76
+ ## Error Handling
77
+
78
+ Errors from `db.exec()` (e.g. invalid column definitions) are passed to the callback:
79
+
80
+ ```javascript
81
+ _Fable.MeadowSQLiteProvider.createTable(tmpBadSchema,
82
+ (pError) =>
83
+ {
84
+ if (pError)
85
+ {
86
+ console.error('DDL execution failed:', pError.message);
87
+ }
88
+ });
89
+ ```
90
+
91
+ ## Related
92
+
93
+ - [generateCreateTableStatement](generateCreateTableStatement.md) -- Generate DDL without executing
94
+ - [createTables](createTables.md) -- Create multiple tables at once
95
+ - [generateDropTableStatement](generateDropTableStatement.md) -- Drop a table
96
+ - [Schema & Table Creation](../schema.md) -- Full type mapping reference
@@ -0,0 +1,91 @@
1
+ # createTables(pMeadowSchema, fCallback)
2
+
3
+ Creates all tables defined in a Meadow schema object. Tables are created sequentially.
4
+
5
+ ## Signature
6
+
7
+ ```javascript
8
+ createTables(pMeadowSchema, fCallback)
9
+ ```
10
+
11
+ ## Parameters
12
+
13
+ | Parameter | Type | Description |
14
+ |-----------|------|-------------|
15
+ | `pMeadowSchema` | `object` | Meadow schema with a `Tables` array of table schemas |
16
+ | `fCallback` | `function` | Callback receiving `(error)` |
17
+
18
+ ## Return Value
19
+
20
+ None. Results are delivered via the callback.
21
+
22
+ ## Schema Object Format
23
+
24
+ ```javascript
25
+ let tmpSchema =
26
+ {
27
+ Tables:
28
+ [
29
+ {
30
+ TableName: 'Book',
31
+ Columns:
32
+ [
33
+ { Column: 'IDBook', DataType: 'ID' },
34
+ { Column: 'GUIDBook', DataType: 'GUID' },
35
+ { Column: 'Title', DataType: 'String', Size: '256' }
36
+ ]
37
+ },
38
+ {
39
+ TableName: 'Author',
40
+ Columns:
41
+ [
42
+ { Column: 'IDAuthor', DataType: 'ID' },
43
+ { Column: 'GUIDAuthor', DataType: 'GUID' },
44
+ { Column: 'Name', DataType: 'String', Size: '128' }
45
+ ]
46
+ },
47
+ {
48
+ TableName: 'BookAuthor',
49
+ Columns:
50
+ [
51
+ { Column: 'IDBookAuthor', DataType: 'ID' },
52
+ { Column: 'IDBook', DataType: 'ForeignKey' },
53
+ { Column: 'IDAuthor', DataType: 'ForeignKey' }
54
+ ]
55
+ }
56
+ ]
57
+ };
58
+ ```
59
+
60
+ ## Basic Usage
61
+
62
+ ```javascript
63
+ _Fable.MeadowSQLiteProvider.createTables(tmpSchema,
64
+ (pError) =>
65
+ {
66
+ if (pError)
67
+ {
68
+ _Fable.log.error(`Schema creation failed: ${pError}`);
69
+ return;
70
+ }
71
+
72
+ _Fable.log.info('All tables created');
73
+ });
74
+ ```
75
+
76
+ ## Behavior
77
+
78
+ - Iterates through `pMeadowSchema.Tables` using `fable.Utility.eachLimit` with concurrency 1
79
+ - Each table is created by calling `createTable()` internally
80
+ - If any table creation fails, the error is passed to the callback
81
+ - Uses `CREATE TABLE IF NOT EXISTS`, so existing tables are skipped without error
82
+
83
+ ## Sequential Execution
84
+
85
+ Tables are created one at a time (concurrency = 1). This ensures that tables referenced by foreign keys can be created in the order you specify in the `Tables` array.
86
+
87
+ ## Related
88
+
89
+ - [createTable](createTable.md) -- Create a single table
90
+ - [generateCreateTableStatement](generateCreateTableStatement.md) -- Generate DDL without executing
91
+ - [Schema & Table Creation](../schema.md) -- Full type mapping reference