retold-data-service 2.0.9 → 2.0.11
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/CONTRIBUTING.md +50 -0
- package/README.md +200 -56
- package/docs/.nojekyll +0 -0
- package/docs/README.md +76 -0
- package/docs/_sidebar.md +13 -0
- package/docs/architecture.md +94 -0
- package/docs/behavior-injection.md +111 -0
- package/docs/configuration.md +93 -0
- package/docs/cover.md +11 -0
- package/docs/dal-access.md +87 -0
- package/docs/endpoints.md +121 -0
- package/docs/index.html +39 -0
- package/docs/initialization.md +77 -0
- package/docs/lifecycle-hooks.md +81 -0
- package/docs/schema-definition.md +128 -0
- package/docs/storage-providers.md +109 -0
- package/package.json +10 -6
- package/source/Retold-Data-Service.js +4 -4
- package/test/RetoldDataService_tests.js +1315 -18
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Storage Providers
|
|
2
|
+
|
|
3
|
+
Retold Data Service supports any Meadow-compatible storage provider. The provider is configured through the `StorageProvider` and `StorageProviderModule` options.
|
|
4
|
+
|
|
5
|
+
## Available Providers
|
|
6
|
+
|
|
7
|
+
| Provider | Module | Best For |
|
|
8
|
+
|----------|--------|----------|
|
|
9
|
+
| MySQL | `meadow-connection-mysql` | Production web applications |
|
|
10
|
+
| SQLite | `meadow-connection-sqlite` | Embedded apps, testing, single-server deployments |
|
|
11
|
+
| MSSQL | `meadow-connection-mssql` | Enterprise SQL Server environments |
|
|
12
|
+
| ALASQL | Built into Meadow | In-memory / browser-side usage |
|
|
13
|
+
|
|
14
|
+
## MySQL Setup
|
|
15
|
+
|
|
16
|
+
MySQL is the default provider.
|
|
17
|
+
|
|
18
|
+
```javascript
|
|
19
|
+
const settings = {
|
|
20
|
+
APIServerPort: 8086,
|
|
21
|
+
MySQL: {
|
|
22
|
+
Server: '127.0.0.1',
|
|
23
|
+
Port: 3306,
|
|
24
|
+
User: 'root',
|
|
25
|
+
Password: 'secret',
|
|
26
|
+
Database: 'mydb',
|
|
27
|
+
ConnectionPoolLimit: 20
|
|
28
|
+
},
|
|
29
|
+
MeadowConnectionMySQLAutoConnect: true
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const _Fable = new libFable(settings);
|
|
33
|
+
|
|
34
|
+
_Fable.serviceManager.instantiateServiceProvider('RetoldDataService', {
|
|
35
|
+
StorageProvider: 'MySQL',
|
|
36
|
+
StorageProviderModule: 'meadow-connection-mysql',
|
|
37
|
+
FullMeadowSchemaPath: `${__dirname}/model/`,
|
|
38
|
+
FullMeadowSchemaFilename: 'MeadowModel-Extended.json'
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## SQLite Setup
|
|
43
|
+
|
|
44
|
+
SQLite requires pre-registering the connection provider before creating the data service:
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
const libMeadowConnectionSQLite = require('meadow-connection-sqlite');
|
|
48
|
+
|
|
49
|
+
const settings = {
|
|
50
|
+
APIServerPort: 8086,
|
|
51
|
+
SQLite: { SQLiteFilePath: './data/app.db' }
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const _Fable = new libFable(settings);
|
|
55
|
+
|
|
56
|
+
// Register and connect SQLite before creating the data service
|
|
57
|
+
_Fable.serviceManager.addServiceType('MeadowSQLiteProvider', libMeadowConnectionSQLite);
|
|
58
|
+
_Fable.serviceManager.instantiateServiceProvider('MeadowSQLiteProvider');
|
|
59
|
+
|
|
60
|
+
_Fable.MeadowSQLiteProvider.connectAsync(
|
|
61
|
+
(pError) =>
|
|
62
|
+
{
|
|
63
|
+
_Fable.serviceManager.instantiateServiceProvider('RetoldDataService', {
|
|
64
|
+
StorageProvider: 'SQLite',
|
|
65
|
+
StorageProviderModule: 'meadow-connection-sqlite',
|
|
66
|
+
FullMeadowSchemaPath: `${__dirname}/model/`,
|
|
67
|
+
FullMeadowSchemaFilename: 'MeadowModel-Extended.json'
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
_Fable.RetoldDataService.initializeService(callback);
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
For in-memory testing, use `':memory:'` as the SQLite file path:
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
SQLite: { SQLiteFilePath: ':memory:' }
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## MSSQL Setup
|
|
81
|
+
|
|
82
|
+
```javascript
|
|
83
|
+
const settings = {
|
|
84
|
+
APIServerPort: 8086,
|
|
85
|
+
MSSQL: {
|
|
86
|
+
Server: '127.0.0.1',
|
|
87
|
+
Port: 1433,
|
|
88
|
+
User: 'sa',
|
|
89
|
+
Password: 'YourPassword123',
|
|
90
|
+
Database: 'mydb'
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
_Fable.serviceManager.instantiateServiceProvider('RetoldDataService', {
|
|
95
|
+
StorageProvider: 'MSSQL',
|
|
96
|
+
StorageProviderModule: 'meadow-connection-mssql',
|
|
97
|
+
FullMeadowSchemaPath: `${__dirname}/model/`,
|
|
98
|
+
FullMeadowSchemaFilename: 'MeadowModel-Extended.json'
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Changing the Provider at Runtime
|
|
103
|
+
|
|
104
|
+
After initialization, each entity's provider can be changed individually:
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
_Fable.DAL.Book.setProvider('MySQL');
|
|
108
|
+
_Fable.DAL.Author.setProvider('SQLite');
|
|
109
|
+
```
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "retold-data-service",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11",
|
|
4
4
|
"description": "Serve up a whole model!",
|
|
5
5
|
"main": "source/Retold-Data-Service.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"start": "node source/Retold-Data-Service.js",
|
|
8
|
-
"coverage": "
|
|
9
|
-
"test": "
|
|
8
|
+
"coverage": "npx nyc --reporter=lcov --reporter=text-lcov npx mocha -- -u tdd -R spec",
|
|
9
|
+
"test": "npx mocha -u tdd -R spec",
|
|
10
10
|
"build": "npx quack build",
|
|
11
11
|
"build-test-model": "cd test && npx stricture -i model/ddl/BookStore.ddl",
|
|
12
12
|
"docker-dev-build": "docker build ./ -f Dockerfile_LUXURYCode -t retold-data-service-image:local",
|
|
@@ -51,15 +51,19 @@
|
|
|
51
51
|
},
|
|
52
52
|
"homepage": "https://github.com/stevenvelozo/retold-data-service",
|
|
53
53
|
"devDependencies": {
|
|
54
|
+
"chai": "^6.2.2",
|
|
55
|
+
"meadow-connection-sqlite": "^1.0.11",
|
|
56
|
+
"mocha": "^11.7.5",
|
|
54
57
|
"quackage": "^1.0.41",
|
|
55
|
-
"stricture": "^1.0.37"
|
|
58
|
+
"stricture": "^1.0.37",
|
|
59
|
+
"supertest": "^7.2.2"
|
|
56
60
|
},
|
|
57
61
|
"dependencies": {
|
|
58
62
|
"fable": "^3.1.11",
|
|
59
63
|
"fable-serviceproviderbase": "^3.0.15",
|
|
60
|
-
"meadow": "^2.0.
|
|
64
|
+
"meadow": "^2.0.21",
|
|
61
65
|
"meadow-connection-mysql": "^1.0.4",
|
|
62
|
-
"meadow-endpoints": "^4.0.
|
|
66
|
+
"meadow-endpoints": "^4.0.7",
|
|
63
67
|
"orator": "^5.0.1",
|
|
64
68
|
"orator-http-proxy": "^1.0.1",
|
|
65
69
|
"orator-serviceserver-restify": "^2.0.4",
|
|
@@ -118,11 +118,11 @@ class RetoldDataService extends libFableServiceProviderBase
|
|
|
118
118
|
//let tmpDALPackageFile = `${this.options.DALMeadowSchemaPath}${this.options.DALMeadowSchemaPrefix}${tmpDALEntityName}${this.options.DALMeadowSchemaPostfix}.json`
|
|
119
119
|
//this.fable.log.info(`Initializing the ${tmpDALEntityName} DAL from [${tmpDALPackageFile}]...`);
|
|
120
120
|
this._DAL[tmpDALEntityName] = this._Meadow.loadFromPackageObject(tmpDALMeadowSchema);
|
|
121
|
-
// 5. Tell this DAL object to use
|
|
122
|
-
this.fable.log.info(`...defaulting the ${tmpDALEntityName} DAL to use
|
|
123
|
-
this._DAL[tmpDALEntityName].setProvider(
|
|
121
|
+
// 5. Tell this DAL object to use the configured storage provider
|
|
122
|
+
this.fable.log.info(`...defaulting the ${tmpDALEntityName} DAL to use ${this.options.StorageProvider}`);
|
|
123
|
+
this._DAL[tmpDALEntityName].setProvider(this.options.StorageProvider);
|
|
124
124
|
// 6. Create a Meadow Endpoints class for this DAL
|
|
125
|
-
this.fable.log.info(`...initializing the ${tmpDALEntityName} Meadow Endpoints
|
|
125
|
+
this.fable.log.info(`...initializing the ${tmpDALEntityName} Meadow Endpoints`);
|
|
126
126
|
this._MeadowEndpoints[tmpDALEntityName] = libMeadowEndpoints.new(this._DAL[tmpDALEntityName]);
|
|
127
127
|
// 8. Expose the meadow endpoints on Orator
|
|
128
128
|
this.fable.log.info(`...mapping the ${tmpDALEntityName} Meadow Endpoints to Orator`);
|