jsql-neo 3.4.3 → 3.4.5
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 +91 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
# JSQL-NEO v3.
|
|
1
|
+
# JSQL-NEO v3.4.3
|
|
2
2
|
|
|
3
|
-
Rust-powered embedded database
|
|
3
|
+
Rust-powered embedded database with **three engines** in one npm package.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Engines
|
|
6
|
+
|
|
7
|
+
| Engine | Entry | Use Case | Speed |
|
|
8
|
+
|--------|-------|----------|-------|
|
|
9
|
+
| **WASM** (Rust → wasm-pack) | `JSQL` | Zero native deps, Node.js | 1.4M rows/sec insert |
|
|
10
|
+
| **HTTP** (Rust actix-web) | `HttpJSQL` | Multi-process / remote | 340K rows/sec insert |
|
|
11
|
+
| **Pure JS** (Database class) | `Database` | Local JSON file, SQLite-like | 617K rows/sec insert |
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
### WASM (no server, zero deps)
|
|
6
16
|
|
|
7
17
|
```js
|
|
8
18
|
const { JSQL } = require('jsql-neo');
|
|
19
|
+
|
|
9
20
|
const db = new JSQL();
|
|
10
21
|
await db.start();
|
|
11
22
|
|
|
@@ -16,26 +27,94 @@ await db.createTable('users', {
|
|
|
16
27
|
|
|
17
28
|
const [id] = await db.insert('users', { name: 'Alice', age: 30 });
|
|
18
29
|
const user = await db.findById('users', id);
|
|
19
|
-
|
|
30
|
+
// → { id: 1, fields: { name: 'Alice', age: 30 }, created_at: '...', updated_at: '...' }
|
|
31
|
+
|
|
32
|
+
await db.stop();
|
|
20
33
|
```
|
|
21
34
|
|
|
22
|
-
|
|
35
|
+
### Pure JS (local file, SQLite-like)
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
const { Database } = require('jsql-neo');
|
|
39
|
+
|
|
40
|
+
const db = new Database('/tmp/mydb.json');
|
|
41
|
+
const users = db.createTable('users', {
|
|
42
|
+
id: { type: 'integer', autoIncrement: true, primaryKey: true },
|
|
43
|
+
name: { type: 'string', length: 32 },
|
|
44
|
+
age: { type: 'integer' }
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const ids = users.insertMany([{ name: 'Alice', age: 30 }, { name: 'Bob', age: 25 }]);
|
|
48
|
+
users.updateById(ids[0], { age: 31 });
|
|
49
|
+
const user = users.findById(ids[0]);
|
|
50
|
+
db.save();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### HTTP Server
|
|
23
54
|
|
|
24
55
|
```bash
|
|
25
|
-
# Start the server
|
|
26
56
|
JSQL_DATA_DIR=/tmp/jsql-neo npx jsql-neo
|
|
57
|
+
```
|
|
27
58
|
|
|
28
|
-
|
|
59
|
+
```js
|
|
29
60
|
const { HttpJSQL } = require('jsql-neo');
|
|
61
|
+
|
|
30
62
|
const db = new HttpJSQL({ host: '127.0.0.1', port: 6379 });
|
|
63
|
+
await db.start();
|
|
64
|
+
|
|
65
|
+
await db.createTable('users', { name: { type: 'string' }, age: { type: 'integer' } });
|
|
66
|
+
const [id] = await db.insert('users', { name: 'Alice', age: 30 });
|
|
67
|
+
const user = await db.findById('users', id);
|
|
68
|
+
|
|
69
|
+
await db.stop();
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## API
|
|
73
|
+
|
|
74
|
+
| Method | WASM | HTTP | Pure JS | Description |
|
|
75
|
+
|--------|------|------|---------|-------------|
|
|
76
|
+
| `createTable(name, schema)` | ✅ | ✅ | ✅ | Define table with typed fields |
|
|
77
|
+
| `insert(table, data)` | ✅ | ✅ | ✅ | Insert row(s), returns IDs |
|
|
78
|
+
| `findById(table, id)` | ✅ | ✅ | ✅ | O(1) PK lookup |
|
|
79
|
+
| `find(table, filter?)` | ✅ | ✅ | ✅ | Filtered query with B-Tree index |
|
|
80
|
+
| `count(table)` | ✅ | ✅ | ✅ | Row count |
|
|
81
|
+
| `updateById(table, id, data)` | ✅ | ✅ | ✅ | O(1) PK update |
|
|
82
|
+
| `removeById(table, id)` | ✅ | ✅ | ✅ | O(1) PK delete |
|
|
83
|
+
| `dropTable(name)` | ✅ | ✅ | ✅ | Remove table |
|
|
84
|
+
|
|
85
|
+
All engines share the same async API for CRUD operations.
|
|
86
|
+
|
|
87
|
+
## Performance (Pure JS, 100K rows)
|
|
88
|
+
|
|
89
|
+
| Operation | Time | Rate |
|
|
90
|
+
|-----------|------|------|
|
|
91
|
+
| Insert 100K | 128 ms | 781K rows/sec |
|
|
92
|
+
| findById × 10,000 | 3 ms | 0.3 μs each |
|
|
93
|
+
| updateById × 10,000 | 82 ms | 8.2 μs each (O(1) hash index) |
|
|
94
|
+
| count × 100 | 0 ms | — |
|
|
95
|
+
| findAll × 5 | 16 ms | — |
|
|
96
|
+
| Filtered query × 100 | 407 ms | — |
|
|
97
|
+
|
|
98
|
+
## Schema Field Options
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
{
|
|
102
|
+
type: 'string' | 'integer' | 'float' | 'boolean',
|
|
103
|
+
primaryKey: true, // PK field (auto-indexed)
|
|
104
|
+
autoIncrement: true, // Auto-generate integer PK
|
|
105
|
+
length: 32, // Max string length
|
|
106
|
+
default: 'value', // Default value
|
|
107
|
+
nullable: true // Allow null
|
|
108
|
+
}
|
|
31
109
|
```
|
|
32
110
|
|
|
33
111
|
## Features
|
|
34
112
|
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
113
|
+
- Three engines: WASM (native Rust), HTTP (actix-web), Pure JS (local JSON)
|
|
114
|
+
- O(1) primary key hash index (`FxHashMap` / `Map`)
|
|
115
|
+
- B-Tree indexing for range queries
|
|
116
|
+
- WAL + snapshot crash recovery (HTTP engine)
|
|
117
|
+
- Strings Pool for memory-efficient storage
|
|
38
118
|
- Batch insert / update / delete
|
|
39
119
|
- Cursor-based pagination
|
|
40
|
-
- Transaction support
|
|
41
|
-
- WASM — zero native dependencies, runs in Node.js and browsers
|
|
120
|
+
- Transaction support (HTTP engine)
|