meadow 2.0.22 → 2.0.26
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 +110 -141
- package/docs/README.md +34 -230
- package/docs/_cover.md +14 -0
- package/docs/_sidebar.md +44 -12
- package/docs/_topbar.md +5 -0
- package/docs/api/doCount.md +109 -0
- package/docs/api/doCreate.md +132 -0
- package/docs/api/doDelete.md +101 -0
- package/docs/api/doRead.md +122 -0
- package/docs/api/doReads.md +136 -0
- package/docs/api/doUndelete.md +98 -0
- package/docs/api/doUpdate.md +129 -0
- package/docs/api/getRoleName.md +84 -0
- package/docs/api/loadFromPackage.md +153 -0
- package/docs/api/marshalRecordFromSourceToObject.md +92 -0
- package/docs/api/query.md +133 -0
- package/docs/api/rawQueries.md +197 -0
- package/docs/api/reference.md +117 -0
- package/docs/api/setAuthorizer.md +103 -0
- package/docs/api/setDefault.md +90 -0
- package/docs/api/setDefaultIdentifier.md +84 -0
- package/docs/api/setDomain.md +56 -0
- package/docs/api/setIDUser.md +91 -0
- package/docs/api/setJsonSchema.md +92 -0
- package/docs/api/setProvider.md +87 -0
- package/docs/api/setSchema.md +107 -0
- package/docs/api/setScope.md +68 -0
- package/docs/api/validateObject.md +119 -0
- package/docs/architecture.md +316 -0
- package/docs/audit-tracking.md +226 -0
- package/docs/configuration.md +317 -0
- package/docs/providers/meadow-endpoints.md +306 -0
- package/docs/providers/mongodb.md +319 -0
- package/docs/providers/postgresql.md +312 -0
- package/docs/providers/rocksdb.md +297 -0
- package/docs/query-dsl.md +269 -0
- package/docs/quick-start.md +384 -0
- package/docs/raw-queries.md +193 -0
- package/docs/retold-catalog.json +61 -1
- package/docs/retold-keyword-index.json +15860 -4839
- package/docs/soft-deletes.md +224 -0
- package/package.json +44 -27
- package/scripts/bookstore-seed-postgresql.sql +135 -0
- package/scripts/dgraph-test-db.sh +144 -0
- package/scripts/meadow-test-cleanup.sh +5 -1
- package/scripts/mongodb-test-db.sh +98 -0
- package/scripts/postgresql-test-db.sh +124 -0
- package/scripts/solr-test-db.sh +135 -0
- package/source/Meadow.js +5 -0
- package/source/providers/Meadow-Provider-DGraph.js +679 -0
- package/source/providers/Meadow-Provider-MongoDB.js +527 -0
- package/source/providers/Meadow-Provider-PostgreSQL.js +361 -0
- package/source/providers/Meadow-Provider-RocksDB.js +1300 -0
- package/source/providers/Meadow-Provider-Solr.js +726 -0
- package/test/Meadow-Provider-DGraph_tests.js +741 -0
- package/test/Meadow-Provider-MongoDB_tests.js +661 -0
- package/test/Meadow-Provider-PostgreSQL_tests.js +787 -0
- package/test/Meadow-Provider-RocksDB_tests.js +887 -0
- package/test/Meadow-Provider-Solr_tests.js +679 -0
package/README.md
CHANGED
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
# Meadow
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A data access library providing magic where you want it, programmability where you don't.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://badge.fury.io/js/meadow)
|
|
6
|
+
[](https://travis-ci.org/stevenvelozo/meadow)
|
|
7
|
+
|
|
8
|
+
Meadow is a JavaScript data broker that handles repetitive CRUD operations through a consistent, provider-agnostic interface. It abstracts database communication behind a unified API -- whether your data lives in MySQL, MSSQL, PostgreSQL, SQLite, MongoDB, RocksDB, or an in-browser ALASQL store, Meadow provides schema management, query generation, data marshalling, and automatic audit stamping while you focus on business logic.
|
|
6
9
|
|
|
7
10
|
## Features
|
|
8
11
|
|
|
9
|
-
- **Provider-Agnostic Design**
|
|
10
|
-
- **Schema-Driven**
|
|
11
|
-
- **FoxHound Query DSL**
|
|
12
|
-
- **Automatic Audit Tracking**
|
|
13
|
-
- **Soft Deletes**
|
|
14
|
-
- **GUID Uniqueness**
|
|
15
|
-
- **Raw Query Overrides**
|
|
16
|
-
- **
|
|
12
|
+
- **Provider-Agnostic Design** -- pluggable database backends through a consistent CRUD interface
|
|
13
|
+
- **Schema-Driven** -- define your data model once and get validation, default objects, and audit tracking for free
|
|
14
|
+
- **FoxHound Query DSL** -- fluent query builder that generates dialect-specific SQL, MongoDB queries, or key-value lookups
|
|
15
|
+
- **Automatic Audit Tracking** -- auto-populated create, update, and delete timestamps with user identity stamps
|
|
16
|
+
- **Soft Deletes** -- built-in logical deletion with automatic query filtering and undelete support
|
|
17
|
+
- **GUID Uniqueness** -- automatic GUID generation and uniqueness enforcement on record creation
|
|
18
|
+
- **Raw Query Overrides** -- escape hatch for custom SQL when the DSL is not enough
|
|
19
|
+
- **Role-Based Authorization** -- declarative access control per operation integrated with Meadow-Endpoints
|
|
20
|
+
- **Fable Integration** -- first-class service in the Fable ecosystem with logging, configuration, and dependency injection
|
|
21
|
+
- **Browser Support** -- ALASQL provider enables the same data access patterns in the browser via IndexedDB
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install meadow
|
|
27
|
+
```
|
|
17
28
|
|
|
18
|
-
## Quick
|
|
29
|
+
## Quick Example
|
|
19
30
|
|
|
20
31
|
```javascript
|
|
21
32
|
const libFable = require('fable').new();
|
|
@@ -39,64 +50,22 @@ const meadow = libMeadow.new(libFable, 'Book')
|
|
|
39
50
|
{ Column: 'Deleted', Type: 'Deleted' }
|
|
40
51
|
]);
|
|
41
52
|
|
|
42
|
-
//
|
|
43
|
-
meadow.
|
|
44
|
-
|
|
45
|
-
{
|
|
46
|
-
if (pError)
|
|
47
|
-
{
|
|
48
|
-
return console.log('Error reading book:', pError);
|
|
49
|
-
}
|
|
50
|
-
console.log('Found:', pBook.Title, 'by', pBook.Author);
|
|
51
|
-
});
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Installation
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
npm install meadow
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
## How It Works
|
|
61
|
-
|
|
62
|
-
Meadow follows the Fable service provider pattern. You create a DAL instance for each entity in your data model, configure its schema and provider, then use the CRUD methods to interact with your database. Meadow handles query generation, data marshalling, schema validation, and audit stamping automatically.
|
|
63
|
-
|
|
64
|
-
```
|
|
65
|
-
Fable (Core)
|
|
66
|
-
└── Meadow (Data Access Layer)
|
|
67
|
-
├── Schema (Column definitions, validation, defaults)
|
|
68
|
-
├── FoxHound Query DSL (Dialect-specific SQL generation)
|
|
69
|
-
├── Behaviors (Create, Read, Reads, Update, Delete, Count, Undelete)
|
|
70
|
-
└── Provider (MySQL, MSSQL, SQLite, ALASQL, MeadowEndpoints, None)
|
|
71
|
-
└── Database Connection
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## CRUD Operations
|
|
75
|
-
|
|
76
|
-
All operations follow an async waterfall pattern with a consistent callback signature.
|
|
77
|
-
|
|
78
|
-
### Create
|
|
79
|
-
|
|
80
|
-
```javascript
|
|
81
|
-
const tmpQuery = meadow.query.addRecord({ Title: 'Dune', Author: 'Frank Herbert' });
|
|
82
|
-
meadow.doCreate(tmpQuery,
|
|
53
|
+
// Create a record
|
|
54
|
+
const tmpCreateQuery = meadow.query.addRecord({ Title: 'Dune', Author: 'Frank Herbert' });
|
|
55
|
+
meadow.doCreate(tmpCreateQuery,
|
|
83
56
|
(pError, pCreateQuery, pReadQuery, pRecord) =>
|
|
84
57
|
{
|
|
85
|
-
console.log('Created book
|
|
58
|
+
console.log('Created book:', pRecord.IDBook, '-', pRecord.Title);
|
|
86
59
|
});
|
|
87
|
-
```
|
|
88
60
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
```javascript
|
|
92
|
-
// Single record
|
|
61
|
+
// Read a single record
|
|
93
62
|
meadow.doRead(meadow.query.addFilter('IDBook', 1),
|
|
94
63
|
(pError, pQuery, pRecord) =>
|
|
95
64
|
{
|
|
96
|
-
console.log('
|
|
65
|
+
console.log('Found:', pRecord.Title, 'by', pRecord.Author);
|
|
97
66
|
});
|
|
98
67
|
|
|
99
|
-
//
|
|
68
|
+
// Read multiple records with pagination
|
|
100
69
|
meadow.doReads(meadow.query.setCap(25).setBegin(0),
|
|
101
70
|
(pError, pQuery, pRecords) =>
|
|
102
71
|
{
|
|
@@ -104,90 +73,83 @@ meadow.doReads(meadow.query.setCap(25).setBegin(0),
|
|
|
104
73
|
});
|
|
105
74
|
```
|
|
106
75
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
```javascript
|
|
110
|
-
const tmpQuery = meadow.query
|
|
111
|
-
.addFilter('IDBook', 1)
|
|
112
|
-
.addRecord({ Title: 'Updated Title' });
|
|
113
|
-
meadow.doUpdate(tmpQuery,
|
|
114
|
-
(pError, pUpdateQuery, pReadQuery, pRecord) =>
|
|
115
|
-
{
|
|
116
|
-
console.log('Updated:', pRecord.Title);
|
|
117
|
-
});
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
### Delete and Count
|
|
121
|
-
|
|
122
|
-
```javascript
|
|
123
|
-
// Delete (soft delete if schema supports it)
|
|
124
|
-
meadow.doDelete(meadow.query.addFilter('IDBook', 1),
|
|
125
|
-
(pError, pQuery, pResult) =>
|
|
126
|
-
{
|
|
127
|
-
console.log('Deleted:', pResult, 'record(s)');
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
// Count records
|
|
131
|
-
meadow.doCount(meadow.query,
|
|
132
|
-
(pError, pQuery, pCount) =>
|
|
133
|
-
{
|
|
134
|
-
console.log('Total books:', pCount);
|
|
135
|
-
});
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
## Schema
|
|
139
|
-
|
|
140
|
-
Meadow schemas define your data model with special column types that enable automatic behavior:
|
|
76
|
+
## Schema Column Types
|
|
141
77
|
|
|
142
78
|
| Type | Description |
|
|
143
79
|
|------|-------------|
|
|
144
80
|
| `AutoIdentity` | Auto-increment primary key |
|
|
145
81
|
| `AutoGUID` | Automatically generated GUID |
|
|
146
|
-
| `
|
|
147
|
-
| `
|
|
148
|
-
| `
|
|
149
|
-
| `
|
|
150
|
-
| `
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
|
155
|
-
|
|
156
|
-
| `
|
|
157
|
-
| `
|
|
158
|
-
| `
|
|
159
|
-
| `ALASQL` | In-browser IndexedDB via ALASQL |
|
|
160
|
-
| `MeadowEndpoints` | REST proxy to remote Meadow API |
|
|
161
|
-
| `None` | Null provider for testing |
|
|
162
|
-
|
|
163
|
-
## ALASQL Provider Example
|
|
164
|
-
|
|
165
|
-
```javascript
|
|
166
|
-
const libFable = require('fable').new();
|
|
167
|
-
const libALASQL = require('alasql');
|
|
82
|
+
| `String` | Variable-length string with optional `Size` |
|
|
83
|
+
| `Text` | Long text field |
|
|
84
|
+
| `Numeric` | Integer field |
|
|
85
|
+
| `Decimal` | Decimal field with `Size` as `"precision,scale"` |
|
|
86
|
+
| `Boolean` | Boolean flag |
|
|
87
|
+
| `DateTime` | Date/time field |
|
|
88
|
+
| `CreateDate` | Auto-populated timestamp on create |
|
|
89
|
+
| `CreateIDUser` | Auto-populated user ID on create |
|
|
90
|
+
| `UpdateDate` | Auto-populated timestamp on update |
|
|
91
|
+
| `UpdateIDUser` | Auto-populated user ID on update |
|
|
92
|
+
| `DeleteDate` | Auto-populated timestamp on delete |
|
|
93
|
+
| `DeleteIDUser` | Auto-populated user ID on delete |
|
|
94
|
+
| `Deleted` | Soft delete flag (enables logical deletion) |
|
|
168
95
|
|
|
169
|
-
|
|
170
|
-
libALASQL('ATTACH INDEXEDDB DATABASE example;');
|
|
171
|
-
libALASQL('USE example;');
|
|
172
|
-
libFable.ALASQL = libALASQL;
|
|
173
|
-
|
|
174
|
-
const meadow = require('meadow').new(libFable, 'Customers')
|
|
175
|
-
.setProvider('ALASQL')
|
|
176
|
-
.setDefaultIdentifier('customerID');
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
## MSSQL Docker Image
|
|
96
|
+
## CRUD Operations
|
|
180
97
|
|
|
181
|
-
|
|
98
|
+
| Method | Callback Signature | Description |
|
|
99
|
+
|--------|-------------------|-------------|
|
|
100
|
+
| `doCreate(pQuery, fCB)` | `(pError, pCreateQuery, pReadQuery, pRecord)` | Insert a new record |
|
|
101
|
+
| `doRead(pQuery, fCB)` | `(pError, pQuery, pRecord)` | Read a single record |
|
|
102
|
+
| `doReads(pQuery, fCB)` | `(pError, pQuery, pRecords)` | Read multiple records |
|
|
103
|
+
| `doUpdate(pQuery, fCB)` | `(pError, pUpdateQuery, pReadQuery, pRecord)` | Update an existing record |
|
|
104
|
+
| `doDelete(pQuery, fCB)` | `(pError, pQuery, pCount)` | Delete a record (soft or hard) |
|
|
105
|
+
| `doUndelete(pQuery, fCB)` | `(pError, pQuery, pCount)` | Restore a soft-deleted record |
|
|
106
|
+
| `doCount(pQuery, fCB)` | `(pError, pQuery, pCount)` | Count matching records |
|
|
107
|
+
|
|
108
|
+
## Configuration Methods
|
|
109
|
+
|
|
110
|
+
| Method | Returns | Description |
|
|
111
|
+
|--------|---------|-------------|
|
|
112
|
+
| `setProvider(pName)` | `this` | Set database provider (`MySQL`, `MSSQL`, `PostgreSQL`, `SQLite`, `MongoDB`, `RocksDB`, `ALASQL`, `MeadowEndpoints`, `None`) |
|
|
113
|
+
| `setScope(pScope)` | `this` | Set entity scope (table name) |
|
|
114
|
+
| `setSchema(pSchema)` | `this` | Set column schema array |
|
|
115
|
+
| `setDefaultIdentifier(pId)` | `this` | Set primary key column name |
|
|
116
|
+
| `setIDUser(pIDUser)` | `this` | Set user ID for audit stamps |
|
|
117
|
+
| `setJsonSchema(pSchema)` | `this` | Set JSON Schema v4 for validation |
|
|
118
|
+
| `setDefault(pDefault)` | `this` | Set default object template |
|
|
119
|
+
| `setAuthorizer(pAuth)` | `this` | Set role-based authorization rules |
|
|
120
|
+
| `setDomain(pDomain)` | `this` | Set entity domain grouping |
|
|
121
|
+
| `loadFromPackage(pPath)` | `Meadow` | Load schema from JSON file |
|
|
122
|
+
| `loadFromPackageObject(pObj)` | `Meadow` | Load schema from object |
|
|
123
|
+
|
|
124
|
+
## Properties
|
|
125
|
+
|
|
126
|
+
| Property | Type | Description |
|
|
127
|
+
|----------|------|-------------|
|
|
128
|
+
| `scope` | `string` | Entity scope name |
|
|
129
|
+
| `schema` | `array` | Column schema definitions |
|
|
130
|
+
| `schemaFull` | `object` | Full MeadowSchema with methods |
|
|
131
|
+
| `jsonSchema` | `object` | JSON Schema v4 definition |
|
|
132
|
+
| `defaultIdentifier` | `string` | Primary key column name |
|
|
133
|
+
| `defaultGUIdentifier` | `string` | GUID column name |
|
|
134
|
+
| `userIdentifier` | `number` | Current user ID |
|
|
135
|
+
| `query` | `object` | Cloned FoxHound query (fresh each access) |
|
|
136
|
+
| `rawQueries` | `object` | Raw query manager |
|
|
137
|
+
| `provider` | `object` | Active provider instance |
|
|
138
|
+
| `providerName` | `string` | Active provider name |
|
|
182
139
|
|
|
183
|
-
|
|
184
|
-
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=1234567890abc." \
|
|
185
|
-
-p 14333:1433 --name meadow-mssql-test --hostname meadowsqltest \
|
|
186
|
-
-d mcr.microsoft.com/mssql/server:2022-latest
|
|
140
|
+
## Providers
|
|
187
141
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
142
|
+
| Provider | Description | Connection Module |
|
|
143
|
+
|----------|-------------|-------------------|
|
|
144
|
+
| `MySQL` | MySQL/MariaDB via mysql2 | [meadow-connection-mysql](https://github.com/stevenvelozo/meadow-connection-mysql) |
|
|
145
|
+
| `MSSQL` | Microsoft SQL Server | [meadow-connection-mssql](https://github.com/stevenvelozo/meadow-connection-mssql) |
|
|
146
|
+
| `PostgreSQL` | PostgreSQL | [meadow-connection-postgresql](https://github.com/stevenvelozo/meadow-connection-postgresql) |
|
|
147
|
+
| `SQLite` | Embedded SQLite via better-sqlite3 | [meadow-connection-sqlite](https://github.com/stevenvelozo/meadow-connection-sqlite) |
|
|
148
|
+
| `MongoDB` | MongoDB document store | [meadow-connection-mongodb](https://github.com/stevenvelozo/meadow-connection-mongodb) |
|
|
149
|
+
| `RocksDB` | Embedded key-value store | [meadow-connection-rocksdb](https://github.com/stevenvelozo/meadow-connection-rocksdb) |
|
|
150
|
+
| `ALASQL` | In-browser IndexedDB via ALASQL | Built-in |
|
|
151
|
+
| `MeadowEndpoints` | REST proxy to remote Meadow API | Built-in |
|
|
152
|
+
| `None` | No-op stub for testing | None required |
|
|
191
153
|
|
|
192
154
|
## Testing
|
|
193
155
|
|
|
@@ -197,7 +159,7 @@ npm test
|
|
|
197
159
|
|
|
198
160
|
## Documentation
|
|
199
161
|
|
|
200
|
-
Detailed documentation is available in the `docs/` folder
|
|
162
|
+
Detailed documentation is available in the `docs/` folder:
|
|
201
163
|
|
|
202
164
|
```bash
|
|
203
165
|
npx docsify-cli serve docs
|
|
@@ -205,10 +167,17 @@ npx docsify-cli serve docs
|
|
|
205
167
|
|
|
206
168
|
## Related Packages
|
|
207
169
|
|
|
208
|
-
- [foxhound](https://github.com/stevenvelozo/foxhound)
|
|
209
|
-
- [stricture](https://github.com/stevenvelozo/stricture)
|
|
210
|
-
- [meadow-endpoints](https://github.com/stevenvelozo/meadow-endpoints)
|
|
211
|
-
- [
|
|
170
|
+
- [foxhound](https://github.com/stevenvelozo/foxhound) -- query DSL for SQL and NoSQL generation
|
|
171
|
+
- [stricture](https://github.com/stevenvelozo/stricture) -- schema definition language
|
|
172
|
+
- [meadow-endpoints](https://github.com/stevenvelozo/meadow-endpoints) -- automatic REST endpoint generation
|
|
173
|
+
- [meadow-connection-mysql](https://github.com/stevenvelozo/meadow-connection-mysql) -- MySQL connection provider
|
|
174
|
+
- [meadow-connection-mssql](https://github.com/stevenvelozo/meadow-connection-mssql) -- MSSQL connection provider
|
|
175
|
+
- [meadow-connection-sqlite](https://github.com/stevenvelozo/meadow-connection-sqlite) -- SQLite connection provider
|
|
176
|
+
- [meadow-connection-postgresql](https://github.com/stevenvelozo/meadow-connection-postgresql) -- PostgreSQL connection provider
|
|
177
|
+
- [meadow-connection-mongodb](https://github.com/stevenvelozo/meadow-connection-mongodb) -- MongoDB connection provider
|
|
178
|
+
- [meadow-connection-rocksdb](https://github.com/stevenvelozo/meadow-connection-rocksdb) -- RocksDB connection provider
|
|
179
|
+
- [fable](https://github.com/stevenvelozo/fable) -- application services framework
|
|
180
|
+
- [orator](https://github.com/stevenvelozo/orator) -- API server abstraction
|
|
212
181
|
|
|
213
182
|
## License
|
|
214
183
|
|
|
@@ -216,4 +185,4 @@ MIT
|
|
|
216
185
|
|
|
217
186
|
## Contributing
|
|
218
187
|
|
|
219
|
-
Pull requests are welcome. For details on
|
|
188
|
+
Pull requests are welcome. For details on code of conduct, contribution process, and testing requirements, see the [Retold Contributing Guide](https://github.com/stevenvelozo/retold/blob/main/docs/contributing.md).
|
package/docs/README.md
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
# Meadow
|
|
2
2
|
|
|
3
|
-
> A data access
|
|
3
|
+
> A data access library providing magic where you want it, programmability where you don't
|
|
4
4
|
|
|
5
|
-
Meadow is a JavaScript data broker that handles repetitive CRUD operations through a consistent, provider-agnostic interface. It
|
|
5
|
+
Meadow is a JavaScript data broker that handles repetitive CRUD operations through a consistent, provider-agnostic interface. It abstracts database communication behind a unified API -- whether your data lives in MySQL, MSSQL, PostgreSQL, SQLite, MongoDB, RocksDB, or an in-browser ALASQL store, Meadow provides schema management, query generation, data marshalling, and automatic audit stamping while you focus on business logic.
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
|
-
- **Provider-Agnostic Design**
|
|
10
|
-
- **Schema-Driven**
|
|
11
|
-
- **FoxHound Query DSL**
|
|
12
|
-
- **Automatic Audit Tracking**
|
|
13
|
-
- **Soft Deletes**
|
|
14
|
-
- **GUID Uniqueness**
|
|
15
|
-
- **Raw Query Overrides**
|
|
16
|
-
- **
|
|
9
|
+
- **Provider-Agnostic Design** -- pluggable database backends through a consistent CRUD interface
|
|
10
|
+
- **Schema-Driven** -- define your data model once and get validation, default objects, and audit tracking for free
|
|
11
|
+
- **FoxHound Query DSL** -- fluent query builder that generates dialect-specific SQL, MongoDB queries, or key-value lookups
|
|
12
|
+
- **Automatic Audit Tracking** -- auto-populated create, update, and delete timestamps with user identity stamps
|
|
13
|
+
- **Soft Deletes** -- built-in logical deletion with automatic query filtering and undelete support
|
|
14
|
+
- **GUID Uniqueness** -- automatic GUID generation and uniqueness enforcement on record creation
|
|
15
|
+
- **Raw Query Overrides** -- escape hatch for custom SQL when the DSL is not enough
|
|
16
|
+
- **Role-Based Authorization** -- declarative access control per operation integrated with Meadow-Endpoints
|
|
17
|
+
- **Fable Integration** -- first-class service in the Fable ecosystem with logging, configuration, and dependency injection
|
|
18
|
+
- **Browser Support** -- ALASQL provider enables the same data access patterns in the browser via IndexedDB
|
|
17
19
|
|
|
18
|
-
##
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install meadow
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick Example
|
|
19
27
|
|
|
20
28
|
```javascript
|
|
21
29
|
const libFable = require('fable').new();
|
|
22
30
|
const libMeadow = require('meadow');
|
|
23
31
|
|
|
24
|
-
// Create a Meadow DAL for the "Book" entity
|
|
25
32
|
const meadow = libMeadow.new(libFable, 'Book')
|
|
26
33
|
.setProvider('MySQL')
|
|
27
34
|
.setDefaultIdentifier('IDBook')
|
|
@@ -39,64 +46,21 @@ const meadow = libMeadow.new(libFable, 'Book')
|
|
|
39
46
|
{ Column: 'Deleted', Type: 'Deleted' }
|
|
40
47
|
]);
|
|
41
48
|
|
|
42
|
-
//
|
|
43
|
-
meadow.
|
|
44
|
-
(pError, pQuery, pBook) =>
|
|
45
|
-
{
|
|
46
|
-
if (pError)
|
|
47
|
-
{
|
|
48
|
-
return console.log('Error reading book:', pError);
|
|
49
|
-
}
|
|
50
|
-
console.log('Found:', pBook.Title, 'by', pBook.Author);
|
|
51
|
-
});
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Installation
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
npm install meadow
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
## How It Works
|
|
61
|
-
|
|
62
|
-
Meadow follows the Fable service provider pattern. You create a DAL instance for each entity in your data model, configure its schema and provider, then use the CRUD methods to interact with your database. Meadow handles query generation, data marshalling, schema validation, and audit stamping automatically.
|
|
63
|
-
|
|
64
|
-
```
|
|
65
|
-
Fable (Core)
|
|
66
|
-
└── Meadow (Data Access Layer)
|
|
67
|
-
├── Schema (Column definitions, validation, defaults)
|
|
68
|
-
├── FoxHound Query DSL (Dialect-specific SQL generation)
|
|
69
|
-
├── Behaviors (Create, Read, Reads, Update, Delete, Count, Undelete)
|
|
70
|
-
└── Provider (MySQL, MSSQL, SQLite, ALASQL, MeadowEndpoints, None)
|
|
71
|
-
└── Database Connection
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## CRUD Operations
|
|
75
|
-
|
|
76
|
-
All operations follow an async waterfall pattern with a consistent callback signature.
|
|
77
|
-
|
|
78
|
-
### Create
|
|
79
|
-
|
|
80
|
-
```javascript
|
|
81
|
-
const tmpQuery = meadow.query.addRecord({ Title: 'Dune', Author: 'Frank Herbert' });
|
|
82
|
-
meadow.doCreate(tmpQuery,
|
|
49
|
+
// Create
|
|
50
|
+
meadow.doCreate(meadow.query.addRecord({ Title: 'Dune', Author: 'Frank Herbert' }),
|
|
83
51
|
(pError, pCreateQuery, pReadQuery, pRecord) =>
|
|
84
52
|
{
|
|
85
|
-
console.log('Created
|
|
53
|
+
console.log('Created:', pRecord.IDBook, '-', pRecord.Title);
|
|
86
54
|
});
|
|
87
|
-
```
|
|
88
55
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
```javascript
|
|
92
|
-
// Single record
|
|
56
|
+
// Read
|
|
93
57
|
meadow.doRead(meadow.query.addFilter('IDBook', 1),
|
|
94
58
|
(pError, pQuery, pRecord) =>
|
|
95
59
|
{
|
|
96
|
-
console.log('
|
|
60
|
+
console.log('Found:', pRecord.Title);
|
|
97
61
|
});
|
|
98
62
|
|
|
99
|
-
//
|
|
63
|
+
// Read multiple with pagination
|
|
100
64
|
meadow.doReads(meadow.query.setCap(25).setBegin(0),
|
|
101
65
|
(pError, pQuery, pRecords) =>
|
|
102
66
|
{
|
|
@@ -104,173 +68,13 @@ meadow.doReads(meadow.query.setCap(25).setBegin(0),
|
|
|
104
68
|
});
|
|
105
69
|
```
|
|
106
70
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
```javascript
|
|
110
|
-
const tmpQuery = meadow.query
|
|
111
|
-
.addFilter('IDBook', 1)
|
|
112
|
-
.addRecord({ Title: 'Updated Title' });
|
|
113
|
-
meadow.doUpdate(tmpQuery,
|
|
114
|
-
(pError, pUpdateQuery, pReadQuery, pRecord) =>
|
|
115
|
-
{
|
|
116
|
-
console.log('Updated:', pRecord.Title);
|
|
117
|
-
});
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
### Delete
|
|
121
|
-
|
|
122
|
-
```javascript
|
|
123
|
-
meadow.doDelete(meadow.query.addFilter('IDBook', 1),
|
|
124
|
-
(pError, pQuery, pResult) =>
|
|
125
|
-
{
|
|
126
|
-
console.log('Deleted:', pResult, 'record(s)');
|
|
127
|
-
});
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### Count
|
|
131
|
-
|
|
132
|
-
```javascript
|
|
133
|
-
meadow.doCount(meadow.query,
|
|
134
|
-
(pError, pQuery, pCount) =>
|
|
135
|
-
{
|
|
136
|
-
console.log('Total books:', pCount);
|
|
137
|
-
});
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
## Schema
|
|
141
|
-
|
|
142
|
-
Meadow schemas define your data model with special column types that enable automatic behavior.
|
|
143
|
-
|
|
144
|
-
### Column Types
|
|
145
|
-
|
|
146
|
-
| Type | Description |
|
|
147
|
-
|------|-------------|
|
|
148
|
-
| `AutoIdentity` | Auto-increment primary key |
|
|
149
|
-
| `AutoGUID` | Automatically generated GUID |
|
|
150
|
-
| `CreateDate` | Auto-populated timestamp on create |
|
|
151
|
-
| `CreateIDUser` | Auto-populated user ID on create |
|
|
152
|
-
| `UpdateDate` | Auto-populated timestamp on update |
|
|
153
|
-
| `UpdateIDUser` | Auto-populated user ID on update |
|
|
154
|
-
| `DeleteDate` | Auto-populated timestamp on delete |
|
|
155
|
-
| `DeleteIDUser` | Auto-populated user ID on delete |
|
|
156
|
-
| `Deleted` | Soft delete flag (enables logical deletion) |
|
|
157
|
-
| `String` | String field with optional `Size` |
|
|
158
|
-
| `Text` | Long text field |
|
|
159
|
-
| `Numeric` | Integer field |
|
|
160
|
-
| `Decimal` | Decimal field with `Size` as `"precision,scale"` |
|
|
161
|
-
| `Boolean` | Boolean field |
|
|
162
|
-
| `DateTime` | Date/time field |
|
|
163
|
-
|
|
164
|
-
### JSON Schema Validation
|
|
165
|
-
|
|
166
|
-
Meadow also supports JSON Schema (v4) for object validation:
|
|
167
|
-
|
|
168
|
-
```javascript
|
|
169
|
-
meadow.setJsonSchema({
|
|
170
|
-
title: 'Book',
|
|
171
|
-
type: 'object',
|
|
172
|
-
properties:
|
|
173
|
-
{
|
|
174
|
-
IDBook: { type: 'integer' },
|
|
175
|
-
Title: { type: 'string' },
|
|
176
|
-
Author: { type: 'string' }
|
|
177
|
-
},
|
|
178
|
-
required: ['Title']
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
const result = meadow.schemaFull.validateObject({ Title: 'Dune' });
|
|
182
|
-
// { Valid: true, Errors: [] }
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
## Configuration
|
|
186
|
-
|
|
187
|
-
Meadow reads database configuration from the Fable settings object:
|
|
188
|
-
|
|
189
|
-
```json
|
|
190
|
-
{
|
|
191
|
-
"Product": "MyApp",
|
|
192
|
-
"ProductVersion": "1.0.0",
|
|
193
|
-
"MySQL": {
|
|
194
|
-
"Server": "localhost",
|
|
195
|
-
"Port": 3306,
|
|
196
|
-
"User": "root",
|
|
197
|
-
"Password": "",
|
|
198
|
-
"Database": "myapp",
|
|
199
|
-
"ConnectionPoolLimit": 20
|
|
200
|
-
},
|
|
201
|
-
"QueryThresholdWarnTime": 200
|
|
202
|
-
}
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
| Setting | Type | Default | Description |
|
|
206
|
-
|---------|------|---------|-------------|
|
|
207
|
-
| `MySQL` | object | - | MySQL connection settings |
|
|
208
|
-
| `QueryThresholdWarnTime` | number | `200` | Slow query warning threshold (ms) |
|
|
209
|
-
| `MeadowProvider` | string | - | Default provider name |
|
|
210
|
-
| `MeadowRoleNames` | array | `['Unauthenticated', 'User', 'Manager', 'Director', 'Executive', 'Administrator']` | Role name mapping |
|
|
211
|
-
|
|
212
|
-
## Providers
|
|
213
|
-
|
|
214
|
-
Meadow supports multiple database backends through its provider system.
|
|
215
|
-
|
|
216
|
-
| Provider | Description | Connection |
|
|
217
|
-
|----------|-------------|------------|
|
|
218
|
-
| `MySQL` | MySQL/MariaDB via mysql2 | `fable.MeadowMySQLConnectionPool` or `fable.MeadowMySQLProvider` |
|
|
219
|
-
| `MSSQL` | Microsoft SQL Server | `fable.MeadowMSSQLProvider` |
|
|
220
|
-
| `SQLite` | SQLite database | Via meadow-connection-sqlite |
|
|
221
|
-
| `ALASQL` | In-browser IndexedDB | `fable.ALASQL` |
|
|
222
|
-
| `MeadowEndpoints` | REST proxy to remote Meadow API | Via `MeadowEndpoints` settings |
|
|
223
|
-
| `None` | Null provider for testing | No connection required |
|
|
224
|
-
|
|
225
|
-
## Raw Query Overrides
|
|
226
|
-
|
|
227
|
-
For complex queries that exceed the DSL capabilities:
|
|
228
|
-
|
|
229
|
-
```javascript
|
|
230
|
-
// Set a custom query for Read operations
|
|
231
|
-
meadow.rawQueries.setQuery('Read',
|
|
232
|
-
'SELECT b.*, a.Name AS AuthorName FROM Book b JOIN Author a ON b.IDAuthor = a.IDAuthor WHERE b.IDBook = :IDBook');
|
|
233
|
-
|
|
234
|
-
// Load from file
|
|
235
|
-
meadow.rawQueries.loadQuery('CustomReport', './queries/book-report.sql');
|
|
236
|
-
|
|
237
|
-
// Check and use
|
|
238
|
-
if (meadow.rawQueries.checkQuery('CustomReport'))
|
|
239
|
-
{
|
|
240
|
-
const sql = meadow.rawQueries.getQuery('CustomReport');
|
|
241
|
-
}
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
## Testing
|
|
245
|
-
|
|
246
|
-
```bash
|
|
247
|
-
npm test
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
## Documentation
|
|
251
|
-
|
|
252
|
-
- [Architecture](architecture.md) - System architecture and design patterns
|
|
253
|
-
- [Schema](schema/README.md) - Column definitions, JSON Schema validation, default objects, authorization
|
|
254
|
-
- [Query DSL](query-dsl.md) - FoxHound query building
|
|
255
|
-
- [Query Operations](query/README.md) - Query object overview and CRUD operations
|
|
256
|
-
- [Create](query/create.md) - Insert new records
|
|
257
|
-
- [Read](query/read.md) - Retrieve single and multiple records
|
|
258
|
-
- [Update](query/update.md) - Modify existing records
|
|
259
|
-
- [Delete](query/delete.md) - Soft delete and undelete records
|
|
260
|
-
- [Count](query/count.md) - Count records matching criteria
|
|
261
|
-
- [Providers](providers/README.md) - Database provider system
|
|
262
|
-
- [MySQL](providers/mysql.md) - Connection pooling, named placeholders
|
|
263
|
-
- [MSSQL](providers/mssql.md) - Prepared statements, type mapping
|
|
264
|
-
- [SQLite](providers/sqlite.md) - Embedded database
|
|
265
|
-
- [ALASQL](providers/alasql.md) - In-memory SQL, browser support
|
|
266
|
-
|
|
267
|
-
## Related Packages
|
|
71
|
+
## Learn More
|
|
268
72
|
|
|
269
|
-
- [
|
|
270
|
-
- [
|
|
271
|
-
- [
|
|
272
|
-
- [
|
|
273
|
-
- [
|
|
274
|
-
- [
|
|
275
|
-
- [
|
|
276
|
-
- [
|
|
73
|
+
- [Quick Start](quick-start.md) -- setup and first operations
|
|
74
|
+
- [Architecture](architecture.md) -- how the service is structured
|
|
75
|
+
- [Schema](schema/README.md) -- column definitions, validation, default objects, authorization
|
|
76
|
+
- [Query DSL](query-dsl.md) -- FoxHound query building
|
|
77
|
+
- [CRUD Operations](query/README.md) -- detailed guides for each operation
|
|
78
|
+
- [Providers](providers/README.md) -- database provider system
|
|
79
|
+
- [Configuration](configuration.md) -- settings reference
|
|
80
|
+
- [API Reference](api/reference.md) -- full method documentation
|
package/docs/_cover.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Meadow <small>v2.0.23</small>
|
|
2
|
+
|
|
3
|
+
> A data access library providing magic where you want it, programmability where you don't
|
|
4
|
+
|
|
5
|
+
- Provider-agnostic CRUD operations across MySQL, MSSQL, PostgreSQL, SQLite, MongoDB, RocksDB, and ALASQL
|
|
6
|
+
- Schema-driven data model with automatic audit tracking and soft deletes
|
|
7
|
+
- FoxHound query DSL for dialect-specific SQL generation
|
|
8
|
+
- Role-based authorization integrated with Meadow-Endpoints
|
|
9
|
+
- Raw query overrides for complex operations beyond the DSL
|
|
10
|
+
- First-class Fable ecosystem integration with logging and configuration
|
|
11
|
+
|
|
12
|
+
[Get Started](quick-start.md)
|
|
13
|
+
[API Reference](api/reference.md)
|
|
14
|
+
[GitHub](https://github.com/stevenvelozo/meadow)
|