json-fs-query 0.1.1 → 1.0.0
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 +41 -6
- package/browser/jsonFsQuery.js +28271 -0
- package/browser/jsonFsQuery.min.js +1 -0
- package/dist/data/introspect/policies/hasDependents.d.ts +13 -0
- package/dist/data/introspect/policies/hasDependents.js +52 -0
- package/dist/data/introspect/policies/hasDependents.min.js +1 -0
- package/dist/data/introspect/policies/keyGenerate.js +1 -1
- package/dist/data/introspect/policies/keyGenerate.min.js +1 -1
- package/dist/data/introspect/policies/keyUnique.d.ts +9 -1
- package/dist/data/introspect/policies/keyUnique.js +19 -9
- package/dist/data/introspect/policies/keyUnique.min.js +1 -1
- package/dist/data/queries/deleteEntity.js +33 -12
- package/dist/data/queries/deleteEntity.min.js +1 -1
- package/dist/data/queries/insertEntity.js +9 -7
- package/dist/data/queries/insertEntity.min.js +1 -1
- package/dist/data/queries/updateEntity.js +64 -38
- package/dist/data/queries/updateEntity.min.js +1 -1
- package/dist/data/utilities/computeKeyValue.d.ts +13 -0
- package/dist/data/utilities/computeKeyValue.js +26 -0
- package/dist/data/utilities/computeKeyValue.min.js +1 -0
- package/dist/data/utilities/config.d.ts +6 -0
- package/dist/data/utilities/config.js +7 -1
- package/dist/data/utilities/config.min.js +1 -1
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
Read and manage data with JSON files - a small query engine that treats a folder of JSON files as a database, with
|
|
4
4
|
a SQL-like query string (`read workouts where date = '2024-06-02'`) instead of a query builder API.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
The core engine (schema management, a full read/insert/update/delete query language, single- and multi-field key
|
|
7
|
+
support, and referential integrity) is implemented and tested. Still open, tracked for whenever they're actually
|
|
8
|
+
needed: multi-field *foreign* keys specifically (single-field ones work; composite primary/unique/index keys work
|
|
9
|
+
too), and CASCADE/SET NULL modes for referential integrity (deleting/updating a referenced record is RESTRICTed -
|
|
10
|
+
blocked outright - rather than cascading or nulling out the dependents; see `configure()` below to turn that
|
|
11
|
+
enforcement off entirely if it doesn't fit your workflow).
|
|
10
12
|
|
|
11
13
|
## Install
|
|
12
14
|
|
|
@@ -35,8 +37,41 @@ await query("delete workouts where date = '2024-06-02'")
|
|
|
35
37
|
await drop('workouts')
|
|
36
38
|
```
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
## Configuration
|
|
41
|
+
|
|
42
|
+
`configure()` sets where this package's data lives and how strictly it enforces foreign keys - call it once,
|
|
43
|
+
before anything else:
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
const { configure } = require('json-fs-query')
|
|
47
|
+
|
|
48
|
+
configure({
|
|
49
|
+
databasePath: 'database/', // where the JSON files live (default 'database/')
|
|
50
|
+
relativePath: '', // URL prefix prepended to databasePath when reading via fetch() in a browser
|
|
51
|
+
enforceForeignKeys: true // RESTRICT delete/update of a record other entities still reference (default true)
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Turning `enforceForeignKeys` off restores the pre-1.0 behavior (no referential integrity checks at all) - useful if
|
|
56
|
+
it doesn't fit a particular workflow, mirroring MySQL's own toggleable `foreign_key_checks`.
|
|
57
|
+
|
|
58
|
+
## In the browser
|
|
59
|
+
|
|
60
|
+
A pre-built bundle is included (`browser/jsonFsQuery.js`, `.min.js` - also served directly via
|
|
61
|
+
[unpkg](https://unpkg.com/json-fs-query) or [jsDelivr](https://cdn.jsdelivr.net/npm/json-fs-query)) and exposes the
|
|
62
|
+
same functions as a global:
|
|
63
|
+
|
|
64
|
+
```html
|
|
65
|
+
<script src="https://unpkg.com/json-fs-query"></script>
|
|
66
|
+
<script>
|
|
67
|
+
jsonFsQuery.configure({ databasePath: 'database/', relativePath: 'https://example.com/' })
|
|
68
|
+
jsonFsQuery.query("read workouts where date = '2024-06-02'").then(console.log)
|
|
69
|
+
</script>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Reads work in the browser via `fetch()` - `create`/`drop`, and any write through `query()` (`insert`/`update`/
|
|
73
|
+
`delete`), need real filesystem access and only work in Node. They're still present in the browser build (same
|
|
74
|
+
public API either way), but throw if actually called there, rather than being silently unavailable.
|
|
40
75
|
|
|
41
76
|
## Documentation
|
|
42
77
|
|