meadow-connection-mssql 1.0.11 → 1.0.13

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,13 +10,14 @@ A Microsoft SQL Server connection provider for the Meadow ORM. Wraps [mssql](htt
10
10
 
11
11
  ## Features
12
12
 
13
- - **MSSQL Connection Pooling** - Managed connection pool via [mssql](https://github.com/tediousjs/node-mssql) (Tedious driver)
14
- - **Fable Service Provider** - Registers with a Fable instance for dependency injection, logging, and configuration
15
- - **Async Connection** - Truly asynchronous connection flow with promise-based pool creation and callback interface
16
- - **Prepared Statements** - Built-in `preparedStatement` getter for creating parameterized queries against the pool
17
- - **Schema-Driven DDL** - Generates `CREATE TABLE` statements with `[dbo]` schema prefix, `IDENTITY` primary keys, and proper MSSQL column types
18
- - **Connection Safety** - Guards against duplicate connection pools with descriptive logging (passwords are never leaked)
19
- - **Configurable Timeouts** - Request timeout (80s) and connection timeout (80s) with pool idle timeout (30s) defaults
13
+ - **MSSQL Connection Pooling** -- Managed connection pool via [mssql](https://github.com/tediousjs/node-mssql) (Tedious driver)
14
+ - **Fable Service Provider** -- Registers with a Fable instance for dependency injection, logging, and configuration
15
+ - **Async Connection** -- Truly asynchronous connection flow with promise-based pool creation and callback interface
16
+ - **Prepared Statements** -- Built-in `preparedStatement` getter for creating parameterized queries against the pool
17
+ - **Direct Driver Access** -- `MSSQL` getter exposes the raw `mssql` package for type constants (`Int`, `VarChar`, `Decimal`, etc.)
18
+ - **Schema-Driven DDL** -- Generates `CREATE TABLE` statements with `[dbo]` schema prefix, `IDENTITY` primary keys, and proper MSSQL column types
19
+ - **Connection Safety** -- Guards against duplicate connection pools with descriptive logging (passwords are never leaked)
20
+ - **Configurable Timeouts** -- Request timeout (80s) and connection timeout (80s) with pool idle timeout (30s) defaults
20
21
 
21
22
  ## Installation
22
23
 
@@ -171,13 +172,13 @@ Generate a safe `DROP TABLE` statement using `IF OBJECT_ID` to check existence b
171
172
 
172
173
  Meadow Connection MSSQL is a database connector for the Meadow data access layer:
173
174
 
174
- - [meadow](https://github.com/stevenvelozo/meadow) - ORM and data access framework
175
- - [foxhound](https://github.com/stevenvelozo/foxhound) - Query DSL used by Meadow
176
- - [stricture](https://github.com/stevenvelozo/stricture) - Schema definition tool
177
- - [meadow-endpoints](https://github.com/stevenvelozo/meadow-endpoints) - RESTful endpoint generation
178
- - [meadow-connection-mysql](https://github.com/stevenvelozo/meadow-connection-mysql) - MySQL connector
179
- - [meadow-connection-sqlite](https://github.com/stevenvelozo/meadow-connection-sqlite) - SQLite connector
180
- - [fable](https://github.com/stevenvelozo/fable) - Application services framework
175
+ - [meadow](https://github.com/stevenvelozo/meadow) -- ORM and data access framework
176
+ - [foxhound](https://github.com/stevenvelozo/foxhound) -- Query DSL used by Meadow
177
+ - [stricture](https://github.com/stevenvelozo/stricture) -- Schema definition tool
178
+ - [meadow-endpoints](https://github.com/stevenvelozo/meadow-endpoints) -- RESTful endpoint generation
179
+ - [meadow-connection-mysql](https://github.com/stevenvelozo/meadow-connection-mysql) -- MySQL connector
180
+ - [meadow-connection-sqlite](https://github.com/stevenvelozo/meadow-connection-sqlite) -- SQLite connector
181
+ - [fable](https://github.com/stevenvelozo/fable) -- Application services framework
181
182
 
182
183
  ## Testing
183
184
 
@@ -195,8 +196,10 @@ npm run coverage
195
196
 
196
197
  ## Related Packages
197
198
 
198
- - [meadow](https://github.com/stevenvelozo/meadow) - Data access and ORM
199
- - [fable](https://github.com/stevenvelozo/fable) - Application services framework
199
+ - [meadow](https://github.com/stevenvelozo/meadow) -- Data access and ORM
200
+ - [meadow-connection-mysql](https://github.com/stevenvelozo/meadow-connection-mysql) -- MySQL connection provider
201
+ - [meadow-connection-rocksdb](https://github.com/stevenvelozo/meadow-connection-rocksdb) -- RocksDB connection provider
202
+ - [fable](https://github.com/stevenvelozo/fable) -- Application services framework
200
203
 
201
204
  ## License
202
205
 
package/docs/README.md CHANGED
@@ -131,9 +131,29 @@ The `MSSQL` getter exposes the underlying `mssql` package for accessing type con
131
131
 
132
132
  The service can generate and execute CREATE TABLE statements from Meadow schema definitions. See [Schema & Table Creation](schema.md) for details.
133
133
 
134
+ ## How It Fits Together
135
+
136
+ ```
137
+ Application Code
138
+ |
139
+ Meadow ORM ← setProvider('MSSQL')
140
+ |
141
+ FoxHound ← Generates SQL queries
142
+ |
143
+ Meadow-Connection-MSSQL ← This module
144
+ |
145
+ mssql Pool ← Connection pooling, Tedious driver
146
+ |
147
+ SQL Server ← Your database
148
+ ```
149
+
150
+ Meadow Connection MSSQL sits between the Meadow ORM layer and the SQL Server. It manages the mssql connection pool, which Meadow's MSSQL provider uses to execute queries generated by FoxHound. The module also exposes prepared statements and the raw mssql library for direct use.
151
+
134
152
  ## Learn More
135
153
 
154
+ - [Quickstart](quickstart.md) -- Step-by-step walkthrough with code examples
155
+ - [Architecture](architecture.md) -- Design, data flow, and component responsibilities
136
156
  - [Schema & Table Creation](schema.md) -- Generate MSSQL tables from Meadow schemas
137
- - [API Reference](api.md) -- Complete method and property documentation
157
+ - [API Reference](api/reference.md) -- Complete method and property documentation
138
158
  - [Meadow](/meadow/meadow/) -- The data access layer
139
159
  - [FoxHound](/meadow/foxhound/) -- Query DSL used by Meadow
package/docs/_cover.md ADDED
@@ -0,0 +1,21 @@
1
+ # Meadow Connection MSSQL
2
+
3
+ <small>v1.0.11</small>
4
+
5
+ > Microsoft SQL Server connection pooling as a Fable service
6
+
7
+ A wrapper around the [mssql](https://github.com/tediousjs/node-mssql) npm package (Tedious driver) that manages connection pooling, prepared statements, and schema DDL generation. Register once, query from anywhere through Meadow or directly.
8
+
9
+ - **Async Connection** -- Promise-based pool creation with callback notification when ready
10
+ - **Connection Pooling** -- Managed pool with configurable timeouts and connection limits
11
+ - **Prepared Statements** -- First-class access to parameterized queries with MSSQL type constants
12
+ - **Direct Driver Access** -- `MSSQL` getter exposes the raw mssql package for type constants
13
+ - **Schema-Driven DDL** -- Generate CREATE TABLE statements with `[dbo]` schema and IDENTITY keys
14
+ - **Connection Safety** -- Guards against duplicate pools with cleansed logging
15
+
16
+ [Get Started](README.md)
17
+ [Quickstart](quickstart.md)
18
+ [Architecture](architecture.md)
19
+ [Schema & Tables](schema.md)
20
+ [API Reference](api/reference.md)
21
+ [GitHub](https://github.com/stevenvelozo/meadow-connection-mssql)
package/docs/_sidebar.md CHANGED
@@ -1,11 +1,25 @@
1
1
  - Getting Started
2
2
 
3
3
  - [Overview](README.md)
4
+ - [Quickstart](quickstart.md)
5
+
6
+ - Architecture
7
+
8
+ - [Design & Data Flow](architecture.md)
4
9
  - [Schema & Table Creation](schema.md)
5
10
 
6
- - Reference
11
+ - API Reference
7
12
 
8
- - [API Reference](api.md)
13
+ - [Full Reference](api/reference.md)
14
+ - [connectAsync()](api/connectAsync.md)
15
+ - [connect()](api/connect.md)
16
+ - [pool](api/pool.md)
17
+ - [preparedStatement](api/preparedStatement.md)
18
+ - [MSSQL](api/MSSQL.md)
19
+ - [generateCreateTableStatement()](api/generateCreateTableStatement.md)
20
+ - [createTable()](api/createTable.md)
21
+ - [createTables()](api/createTables.md)
22
+ - [generateDropTableStatement()](api/generateDropTableStatement.md)
9
23
 
10
24
  - Retold Ecosystem
11
25
 
@@ -13,4 +27,7 @@
13
27
  - [FoxHound](/meadow/foxhound/)
14
28
  - [Stricture](/meadow/stricture/)
15
29
  - [Meadow Endpoints](/meadow/meadow-endpoints/)
30
+ - [Meadow Connection MySQL](/meadow/meadow-connection-mysql/)
31
+ - [Meadow Connection SQLite](/meadow/meadow-connection-sqlite/)
32
+ - [Meadow Connection RocksDB](/meadow/meadow-connection-rocksdb/)
16
33
  - [Fable](/fable/fable/)
package/docs/_topbar.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Meadow Connection MSSQL
2
2
 
3
3
  - [Overview](README.md)
4
+ - [Quickstart](quickstart.md)
5
+ - [Architecture](architecture.md)
4
6
  - [Schema & Tables](schema.md)
5
- - [API Reference](api.md)
7
+ - [API Reference](api/reference.md)
6
8
  - [GitHub](https://github.com/stevenvelozo/meadow-connection-mssql)
@@ -0,0 +1,112 @@
1
+ # MSSQL (getter)
2
+
3
+ Returns the underlying `mssql` npm package module for direct access to SQL Server type constants and driver features.
4
+
5
+ ## Signature
6
+
7
+ ```javascript
8
+ get MSSQL()
9
+ ```
10
+
11
+ ## Return Value
12
+
13
+ | Type | Description |
14
+ |------|-------------|
15
+ | object | The `mssql` npm module |
16
+
17
+ ## Primary Use
18
+
19
+ The main purpose of this getter is to access type constants for prepared statement parameters:
20
+
21
+ ```javascript
22
+ let tmpPS = _Fable.MeadowMSSQLProvider.preparedStatement;
23
+
24
+ tmpPS.input('bookId', _Fable.MeadowMSSQLProvider.MSSQL.Int);
25
+ tmpPS.input('title', _Fable.MeadowMSSQLProvider.MSSQL.VarChar(255));
26
+ tmpPS.input('price', _Fable.MeadowMSSQLProvider.MSSQL.Decimal(10, 2));
27
+ ```
28
+
29
+ ## Type Constants Reference
30
+
31
+ ### Integer Types
32
+
33
+ | Constant | SQL Server Type | Range |
34
+ |----------|----------------|-------|
35
+ | `MSSQL.Int` | `INT` | -2^31 to 2^31-1 |
36
+ | `MSSQL.BigInt` | `BIGINT` | -2^63 to 2^63-1 |
37
+ | `MSSQL.SmallInt` | `SMALLINT` | -32,768 to 32,767 |
38
+ | `MSSQL.TinyInt` | `TINYINT` | 0 to 255 |
39
+
40
+ ### String Types
41
+
42
+ | Constant | SQL Server Type | Description |
43
+ |----------|----------------|-------------|
44
+ | `MSSQL.VarChar(n)` | `VARCHAR(n)` | Variable-length non-Unicode string |
45
+ | `MSSQL.NVarChar(n)` | `NVARCHAR(n)` | Variable-length Unicode string |
46
+ | `MSSQL.Char(n)` | `CHAR(n)` | Fixed-length non-Unicode string |
47
+ | `MSSQL.NChar(n)` | `NCHAR(n)` | Fixed-length Unicode string |
48
+ | `MSSQL.Text` | `TEXT` | Large non-Unicode text |
49
+ | `MSSQL.NText` | `NTEXT` | Large Unicode text |
50
+
51
+ ### Numeric Types
52
+
53
+ | Constant | SQL Server Type | Description |
54
+ |----------|----------------|-------------|
55
+ | `MSSQL.Decimal(p, s)` | `DECIMAL(p,s)` | Fixed precision and scale |
56
+ | `MSSQL.Float` | `FLOAT` | Approximate numeric |
57
+
58
+ ### Date/Time Types
59
+
60
+ | Constant | SQL Server Type | Description |
61
+ |----------|----------------|-------------|
62
+ | `MSSQL.DateTime` | `DATETIME` | Date and time (3.33ms precision) |
63
+ | `MSSQL.DateTime2(s)` | `DATETIME2(s)` | Higher precision date/time |
64
+ | `MSSQL.Date` | `DATE` | Date only |
65
+ | `MSSQL.Time` | `TIME` | Time only |
66
+
67
+ ### Other Types
68
+
69
+ | Constant | SQL Server Type | Description |
70
+ |----------|----------------|-------------|
71
+ | `MSSQL.Bit` | `BIT` | Boolean (0 or 1) |
72
+
73
+ ## Usage with Prepared Statements
74
+
75
+ ```javascript
76
+ let tmpMSSQL = _Fable.MeadowMSSQLProvider.MSSQL;
77
+ let tmpPS = _Fable.MeadowMSSQLProvider.preparedStatement;
78
+
79
+ tmpPS.input('id', tmpMSSQL.Int);
80
+ tmpPS.input('name', tmpMSSQL.VarChar(200));
81
+ tmpPS.input('price', tmpMSSQL.Decimal(10, 2));
82
+ tmpPS.input('published', tmpMSSQL.DateTime);
83
+ tmpPS.input('active', tmpMSSQL.Bit);
84
+
85
+ tmpPS.prepare(
86
+ 'INSERT INTO Product ([Name], [Price], [PublishDate], [Active]) VALUES (@name, @price, @published, @active); SELECT SCOPE_IDENTITY() AS ID',
87
+ (pError) =>
88
+ {
89
+ if (pError) { return; }
90
+
91
+ tmpPS.execute(
92
+ {
93
+ name: 'Widget',
94
+ price: 19.99,
95
+ published: new Date(),
96
+ active: true
97
+ },
98
+ (pError, pResult) =>
99
+ {
100
+ if (!pError)
101
+ {
102
+ console.log(`Inserted ID: ${pResult.recordset[0].ID}`);
103
+ }
104
+ tmpPS.unprepare(() => {});
105
+ });
106
+ });
107
+ ```
108
+
109
+ ## Related
110
+
111
+ - [preparedStatement](preparedStatement.md) -- Create prepared statements that use these types
112
+ - [pool](pool.md) -- Direct query access
@@ -0,0 +1,74 @@
1
+ # connect()
2
+
3
+ Synchronous convenience wrapper that calls `connectAsync()` without a callback.
4
+
5
+ > **Warning:** This method is **not recommended** because the MSSQL driver requires an asynchronous connection handshake. Using `connect()` can cause race conditions where queries are executed before the pool is ready. Always prefer [connectAsync()](connectAsync.md).
6
+
7
+ ## Signature
8
+
9
+ ```javascript
10
+ connect()
11
+ ```
12
+
13
+ ## Parameters
14
+
15
+ None.
16
+
17
+ ## Return Value
18
+
19
+ None.
20
+
21
+ ## Behavior
22
+
23
+ 1. Logs a warning: "The non-async Meadow-MSSQL connect() was called and the Microsoft SQL node driver has an asynchronous connection method; although this may function it will likely cause a race condition."
24
+ 2. Calls `this.connectAsync()` internally without passing a callback
25
+
26
+ ## Usage
27
+
28
+ ```javascript
29
+ // NOT recommended -- use connectAsync() instead
30
+ _Fable.MeadowMSSQLProvider.connect();
31
+
32
+ // The pool may not be ready yet -- race condition!
33
+ // _Fable.MeadowMSSQLProvider.pool.query(...) // might fail
34
+ ```
35
+
36
+ ## Why It Exists
37
+
38
+ This method exists for API symmetry with other Meadow connection providers (MySQL, SQLite) that support synchronous connection. The `MeadowConnectionMSSQLAutoConnect` flag calls `connect()` during construction, which allows a one-liner instantiation pattern:
39
+
40
+ ```javascript
41
+ let _Fable = new libFable(
42
+ {
43
+ "MSSQL":
44
+ {
45
+ "server": "localhost",
46
+ "port": 1433,
47
+ "user": "sa",
48
+ "password": "YourPassword123",
49
+ "database": "bookstore",
50
+ "MeadowConnectionMSSQLAutoConnect": true
51
+ }
52
+ });
53
+
54
+ _Fable.serviceManager.addAndInstantiateServiceType(
55
+ 'MeadowMSSQLProvider', libMeadowConnectionMSSQL);
56
+
57
+ // Pool is connecting asynchronously -- not guaranteed to be ready yet
58
+ ```
59
+
60
+ ## Recommended Alternative
61
+
62
+ ```javascript
63
+ _Fable.MeadowMSSQLProvider.connectAsync(
64
+ (pError, pPool) =>
65
+ {
66
+ if (pError) return console.error(pError);
67
+ // Pool is guaranteed to be ready here
68
+ });
69
+ ```
70
+
71
+ ## Related
72
+
73
+ - [connectAsync](connectAsync.md) -- Async connection (recommended)
74
+ - [pool](pool.md) -- Access the connection pool
@@ -0,0 +1,112 @@
1
+ # connectAsync(fCallback)
2
+
3
+ Asynchronously establishes a connection pool to Microsoft SQL Server. This is the **recommended** connection method -- MSSQL connections are inherently asynchronous due to the TDS protocol handshake.
4
+
5
+ ## Signature
6
+
7
+ ```javascript
8
+ connectAsync(fCallback)
9
+ ```
10
+
11
+ ## Parameters
12
+
13
+ | Parameter | Type | Required | Description |
14
+ |-----------|------|----------|-------------|
15
+ | `fCallback` | function | Yes | Callback with signature `(pError, pConnectionPool)` |
16
+
17
+ ## Return Value
18
+
19
+ None (result provided via callback).
20
+
21
+ ## Callback Arguments
22
+
23
+ | Argument | Type | Description |
24
+ |----------|------|-------------|
25
+ | `pError` | Error or null | Connection error, if any |
26
+ | `pConnectionPool` | mssql Pool | The connected mssql pool instance |
27
+
28
+ ## Behavior
29
+
30
+ 1. If `fCallback` is not a function, logs an error and substitutes a no-op callback
31
+ 2. If a pool already exists (`this._ConnectionPool` is truthy):
32
+ - Logs an error with cleansed connection details (password masked)
33
+ - Returns the existing pool via the callback (prevents duplicate connections)
34
+ 3. If not connected:
35
+ - Logs the connection attempt details (server, port, user, database, pool limit)
36
+ - Calls `mssql.connect()` with the resolved settings (Promise-based)
37
+ - Applies hardcoded pool, timeout, and TLS settings
38
+ - On success: sets `connected = true`, logs success, calls callback with `(null, pool)`
39
+ - On error: logs the error, calls callback with `(error)`
40
+
41
+ ## Basic Usage
42
+
43
+ ```javascript
44
+ const libFable = require('fable');
45
+ const libMeadowConnectionMSSQL = require('meadow-connection-mssql');
46
+
47
+ let _Fable = new libFable(
48
+ {
49
+ "MSSQL":
50
+ {
51
+ "server": "localhost",
52
+ "port": 1433,
53
+ "user": "sa",
54
+ "password": "YourPassword123",
55
+ "database": "bookstore"
56
+ }
57
+ });
58
+
59
+ _Fable.serviceManager.addServiceType('MeadowMSSQLProvider', libMeadowConnectionMSSQL);
60
+ _Fable.serviceManager.instantiateServiceProvider('MeadowMSSQLProvider');
61
+
62
+ _Fable.MeadowMSSQLProvider.connectAsync(
63
+ (pError, pPool) =>
64
+ {
65
+ if (pError)
66
+ {
67
+ console.error('Connection failed:', pError);
68
+ return;
69
+ }
70
+
71
+ // pPool is the mssql connection pool
72
+ pPool.query('SELECT TOP 5 * FROM Book')
73
+ .then((pResult) =>
74
+ {
75
+ console.log(`Found ${pResult.recordset.length} books.`);
76
+ });
77
+ });
78
+ ```
79
+
80
+ ## Double-Connect Guard
81
+
82
+ Calling `connectAsync()` a second time returns the existing pool without creating a new one:
83
+
84
+ ```javascript
85
+ _Fable.MeadowMSSQLProvider.connectAsync(
86
+ (pError, pPool1) =>
87
+ {
88
+ // First call -- pool created
89
+
90
+ _Fable.MeadowMSSQLProvider.connectAsync(
91
+ (pError, pPool2) =>
92
+ {
93
+ // Second call -- logs error, returns existing pool
94
+ // "already established a connection"
95
+ });
96
+ });
97
+ ```
98
+
99
+ ## Missing Callback Warning
100
+
101
+ If called without a callback, `connectAsync()` logs an error:
102
+
103
+ ```javascript
104
+ // Not recommended
105
+ _Fable.MeadowMSSQLProvider.connectAsync();
106
+ // Logs error about missing callback
107
+ ```
108
+
109
+ ## Related
110
+
111
+ - [connect](connect.md) -- Synchronous wrapper (not recommended)
112
+ - [pool](pool.md) -- Access the connection pool
@@ -0,0 +1,96 @@
1
+ # createTable(pMeadowTableSchema, fCallback)
2
+
3
+ Generates and executes a `CREATE TABLE` statement against the connected MSSQL pool.
4
+
5
+ ## Signature
6
+
7
+ ```javascript
8
+ createTable(pMeadowTableSchema, fCallback)
9
+ ```
10
+
11
+ ## Parameters
12
+
13
+ | Parameter | Type | Required | Description |
14
+ |-----------|------|----------|-------------|
15
+ | `pMeadowTableSchema` | object | Yes | Schema with `TableName` and `Columns` array |
16
+ | `fCallback` | function | Yes | Callback with signature `(pError)` |
17
+
18
+ ## Return Value
19
+
20
+ None (result provided via callback).
21
+
22
+ ## Behavior
23
+
24
+ 1. Calls `generateCreateTableStatement(pMeadowTableSchema)` to produce the DDL string
25
+ 2. Executes via `this._ConnectionPool.query()` (Promise-based)
26
+ 3. On success:
27
+ - Logs info: "Meadow-MSSQL CREATE TABLE [TableName] Success"
28
+ - Logs warning with the full SQL statement
29
+ - Calls `fCallback()` with no error
30
+ 4. On error:
31
+ - Checks if the error indicates the table already exists (via `originalError.info.message`)
32
+ - If table exists: silently succeeds, calls `fCallback()` with no error
33
+ - Otherwise: logs the error, calls `fCallback(pError)`
34
+
35
+ ## Basic Usage
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: 255 },
46
+ { Column: 'Author', DataType: 'String', Size: 128 },
47
+ { Column: 'Year', DataType: 'Numeric' }
48
+ ]
49
+ };
50
+
51
+ _Fable.MeadowMSSQLProvider.createTable(tmpSchema,
52
+ (pError) =>
53
+ {
54
+ if (pError)
55
+ {
56
+ console.error('Table creation failed:', pError);
57
+ return;
58
+ }
59
+ console.log('Book table created successfully.');
60
+ });
61
+ ```
62
+
63
+ ## Idempotent Operation
64
+
65
+ Calling `createTable()` for an existing table does not produce an error. The "table already exists" error is caught internally and execution continues:
66
+
67
+ ```
68
+ // No error -- table simply already existed
69
+ ```
70
+
71
+ This makes `createTable()` safe to call during application startup.
72
+
73
+ ## Prerequisites
74
+
75
+ The connection pool must be established before calling `createTable()`:
76
+
77
+ ```javascript
78
+ _Fable.MeadowMSSQLProvider.connectAsync(
79
+ (pError) =>
80
+ {
81
+ if (pError) { return; }
82
+
83
+ _Fable.MeadowMSSQLProvider.createTable(tmpSchema,
84
+ (pCreateError) =>
85
+ {
86
+ if (pCreateError) { console.error(pCreateError); }
87
+ });
88
+ });
89
+ ```
90
+
91
+ ## Related
92
+
93
+ - [generateCreateTableStatement](generateCreateTableStatement.md) -- Generate DDL without executing
94
+ - [createTables](createTables.md) -- Create multiple tables sequentially
95
+ - [generateDropTableStatement](generateDropTableStatement.md) -- Generate DROP TABLE DDL
96
+ - [Schema & Table Creation](../schema.md) -- Full walkthrough
@@ -0,0 +1,111 @@
1
+ # createTables(pMeadowSchema, fCallback)
2
+
3
+ Creates all tables defined in a Meadow schema object by calling `createTable()` for each table sequentially.
4
+
5
+ ## Signature
6
+
7
+ ```javascript
8
+ createTables(pMeadowSchema, fCallback)
9
+ ```
10
+
11
+ ## Parameters
12
+
13
+ | Parameter | Type | Required | Description |
14
+ |-----------|------|----------|-------------|
15
+ | `pMeadowSchema` | object | Yes | Schema with a `Tables` array of table schema objects |
16
+ | `fCallback` | function | Yes | Callback with signature `(pError)` |
17
+
18
+ ### Schema Object Format
19
+
20
+ ```javascript
21
+ {
22
+ Tables:
23
+ [
24
+ {
25
+ TableName: 'Author',
26
+ Columns:
27
+ [
28
+ { Column: 'IDAuthor', DataType: 'ID' },
29
+ { Column: 'Name', DataType: 'String', Size: 200 }
30
+ ]
31
+ },
32
+ {
33
+ TableName: 'Book',
34
+ Columns:
35
+ [
36
+ { Column: 'IDBook', DataType: 'ID' },
37
+ { Column: 'Title', DataType: 'String', Size: 255 },
38
+ { Column: 'IDAuthor', DataType: 'ForeignKey' }
39
+ ]
40
+ }
41
+ ]
42
+ }
43
+ ```
44
+
45
+ ## Return Value
46
+
47
+ None (result provided via callback).
48
+
49
+ ## Behavior
50
+
51
+ 1. Iterates `pMeadowSchema.Tables` using `fable.Utility.eachLimit()` with a concurrency of 1 (serial)
52
+ 2. Calls `createTable()` for each table in the array
53
+ 3. If any table creation fails (with an error other than "already exists"), logs the error and passes it to the final callback
54
+ 4. On completion, logs "Done creating tables!" and calls `fCallback()`
55
+
56
+ ## Basic Usage
57
+
58
+ ```javascript
59
+ let tmpFullSchema =
60
+ {
61
+ Tables:
62
+ [
63
+ {
64
+ TableName: 'Author',
65
+ Columns:
66
+ [
67
+ { Column: 'IDAuthor', DataType: 'ID' },
68
+ { Column: 'GUIDAuthor', DataType: 'GUID' },
69
+ { Column: 'Name', DataType: 'String', Size: 200 },
70
+ { Column: 'Bio', DataType: 'Text' }
71
+ ]
72
+ },
73
+ {
74
+ TableName: 'Book',
75
+ Columns:
76
+ [
77
+ { Column: 'IDBook', DataType: 'ID' },
78
+ { Column: 'GUIDBook', DataType: 'GUID' },
79
+ { Column: 'Title', DataType: 'String', Size: 255 },
80
+ { Column: 'Year', DataType: 'Numeric' },
81
+ { Column: 'IDAuthor', DataType: 'ForeignKey' }
82
+ ]
83
+ }
84
+ ]
85
+ };
86
+
87
+ _Fable.MeadowMSSQLProvider.createTables(tmpFullSchema,
88
+ (pError) =>
89
+ {
90
+ if (pError)
91
+ {
92
+ console.error('Schema creation failed:', pError);
93
+ return;
94
+ }
95
+ console.log('All tables created.');
96
+ });
97
+ ```
98
+
99
+ ## Serial Execution
100
+
101
+ Tables are created one at a time (concurrency of 1). This respects dependency ordering and avoids concurrent DDL issues with SQL Server.
102
+
103
+ ## Error Handling
104
+
105
+ If a table creation fails with an error other than "table already exists", execution stops and the error is passed to the callback. Tables created before the failure remain in the database.
106
+
107
+ ## Related
108
+
109
+ - [createTable](createTable.md) -- Create a single table
110
+ - [generateCreateTableStatement](generateCreateTableStatement.md) -- Generate DDL without executing
111
+ - [Schema & Table Creation](../schema.md) -- Full walkthrough