@kedem/okdb 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/LICENSE +57 -0
- package/README.md +344 -0
- package/banner.jpg +0 -0
- package/bin/okdb.js +2 -0
- package/docs/OKDB-ARCHITECTURE.md +1036 -0
- package/docs/auth-and-sync.md +558 -0
- package/docs/auth-permissions.md +143 -0
- package/docs/change-log.md +169 -0
- package/docs/data-model.md +174 -0
- package/docs/embeddings.md +338 -0
- package/docs/files.md +131 -0
- package/docs/fts.md +139 -0
- package/docs/functions.md +514 -0
- package/docs/getting-started.md +233 -0
- package/docs/http-api.md +705 -0
- package/docs/index.md +115 -0
- package/docs/indexes.md +207 -0
- package/docs/logging.md +116 -0
- package/docs/manifest.json +38 -0
- package/docs/migration.md +154 -0
- package/docs/pipelines.md +598 -0
- package/docs/plugins.md +144 -0
- package/docs/querying.md +204 -0
- package/docs/queue.md +637 -0
- package/docs/sync.md +156 -0
- package/docs/transactions.md +140 -0
- package/docs/ttl.md +375 -0
- package/okdb.js +1 -0
- package/package.json +26 -0
- package/public/admin-app.js +1 -0
- package/public/android-chrome-192x192.png +0 -0
- package/public/android-chrome-512x512.png +0 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/components/admin-route-host.ok.js +1 -0
- package/public/components/env-picker.ok.js +1 -0
- package/public/components/field-path-input.ok.js +1 -0
- package/public/components/field.html +6 -0
- package/public/components/geo-map.ok.js +1 -0
- package/public/components/ok-cron-input.ok.js +1 -0
- package/public/components/ok-dropzone.ok.js +1 -0
- package/public/components/ok-js-input.ok.js +1 -0
- package/public/components/ok-json-input.ok.js +1 -0
- package/public/components/ok-text-monaco-input.ok.js +1 -0
- package/public/components/theme-toggle.ok.js +1 -0
- package/public/favicon-16x16.png +0 -0
- package/public/favicon-32x32.png +0 -0
- package/public/favicon.ico +0 -0
- package/public/images/logo.png +0 -0
- package/public/images/logo.svg +333 -0
- package/public/index.html +6 -0
- package/public/layouts/_default.ok.html +1 -0
- package/public/layouts/okdb-cube.ok.html +1 -0
- package/public/login-app.js +1 -0
- package/public/login.html +1 -0
- package/public/modules/ok.js +1 -0
- package/public/sections/api/index.ok.html +1 -0
- package/public/sections/api/parts/api-endpoint.ok.js +1 -0
- package/public/sections/auth/index.ok.html +1 -0
- package/public/sections/auth/modals/create-token-modal.ok.js +1 -0
- package/public/sections/auth/modals/edit-token-modal.ok.js +1 -0
- package/public/sections/auth/modals/perm-info-popover.ok.js +1 -0
- package/public/sections/auth/parts/token-detail.ok.js +1 -0
- package/public/sections/auth/parts/token-list.ok.js +1 -0
- package/public/sections/db/index.ok.html +1 -0
- package/public/sections/db/modals/add-item-modal.ok.js +1 -0
- package/public/sections/db/modals/create-env-modal.ok.js +1 -0
- package/public/sections/db/modals/create-fts-modal.ok.js +1 -0
- package/public/sections/db/modals/create-index-modal.ok.js +1 -0
- package/public/sections/db/modals/create-pipeline-modal.ok.js +1 -0
- package/public/sections/db/modals/demo-env-modal.ok.js +1 -0
- package/public/sections/db/modals/remove-env-modal.ok.js +1 -0
- package/public/sections/db/modals/schema-edit-modal.ok.js +1 -0
- package/public/sections/db/parts/db-overview.ok.js +1 -0
- package/public/sections/db/parts/db-pipelines-panel.ok.js +1 -0
- package/public/sections/db/parts/edit-row.ok.js +1 -0
- package/public/sections/db/parts/tm-timeline.ok.js +1 -0
- package/public/sections/db/parts/type-changelog.ok.js +1 -0
- package/public/sections/db/parts/type-list.ok.js +1 -0
- package/public/sections/db/parts/type-pipelines-tab.ok.js +1 -0
- package/public/sections/db/parts/type-schema-tab.ok.js +1 -0
- package/public/sections/db/parts/type-viewer.ok.js +1 -0
- package/public/sections/db/parts/type-violations-tab.ok.js +1 -0
- package/public/sections/docs/index.ok.html +1 -0
- package/public/sections/embeddings/index.ok.html +1 -0
- package/public/sections/embeddings/modals/register-model-modal.ok.js +1 -0
- package/public/sections/embeddings/parts/embed-create-panel.ok.js +1 -0
- package/public/sections/embeddings/parts/embed-embedder-panel.ok.js +1 -0
- package/public/sections/embeddings/parts/embed-engine-declaration-editor.ok.js +1 -0
- package/public/sections/embeddings/parts/embed-engine-list.ok.js +1 -0
- package/public/sections/embeddings/parts/embed-indexer-panel.ok.js +1 -0
- package/public/sections/embeddings/parts/embed-lifecycle-bar.ok.js +1 -0
- package/public/sections/embeddings/parts/embed-model-catalog.ok.js +1 -0
- package/public/sections/embeddings/parts/embed-overview.ok.js +1 -0
- package/public/sections/embeddings/parts/embed-search-panel.ok.js +1 -0
- package/public/sections/embeddings/parts/embed-worker-panel.ok.js +1 -0
- package/public/sections/embeddings/parts/embeddings-engine-panel.ok.js +1 -0
- package/public/sections/embeddings/parts/engines-overview.ok.js +1 -0
- package/public/sections/embeddings/parts/pipeline-create-panel.ok.js +1 -0
- package/public/sections/engines/engine-panel-shared-style.js +1 -0
- package/public/sections/engines/engine-ui-utils.js +1 -0
- package/public/sections/engines/index.ok.html +1 -0
- package/public/sections/engines/modals/engine-modal.ok.js +1 -0
- package/public/sections/engines/parts/engine-declaration-editor.ok.js +1 -0
- package/public/sections/engines/parts/engine-lifecycle-actions.ok.js +1 -0
- package/public/sections/engines/parts/engine-panel-shell.ok.js +1 -0
- package/public/sections/engines/parts/engine-resource-card.ok.js +1 -0
- package/public/sections/engines/parts/engine-row-item.ok.js +1 -0
- package/public/sections/engines/parts/generic-engine-panel.ok.js +1 -0
- package/public/sections/files/index.ok.html +1 -0
- package/public/sections/files/parts/files-blob-status.ok.js +1 -0
- package/public/sections/files/parts/files-collection-list.ok.js +1 -0
- package/public/sections/files/parts/files-collection-panel.ok.js +1 -0
- package/public/sections/files/parts/files-file-list.ok.js +1 -0
- package/public/sections/files/parts/files-overview.ok.js +1 -0
- package/public/sections/files/parts/files-path-browser.ok.js +1 -0
- package/public/sections/files/parts/files-upload-panel.ok.js +1 -0
- package/public/sections/functions/index.ok.html +1 -0
- package/public/sections/functions/modals/function-modal.ok.js +1 -0
- package/public/sections/functions/parts/function-detail.ok.js +1 -0
- package/public/sections/functions/parts/function-logs.ok.js +1 -0
- package/public/sections/functions/parts/function-runner.ok.js +1 -0
- package/public/sections/functions/parts/functions-list.ok.js +1 -0
- package/public/sections/license/index.ok.html +1 -0
- package/public/sections/license/parts/license-panel.ok.js +1 -0
- package/public/sections/processors/index.ok.html +1 -0
- package/public/sections/queue/index.ok.html +1 -0
- package/public/sections/queue/modals/create-bucket-modal.ok.js +1 -0
- package/public/sections/queue/modals/edit-bucket-modal.ok.js +1 -0
- package/public/sections/queue/modals/edit-job-modal.ok.js +1 -0
- package/public/sections/queue/modals/enqueue-job-modal.ok.js +1 -0
- package/public/sections/queue/modals/job-type-modal.ok.js +1 -0
- package/public/sections/queue/parts/ok-job-form.ok.js +1 -0
- package/public/sections/queue/parts/queue-buckets.ok.js +1 -0
- package/public/sections/queue/parts/queue-job-types.ok.js +1 -0
- package/public/sections/queue/parts/queue-jobs.ok.js +1 -0
- package/public/sections/queue/parts/queue-types.ok.js +1 -0
- package/public/sections/queue/parts/queue-workers.ok.js +1 -0
- package/public/sections/sync/index.ok.html +5 -0
- package/public/sections/sync/parts/sync-node-detail.ok.js +1 -0
- package/public/sections/sync/parts/sync-retention.ok.js +1 -0
- package/public/sections/sync/parts/sync-topology.ok.js +1 -0
- package/public/sections/system/index.ok.html +1 -0
- package/public/sections/system/modals/data-ops-modal.ok.js +1 -0
- package/public/sections/system/parts/system-api-panel.ok.js +1 -0
- package/public/sections/system/parts/system-auth-panel.ok.js +1 -0
- package/public/sections/system/parts/system-log-history.ok.js +1 -0
- package/public/sections/system/parts/system-log.ok.js +1 -0
- package/public/sections/system/parts/system-status.ok.js +1 -0
- package/public/sections/system/parts/system-sync-panel.ok.js +1 -0
- package/public/sections/views/index.ok.html +1 -0
- package/public/sections/views/modals/create-view-modal.ok.js +1 -0
- package/public/sections/views/parts/view-detail.ok.js +1 -0
- package/public/sections/views/parts/views-list.ok.js +1 -0
- package/public/sections/views/parts/views-overview.ok.js +1 -0
- package/public/setup-app.js +1 -0
- package/public/setup.html +1 -0
- package/public/site.webmanifest +1 -0
- package/public/stores/auth-store.js +1 -0
- package/public/stores/events-store.js +1 -0
- package/public/stores/functions-store.js +1 -0
- package/public/stores/okdb-store.js +1 -0
- package/public/stores/theme-store.js +1 -0
- package/public/styles.css +1 -0
- package/public/test-cron-input.html +10 -0
- package/public/test-json-input.html +101 -0
- package/public/util/permissions.js +1 -0
- package/public/util/sift-schema.js +1 -0
- package/public/vendor/okjs/ok.esm.min.js +2 -0
- package/public/vendor/okjs/toolkit/behavior/async.ok.js +1 -0
- package/public/vendor/okjs/toolkit/components/ok-chart.ok.js +1 -0
- package/public/vendor/okjs/toolkit/components/ok-doc-viewer.ok.js +1 -0
- package/public/vendor/okjs/toolkit/components/ok-marked.ok.js +1 -0
- package/public/vendor/okjs/toolkit/components/ok-monaco.ok.js +1 -0
- package/public/vendor/okjs/toolkit/core/ok-layer-service.ok.js +1 -0
- package/public/vendor/okjs/toolkit/core/ok-layer.ok.js +1 -0
- package/public/vendor/okjs/toolkit/core/ok-overlay.ok.js +1 -0
- package/public/vendor/okjs/toolkit/core/ok-sandbox.ok.js +1 -0
- package/public/vendor/okjs/toolkit/core/transition.ok.js +1 -0
- package/public/vendor/okjs/toolkit/core/virtualized.ok.js +1 -0
- package/public/vendor/okjs/toolkit/devtools/ok-console-service.ok.js +1 -0
- package/public/vendor/okjs/toolkit/devtools/ok-console.ok.js +1 -0
- package/public/vendor/okjs/toolkit/devtools/ok-fps-monitor-service.ok.js +1 -0
- package/public/vendor/okjs/toolkit/devtools/ok-fps-monitor.ok.js +1 -0
- package/public/vendor/okjs/toolkit/devtools/ok-inspector-service.ok.js +1 -0
- package/public/vendor/okjs/toolkit/devtools/ok-inspector.ok.js +1 -0
- package/public/vendor/okjs/toolkit/devtools/ok-js-tree.ok.js +1 -0
- package/public/vendor/okjs/toolkit/devtools/ok-timeline-service.ok.js +1 -0
- package/public/vendor/okjs/toolkit/devtools/ok-timeline.ok.js +1 -0
- package/public/vendor/okjs/toolkit/docs/doc-viewer.ok.js +1 -0
- package/public/vendor/okjs/toolkit/editor/ok-live-component.ok.js +1 -0
- package/public/vendor/okjs/toolkit/editor/ok-live-example.ok.js +1 -0
- package/public/vendor/okjs/toolkit/editor/ok-live-shell.ok.js +1 -0
- package/public/vendor/okjs/toolkit/elements/ok-dropdown.ok.js +1 -0
- package/public/vendor/okjs/toolkit/elements/ok-icon.ok.js +1 -0
- package/public/vendor/okjs/toolkit/elements/ok-select.ok.js +1 -0
- package/public/vendor/okjs/toolkit/elements/ok-table.ok.js +1 -0
- package/public/vendor/okjs/toolkit/errors/ok-crash-boundary.ok.js +1 -0
- package/public/vendor/okjs/toolkit/errors/ok-crash-info.ok.js +1 -0
- package/public/vendor/okjs/toolkit/i18n/i18n-editor-examples.ok.js +1 -0
- package/public/vendor/okjs/toolkit/i18n/i18n-editor.ok.js +1 -0
- package/public/vendor/okjs/toolkit/i18n/i18n-key-editor-tips.ok.js +1 -0
- package/public/vendor/okjs/toolkit/i18n/i18n-key-editor.ok.js +1 -0
- package/public/vendor/okjs/toolkit/i18n/i18n-service.ok.js +1 -0
- package/public/vendor/okjs/toolkit/i18n/ok-i18n.js +1 -0
- package/public/vendor/okjs/toolkit/interaction/ok-contextmenu.ok.js +1 -0
- package/public/vendor/okjs/toolkit/interaction/ok-dismiss-service.ok.js +1 -0
- package/public/vendor/okjs/toolkit/interaction/ok-draggable.ok.js +1 -0
- package/public/vendor/okjs/toolkit/interaction/ok-flyover-panel.ok.js +1 -0
- package/public/vendor/okjs/toolkit/interaction/ok-flyover.ok.js +1 -0
- package/public/vendor/okjs/toolkit/interaction/ok-highlight-service.ok.js +1 -0
- package/public/vendor/okjs/toolkit/interaction/ok-highlight.ok.js +1 -0
- package/public/vendor/okjs/toolkit/interaction/ok-hotkeys-service.ok.js +1 -0
- package/public/vendor/okjs/toolkit/interaction/ok-picker-service.ok.js +1 -0
- package/public/vendor/okjs/toolkit/interaction/ok-popout-service.ok.js +1 -0
- package/public/vendor/okjs/toolkit/interaction/ok-popout.ok.js +1 -0
- package/public/vendor/okjs/toolkit/interaction/ok-portal-service.ok.js +1 -0
- package/public/vendor/okjs/toolkit/interaction/ok-submenu.ok.js +1 -0
- package/public/vendor/okjs/toolkit/layout/ok-resizer.ok.js +1 -0
- package/public/vendor/okjs/toolkit/manifest.js +1 -0
- package/public/vendor/okjs/toolkit/modals/ok-modal-service.ok.js +1 -0
- package/public/vendor/okjs/toolkit/modals/ok-modal.ok.js +1 -0
- package/public/vendor/okjs/toolkit/modals/ok-toast-service.ok.js +1 -0
- package/public/vendor/okjs/toolkit/modals/ok-window.ok.js +1 -0
- package/public/vendor/okjs/toolkit/navigation/hash-router.ok.js +1 -0
- package/public/vendor/okjs/toolkit/navigation/history-router.ok.js +1 -0
- package/public/vendor/okjs/toolkit/navigation/router.ok.js +1 -0
- package/public/vendor/okjs/toolkit/sync/reactive-sync-service.ok.js +1 -0
- package/public/vendor/okjs/toolkit/sync/reactive-sync.js +1 -0
- package/public/vendor/okjs/toolkit/theming/blocks/ok-design-button.css.js +1 -0
- package/public/vendor/okjs/toolkit/theming/blocks/ok-design-input.css.js +1 -0
- package/public/vendor/okjs/toolkit/theming/ok-design-style.js +1 -0
- package/public/vendor/okjs/toolkit/theming/ok-design-vars.js +1 -0
- package/public/vendor/okjs/toolkit/theming/ok-design.ok.js +1 -0
- package/public/vendor/okjs/toolkit/theming/ok-theme-editor/ok-theme-editor-input.ok.js +1 -0
- package/public/vendor/okjs/toolkit/theming/ok-theme-editor/ok-theme-editor-service.ok.js +1 -0
- package/public/vendor/okjs/toolkit/theming/ok-theme-editor/ok-theme-editor-style.js +1 -0
- package/public/vendor/okjs/toolkit/theming/ok-theme-editor/ok-theme-editor-utils.js +1 -0
- package/public/vendor/okjs/toolkit/theming/ok-theme-editor/ok-theme-editor-variable.ok.js +1 -0
- package/public/vendor/okjs/toolkit/theming/ok-theme-editor/ok-theme-editor-vm.js +1 -0
- package/public/vendor/okjs/toolkit/theming/ok-theme-editor/ok-theme-editor.ok.js +1 -0
- package/public/vendor/okjs/toolkit/theming/ok-theme.ok.js +1 -0
- package/public/view-models/type-query-vm.js +1 -0
- package/types/environment.d.ts +130 -0
- package/types/errors.d.ts +98 -0
- package/types/features/admin.d.ts +4 -0
- package/types/features/api.d.ts +18 -0
- package/types/features/auth.d.ts +31 -0
- package/types/features/embeddings.d.ts +39 -0
- package/types/features/engines.d.ts +23 -0
- package/types/features/files.d.ts +29 -0
- package/types/features/fts.d.ts +25 -0
- package/types/features/functions.d.ts +23 -0
- package/types/features/mcp.d.ts +17 -0
- package/types/features/pipelines.d.ts +19 -0
- package/types/features/queue.d.ts +189 -0
- package/types/features/sync.d.ts +34 -0
- package/types/features/time-machine.d.ts +32 -0
- package/types/features/views.d.ts +16 -0
- package/types/index.d.ts +153 -0
- package/types/options.d.ts +202 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
# Getting Started
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
OKDB is a private package. Reference it from its local path or your monorepo:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install /path/to/okdb
|
|
9
|
+
# or in package.json:
|
|
10
|
+
# "okdb": "file:../okdb"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Dependencies that OKDB needs internally (`lmdb`, `sift`, `hnswlib-node`, etc.) are all declared in its own `package.json` and will install automatically.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Opening a database
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
const OKDB = require('src/okdb');
|
|
21
|
+
|
|
22
|
+
const okdb = new OKDB('./mydb', options);
|
|
23
|
+
await okdb.open();
|
|
24
|
+
|
|
25
|
+
// ... use the database ...
|
|
26
|
+
|
|
27
|
+
await okdb.close();
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The path is the root directory. OKDB creates subdirectories inside it for each environment (`default/`, `~system/`, etc.). If the directory doesn't exist it will be created.
|
|
31
|
+
|
|
32
|
+
### Constructor options
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
const okdb = new OKDB('./mydb', {
|
|
36
|
+
// Durability preset: 'strict' | 'balanced' (default) | 'fast'
|
|
37
|
+
// 'balanced' enables overlappingSync for throughput without losing crash safety
|
|
38
|
+
// 'fast' disables fsync — fastest writes, data loss risk on OS crash
|
|
39
|
+
durability: 'balanced',
|
|
40
|
+
|
|
41
|
+
// LMDB map size in bytes (default 4 GiB — grows automatically)
|
|
42
|
+
mapSize: 4 * 1024 ** 3,
|
|
43
|
+
|
|
44
|
+
// LZ4 compression on values (default true)
|
|
45
|
+
compression: true,
|
|
46
|
+
|
|
47
|
+
// AES-256 encryption key (optional)
|
|
48
|
+
encryptionKey: undefined,
|
|
49
|
+
|
|
50
|
+
// HTTP server options
|
|
51
|
+
api: {
|
|
52
|
+
tokens: ['my-bearer-token'], // Bearer tokens for API auth
|
|
53
|
+
},
|
|
54
|
+
admin: {
|
|
55
|
+
auth: {
|
|
56
|
+
user: 'admin',
|
|
57
|
+
pass: 'secret',
|
|
58
|
+
cookieSecret: 'change-me',
|
|
59
|
+
cookieTtlMs: 3_600_000,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
sync: {
|
|
63
|
+
token: 'cluster-secret',
|
|
64
|
+
address: 'http://localhost:8080', // this node's public address
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Your first type
|
|
72
|
+
|
|
73
|
+
A **type** is OKDB's equivalent of a collection or table. Records in a type share the same secondary indexes and FTS indexes.
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
await okdb.registerType('users');
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Types are idempotent to register — calling `registerType` on an already-registered type throws. Use `ensureType` for idempotent setup:
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
await okdb.ensureType('users', {
|
|
83
|
+
indexes: [['role'], ['email'], ['createdAt']],
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Writing records
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
// Upsert — create or overwrite
|
|
93
|
+
await okdb.put('users', 'alice', { name: 'Alice', role: 'admin', email: 'alice@example.com', createdAt: Date.now() });
|
|
94
|
+
|
|
95
|
+
// Create — throws ALREADY_EXISTS if key exists
|
|
96
|
+
await okdb.create('users', 'bob', { name: 'Bob', role: 'member', email: 'bob@example.com', createdAt: Date.now() });
|
|
97
|
+
|
|
98
|
+
// Update — throws NOT_FOUND if key absent
|
|
99
|
+
await okdb.update('users', 'alice', {
|
|
100
|
+
name: 'Alice',
|
|
101
|
+
role: 'superadmin',
|
|
102
|
+
email: 'alice@example.com',
|
|
103
|
+
createdAt: Date.now(),
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Remove
|
|
107
|
+
await okdb.remove('users', 'alice');
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
:::note
|
|
111
|
+
All write methods return a Promise. The record is durable once the promise resolves.
|
|
112
|
+
:::
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Reading records
|
|
117
|
+
|
|
118
|
+
Reads are **synchronous** — no `await` needed.
|
|
119
|
+
|
|
120
|
+
```javascript
|
|
121
|
+
// Single record (returns value or undefined)
|
|
122
|
+
const user = okdb.get('users', 'bob');
|
|
123
|
+
|
|
124
|
+
// Single record with version metadata
|
|
125
|
+
const { value, version } = okdb.getEntry('users', 'bob');
|
|
126
|
+
|
|
127
|
+
// Multiple records at once
|
|
128
|
+
const [alice, bob] = okdb.getMany('users', ['alice', 'bob']);
|
|
129
|
+
|
|
130
|
+
// All keys in a type
|
|
131
|
+
for (const key of okdb.getKeys('users')) {
|
|
132
|
+
console.log(key);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// All values
|
|
136
|
+
for (const value of okdb.getValues('users')) {
|
|
137
|
+
console.log(value);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Count (no full scan needed)
|
|
141
|
+
const count = okdb.getCount('users');
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Querying
|
|
147
|
+
|
|
148
|
+
MongoDB-style filters via [sift](https://github.com/crcn/sift.js):
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
const admins = okdb.query('users', { role: 'admin' });
|
|
152
|
+
for (const { key, value } of admins) {
|
|
153
|
+
console.log(key, value.name);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Nested field conditions
|
|
157
|
+
const recent = okdb.query('users', {
|
|
158
|
+
createdAt: { $gt: Date.now() - 86400_000 },
|
|
159
|
+
role: { $in: ['admin', 'moderator'] },
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
:::tip
|
|
164
|
+
`query()` without an `index` option does a full scan filtered in-process. For large types, use an index to narrow the scan range first. See [Indexes](./indexes.md).
|
|
165
|
+
:::
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Starting the HTTP server
|
|
170
|
+
|
|
171
|
+
OKDB includes a built-in HTTP server with a REST API and admin UI:
|
|
172
|
+
|
|
173
|
+
```javascript
|
|
174
|
+
// Start listening
|
|
175
|
+
okdb.http.listen(8080);
|
|
176
|
+
|
|
177
|
+
console.log('API: http://localhost:8080/api/type/users');
|
|
178
|
+
console.log('Admin: http://localhost:8080/admin/index.html');
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The admin UI provides a browser-based data explorer, index manager, and real-time monitoring.
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Closing
|
|
186
|
+
|
|
187
|
+
Always close cleanly so processors drain and LMDB flushes properly:
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
process.on('SIGINT', () => okdb.close().then(() => process.exit(0)));
|
|
191
|
+
process.on('SIGTERM', () => okdb.close().then(() => process.exit(0)));
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Full minimal example
|
|
197
|
+
|
|
198
|
+
```javascript
|
|
199
|
+
'use strict';
|
|
200
|
+
const OKDB = require('src/okdb');
|
|
201
|
+
|
|
202
|
+
async function main() {
|
|
203
|
+
const okdb = new OKDB('./demo');
|
|
204
|
+
await okdb.open();
|
|
205
|
+
|
|
206
|
+
await okdb.ensureType('products', {
|
|
207
|
+
indexes: [['category'], ['price'], ['category', 'price']],
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
await okdb.put('products', 'p1', { name: 'Widget', category: 'tools', price: 9.99 });
|
|
211
|
+
await okdb.put('products', 'p2', { name: 'Gadget', category: 'tools', price: 19.99 });
|
|
212
|
+
await okdb.put('products', 'p3', { name: 'Doohickey', category: 'misc', price: 4.99 });
|
|
213
|
+
|
|
214
|
+
// Query with filter
|
|
215
|
+
const tools = okdb.query('products', { category: 'tools' });
|
|
216
|
+
for (const { key, value } of tools) {
|
|
217
|
+
console.log(`${key}: ${value.name} — $${value.price}`);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Range scan by index
|
|
221
|
+
const cheap = okdb.byIndex('products', ['price'], {
|
|
222
|
+
start: [0],
|
|
223
|
+
end: [10],
|
|
224
|
+
});
|
|
225
|
+
for (const { key, value } of cheap) {
|
|
226
|
+
console.log(`${value.name} costs $${value.price}`);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
await okdb.close();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
main().catch(console.error);
|
|
233
|
+
```
|