masterrecord 0.2.27 → 0.2.29
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/context.js +15 -1
- package/package.json +1 -1
- package/readme.md +6 -6
package/context.js
CHANGED
|
@@ -38,7 +38,7 @@ class context {
|
|
|
38
38
|
SQLite expected model
|
|
39
39
|
{
|
|
40
40
|
"type": "better-sqlite3",
|
|
41
|
-
"connection" : "/db/",
|
|
41
|
+
"connection" : "/db/mydb.sqlite", // or "/db/" (auto-creates <contextname>.sqlite)
|
|
42
42
|
"password": "",
|
|
43
43
|
"username": ""
|
|
44
44
|
}
|
|
@@ -177,6 +177,13 @@ class context {
|
|
|
177
177
|
dbPath = path.join(file.rootFolder, trimmed);
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
+
// If dbPath is a directory (ends with separator or exists as directory), append default filename
|
|
181
|
+
const endsWithSep = dbPath.endsWith('/') || dbPath.endsWith('\\');
|
|
182
|
+
const isDir = fs.existsSync(dbPath) && fs.statSync(dbPath).isDirectory();
|
|
183
|
+
if(endsWithSep || isDir){
|
|
184
|
+
const dbName = `${contextName.toLowerCase()}.sqlite`;
|
|
185
|
+
dbPath = path.join(dbPath, dbName);
|
|
186
|
+
}
|
|
180
187
|
const dbDir = path.dirname(dbPath);
|
|
181
188
|
if(!fs.existsSync(dbDir)){
|
|
182
189
|
fs.mkdirSync(dbDir, { recursive: true });
|
|
@@ -228,6 +235,13 @@ class context {
|
|
|
228
235
|
dbPath = path.join(file.rootFolder, trimmed);
|
|
229
236
|
}
|
|
230
237
|
}
|
|
238
|
+
// If dbPath is a directory (ends with separator or exists as directory), append default filename
|
|
239
|
+
const endsWithSep = dbPath.endsWith('/') || dbPath.endsWith('\\');
|
|
240
|
+
const isDir = fs.existsSync(dbPath) && fs.statSync(dbPath).isDirectory();
|
|
241
|
+
if(endsWithSep || isDir){
|
|
242
|
+
const dbName = `${contextName.toLowerCase()}.sqlite`;
|
|
243
|
+
dbPath = path.join(dbPath, dbName);
|
|
244
|
+
}
|
|
231
245
|
options.completeConnection = dbPath;
|
|
232
246
|
var dbDirectory = path.dirname(options.completeConnection);
|
|
233
247
|
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"app-root-path": "^3.1.0",
|
|
10
10
|
"better-sqlite3": "^12.4.1"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.2.
|
|
12
|
+
"version": "0.2.29",
|
|
13
13
|
"description": "An Object-relational mapping for the Master framework. Master Record connects classes to relational database tables to establish a database with almost zero-configuration ",
|
|
14
14
|
"homepage": "https://github.com/Tailor/MasterRecord#readme",
|
|
15
15
|
"repository": {
|
package/readme.md
CHANGED
|
@@ -12,13 +12,13 @@ MasterRecord is a lightweight, code-first ORM and migration tool for Node.js wit
|
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
# npm
|
|
15
|
-
npm install masterrecord
|
|
15
|
+
npm install -g masterrecord
|
|
16
16
|
|
|
17
17
|
# pnpm
|
|
18
|
-
pnpm add masterrecord
|
|
18
|
+
pnpm add -g masterrecord
|
|
19
19
|
|
|
20
20
|
# yarn
|
|
21
|
-
yarn add masterrecord
|
|
21
|
+
yarn global add masterrecord
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
## Quick Start
|
|
@@ -26,19 +26,19 @@ yarn add masterrecord
|
|
|
26
26
|
1) Create an environment config file (see Environment below), then enable migrations:
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
|
-
|
|
29
|
+
masterrecord enable-migrations AppContext
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
2) Make or change your entities, then create a migration file:
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
|
-
|
|
35
|
+
masterrecord add-migration Init AppContext
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
3) Apply the migration to your database:
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
master=development
|
|
41
|
+
master=development masterrecord update-database AppContext
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
### Enable migrations (one-time per Context)
|