@sochdb/sochdb 0.4.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 +201 -0
- package/README.md +3349 -0
- package/_bin/aarch64-apple-darwin/libsochdb_storage.dylib +0 -0
- package/_bin/aarch64-apple-darwin/sochdb-bulk +0 -0
- package/_bin/aarch64-apple-darwin/sochdb-grpc-server +0 -0
- package/_bin/aarch64-apple-darwin/sochdb-server +0 -0
- package/_bin/x86_64-pc-windows-msvc/sochdb-bulk.exe +0 -0
- package/_bin/x86_64-pc-windows-msvc/sochdb-grpc-server.exe +0 -0
- package/_bin/x86_64-pc-windows-msvc/sochdb_storage.dll +0 -0
- package/_bin/x86_64-unknown-linux-gnu/libsochdb_storage.so +0 -0
- package/_bin/x86_64-unknown-linux-gnu/sochdb-bulk +0 -0
- package/_bin/x86_64-unknown-linux-gnu/sochdb-grpc-server +0 -0
- package/_bin/x86_64-unknown-linux-gnu/sochdb-server +0 -0
- package/bin/sochdb-bulk.js +80 -0
- package/bin/sochdb-grpc-server.js +80 -0
- package/bin/sochdb-server.js +84 -0
- package/dist/cjs/analytics.js +196 -0
- package/dist/cjs/database.js +929 -0
- package/dist/cjs/embedded/database.js +236 -0
- package/dist/cjs/embedded/ffi/bindings.js +113 -0
- package/dist/cjs/embedded/ffi/library-finder.js +135 -0
- package/dist/cjs/embedded/index.js +14 -0
- package/dist/cjs/embedded/transaction.js +172 -0
- package/dist/cjs/errors.js +71 -0
- package/dist/cjs/format.js +176 -0
- package/dist/cjs/grpc-client.js +328 -0
- package/dist/cjs/index.js +75 -0
- package/dist/cjs/ipc-client.js +504 -0
- package/dist/cjs/query.js +154 -0
- package/dist/cjs/server-manager.js +295 -0
- package/dist/cjs/sql-engine.js +874 -0
- package/dist/esm/analytics.js +196 -0
- package/dist/esm/database.js +931 -0
- package/dist/esm/embedded/database.js +239 -0
- package/dist/esm/embedded/ffi/bindings.js +142 -0
- package/dist/esm/embedded/ffi/library-finder.js +135 -0
- package/dist/esm/embedded/index.js +14 -0
- package/dist/esm/embedded/transaction.js +176 -0
- package/dist/esm/errors.js +71 -0
- package/dist/esm/format.js +179 -0
- package/dist/esm/grpc-client.js +333 -0
- package/dist/esm/index.js +75 -0
- package/dist/esm/ipc-client.js +505 -0
- package/dist/esm/query.js +159 -0
- package/dist/esm/server-manager.js +295 -0
- package/dist/esm/sql-engine.js +875 -0
- package/dist/types/analytics.d.ts +66 -0
- package/dist/types/analytics.d.ts.map +1 -0
- package/dist/types/database.d.ts +523 -0
- package/dist/types/database.d.ts.map +1 -0
- package/dist/types/embedded/database.d.ts +105 -0
- package/dist/types/embedded/database.d.ts.map +1 -0
- package/dist/types/embedded/ffi/bindings.d.ts +24 -0
- package/dist/types/embedded/ffi/bindings.d.ts.map +1 -0
- package/dist/types/embedded/ffi/library-finder.d.ts +17 -0
- package/dist/types/embedded/ffi/library-finder.d.ts.map +1 -0
- package/dist/types/embedded/index.d.ts +9 -0
- package/dist/types/embedded/index.d.ts.map +1 -0
- package/dist/types/embedded/transaction.d.ts +21 -0
- package/dist/types/embedded/transaction.d.ts.map +1 -0
- package/dist/types/errors.d.ts +36 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/format.d.ts +117 -0
- package/dist/types/format.d.ts.map +1 -0
- package/dist/types/grpc-client.d.ts +120 -0
- package/dist/types/grpc-client.d.ts.map +1 -0
- package/dist/types/index.d.ts +50 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/ipc-client.d.ts +177 -0
- package/dist/types/ipc-client.d.ts.map +1 -0
- package/dist/types/query.d.ts +85 -0
- package/dist/types/query.d.ts.map +1 -0
- package/dist/types/server-manager.d.ts +29 -0
- package/dist/types/server-manager.d.ts.map +1 -0
- package/dist/types/sql-engine.d.ts +100 -0
- package/dist/types/sql-engine.d.ts.map +1 -0
- package/package.json +90 -0
- package/scripts/postinstall.js +50 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SochDB IPC Client
|
|
3
|
+
*
|
|
4
|
+
* Connects to a SochDB IPC server via Unix domain socket.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
import { Query } from './query';
|
|
9
|
+
/**
|
|
10
|
+
* Wire protocol opcodes.
|
|
11
|
+
*/
|
|
12
|
+
export declare const OpCode: {
|
|
13
|
+
readonly Put: 1;
|
|
14
|
+
readonly Get: 2;
|
|
15
|
+
readonly Delete: 3;
|
|
16
|
+
readonly BeginTxn: 4;
|
|
17
|
+
readonly CommitTxn: 5;
|
|
18
|
+
readonly AbortTxn: 6;
|
|
19
|
+
readonly Query: 7;
|
|
20
|
+
readonly CreateTable: 8;
|
|
21
|
+
readonly PutPath: 9;
|
|
22
|
+
readonly GetPath: 10;
|
|
23
|
+
readonly Scan: 11;
|
|
24
|
+
readonly Checkpoint: 12;
|
|
25
|
+
readonly Stats: 13;
|
|
26
|
+
readonly Ping: 14;
|
|
27
|
+
readonly OK: 128;
|
|
28
|
+
readonly Error: 129;
|
|
29
|
+
readonly Value: 130;
|
|
30
|
+
readonly TxnId: 131;
|
|
31
|
+
readonly Row: 132;
|
|
32
|
+
readonly EndStream: 133;
|
|
33
|
+
readonly StatsResp: 134;
|
|
34
|
+
readonly Pong: 135;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Configuration options for IpcClient.
|
|
38
|
+
*/
|
|
39
|
+
export interface IpcClientConfig {
|
|
40
|
+
/** Path to Unix domain socket */
|
|
41
|
+
socketPath: string;
|
|
42
|
+
/** Connection timeout in milliseconds (default: 5000) */
|
|
43
|
+
connectTimeout?: number;
|
|
44
|
+
/** Read timeout in milliseconds (default: 30000) */
|
|
45
|
+
readTimeout?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* IPC Client for SochDB.
|
|
49
|
+
*
|
|
50
|
+
* Connects to a SochDB server via Unix domain socket.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { IpcClient } from '@sushanth/sochdb';
|
|
55
|
+
*
|
|
56
|
+
* const client = await IpcClient.connect('/tmp/sochdb.sock');
|
|
57
|
+
*
|
|
58
|
+
* await client.put(Buffer.from('key'), Buffer.from('value'));
|
|
59
|
+
* const value = await client.get(Buffer.from('key'));
|
|
60
|
+
*
|
|
61
|
+
* await client.close();
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare class IpcClient {
|
|
65
|
+
private _socket;
|
|
66
|
+
private _config;
|
|
67
|
+
private _pendingReads;
|
|
68
|
+
private _readBuffer;
|
|
69
|
+
private _closed;
|
|
70
|
+
private constructor();
|
|
71
|
+
/**
|
|
72
|
+
* Connect to a SochDB IPC server.
|
|
73
|
+
*
|
|
74
|
+
* @param socketPath - Path to the Unix domain socket
|
|
75
|
+
* @returns A connected IpcClient instance
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const client = await IpcClient.connect('/tmp/sochdb.sock');
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
static connect(socketPath: string): Promise<IpcClient>;
|
|
83
|
+
private _connect;
|
|
84
|
+
private _processBuffer;
|
|
85
|
+
private _send;
|
|
86
|
+
private _parseResponse;
|
|
87
|
+
/**
|
|
88
|
+
* Encode a key for the wire protocol.
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
static encodeKey(key: Buffer): Buffer;
|
|
92
|
+
/**
|
|
93
|
+
* Encode a key-value pair for the wire protocol.
|
|
94
|
+
* @internal
|
|
95
|
+
*/
|
|
96
|
+
static encodeKeyValue(key: Buffer, value: Buffer): Buffer;
|
|
97
|
+
/**
|
|
98
|
+
* Get a value by key.
|
|
99
|
+
*/
|
|
100
|
+
get(key: Buffer): Promise<Buffer | null>;
|
|
101
|
+
/**
|
|
102
|
+
* Put a key-value pair.
|
|
103
|
+
*/
|
|
104
|
+
put(key: Buffer, value: Buffer): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Delete a key.
|
|
107
|
+
*/
|
|
108
|
+
delete(key: Buffer): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Get a value by path.
|
|
111
|
+
* Wire format: path_count(2 LE) + [path_len(2 LE) + path_segment]...
|
|
112
|
+
*/
|
|
113
|
+
getPath(path: string): Promise<Buffer | null>;
|
|
114
|
+
/**
|
|
115
|
+
* Put a value at a path.
|
|
116
|
+
* Wire format: path_count(2 LE) + [path_len(2 LE) + path_segment]... + value
|
|
117
|
+
*/
|
|
118
|
+
putPath(path: string, value: Buffer): Promise<void>;
|
|
119
|
+
/**
|
|
120
|
+
* Execute a query and return TOON-formatted results.
|
|
121
|
+
*
|
|
122
|
+
* Wire format: path_len(2) + path + limit(4) + offset(4) + cols_count(2) + [col_len(2) + col]...
|
|
123
|
+
*/
|
|
124
|
+
query(pathPrefix: string, options?: {
|
|
125
|
+
limit?: number;
|
|
126
|
+
offset?: number;
|
|
127
|
+
columns?: string[];
|
|
128
|
+
}): Promise<string>;
|
|
129
|
+
/**
|
|
130
|
+
* Scan for keys with a prefix, returning key-value pairs.
|
|
131
|
+
* This is the preferred method for simple prefix-based iteration.
|
|
132
|
+
*
|
|
133
|
+
* Wire format: prefix string
|
|
134
|
+
* Response format: count(4 LE) + [key_len(2 LE) + key + val_len(4 LE) + val]...
|
|
135
|
+
*/
|
|
136
|
+
scan(prefix: string): Promise<Array<{
|
|
137
|
+
key: Buffer;
|
|
138
|
+
value: Buffer;
|
|
139
|
+
}>>;
|
|
140
|
+
/**
|
|
141
|
+
* Create a query builder.
|
|
142
|
+
*/
|
|
143
|
+
queryBuilder(pathPrefix: string): Query;
|
|
144
|
+
/**
|
|
145
|
+
* Begin a new transaction.
|
|
146
|
+
*/
|
|
147
|
+
beginTransaction(): Promise<bigint>;
|
|
148
|
+
/**
|
|
149
|
+
* Commit a transaction.
|
|
150
|
+
*/
|
|
151
|
+
commitTransaction(txnId: bigint): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* Abort a transaction.
|
|
154
|
+
*/
|
|
155
|
+
abortTransaction(txnId: bigint): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Force a checkpoint.
|
|
158
|
+
*/
|
|
159
|
+
checkpoint(): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Get storage statistics.
|
|
162
|
+
*/
|
|
163
|
+
stats(): Promise<{
|
|
164
|
+
memtableSizeBytes: number;
|
|
165
|
+
walSizeBytes: number;
|
|
166
|
+
activeTransactions: number;
|
|
167
|
+
}>;
|
|
168
|
+
/**
|
|
169
|
+
* Ping the server.
|
|
170
|
+
*/
|
|
171
|
+
ping(): Promise<boolean>;
|
|
172
|
+
/**
|
|
173
|
+
* Close the connection.
|
|
174
|
+
*/
|
|
175
|
+
close(): Promise<void>;
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=ipc-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipc-client.d.ts","sourceRoot":"","sources":["../../src/ipc-client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;GAEG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;CA0BT,CAAC;AA6BX;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,iCAAiC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oDAAoD;IACpD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,aAAa,CAGb;IACR,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,OAAO,CAAS;IAExB,OA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CAAC,UAAU,EAAE,MAAM,GAAG,KAAK;IAIvC;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAUzC;;OAEG;IACG,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOrD;;OAEG;IACG,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOpD;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAKjC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC;QACrB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,MAAM,CAAC;QACrB,kBAAkB,EAAE,MAAM,CAAC;KAC5B,CAAC;IAWF;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAU9B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAa7B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SochDB Query Builder
|
|
3
|
+
*
|
|
4
|
+
* Fluent query interface for SochDB.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
import { IpcClient } from './ipc-client';
|
|
9
|
+
/**
|
|
10
|
+
* Query result row.
|
|
11
|
+
*/
|
|
12
|
+
export interface QueryResult {
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Fluent query builder for SochDB.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const results = await db.query('users/')
|
|
21
|
+
* .limit(10)
|
|
22
|
+
* .select(['name', 'email'])
|
|
23
|
+
* .toList();
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare class Query {
|
|
27
|
+
private _client;
|
|
28
|
+
private _pathPrefix;
|
|
29
|
+
private _limit?;
|
|
30
|
+
private _offset?;
|
|
31
|
+
private _columns?;
|
|
32
|
+
constructor(client: IpcClient, pathPrefix: string);
|
|
33
|
+
/**
|
|
34
|
+
* Limit the number of results.
|
|
35
|
+
*
|
|
36
|
+
* @param n - Maximum number of results to return
|
|
37
|
+
* @returns This query builder for chaining
|
|
38
|
+
*/
|
|
39
|
+
limit(n: number): Query;
|
|
40
|
+
/**
|
|
41
|
+
* Skip the first n results.
|
|
42
|
+
*
|
|
43
|
+
* @param n - Number of results to skip
|
|
44
|
+
* @returns This query builder for chaining
|
|
45
|
+
*/
|
|
46
|
+
offset(n: number): Query;
|
|
47
|
+
/**
|
|
48
|
+
* Select specific columns to return.
|
|
49
|
+
*
|
|
50
|
+
* @param columns - Array of column names to select
|
|
51
|
+
* @returns This query builder for chaining
|
|
52
|
+
*/
|
|
53
|
+
select(columns: string[]): Query;
|
|
54
|
+
/**
|
|
55
|
+
* Execute the query and return results as TOON string.
|
|
56
|
+
*
|
|
57
|
+
* @returns TOON formatted string (e.g., "result[N]{cols}: row1; row2")
|
|
58
|
+
*/
|
|
59
|
+
execute(): Promise<string>;
|
|
60
|
+
/**
|
|
61
|
+
* Execute and parse results into a list of objects.
|
|
62
|
+
*
|
|
63
|
+
* @returns Array of result objects
|
|
64
|
+
*/
|
|
65
|
+
toList(): Promise<QueryResult[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Execute and return the first result, or null if none.
|
|
68
|
+
*
|
|
69
|
+
* @returns First result or null
|
|
70
|
+
*/
|
|
71
|
+
first(): Promise<QueryResult | null>;
|
|
72
|
+
/**
|
|
73
|
+
* Execute and return the count of results.
|
|
74
|
+
*
|
|
75
|
+
* @returns Number of matching results
|
|
76
|
+
*/
|
|
77
|
+
count(): Promise<number>;
|
|
78
|
+
/**
|
|
79
|
+
* Simple TOON parser.
|
|
80
|
+
*
|
|
81
|
+
* Parses TOON format: "result[N]{col1,col2}: val1,val2; val3,val4"
|
|
82
|
+
*/
|
|
83
|
+
private _parseToon;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/query.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;;;;GAUG;AACH,qBAAa,KAAK;IAChB,OAAO,CAAC,OAAO,CAAY;IAC3B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAC,CAAW;gBAEhB,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM;IAKjD;;;;;OAKG;IACH,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK;IAKvB;;;;;OAKG;IACH,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK;IAKxB;;;;;OAKG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,KAAK;IAKhC;;;;OAIG;IACG,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAQhC;;;;OAIG;IACG,MAAM,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAKtC;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAQ1C;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAK9B;;;;OAIG;IACH,OAAO,CAAC,UAAU;CAmDnB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SochDB Embedded Server Manager
|
|
3
|
+
*
|
|
4
|
+
* Manages the lifecycle of the SochDB server process for embedded mode.
|
|
5
|
+
* Automatically starts the server when needed and stops it on cleanup.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Start an embedded SochDB server for the given database path.
|
|
11
|
+
* If a server is already running for this path, return the existing instance.
|
|
12
|
+
*
|
|
13
|
+
* @param dbPath - Path to the database directory
|
|
14
|
+
* @returns The socket path for connecting
|
|
15
|
+
*/
|
|
16
|
+
export declare function startEmbeddedServer(dbPath: string): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Stop the embedded server for a specific database path
|
|
19
|
+
*/
|
|
20
|
+
export declare function stopEmbeddedServer(dbPath: string): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Stop all running embedded servers
|
|
23
|
+
*/
|
|
24
|
+
export declare function stopAllEmbeddedServers(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Check if an embedded server is running for a database path
|
|
27
|
+
*/
|
|
28
|
+
export declare function isServerRunning(dbPath: string): boolean;
|
|
29
|
+
//# sourceMappingURL=server-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-manager.d.ts","sourceRoot":"","sources":["../../src/server-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA8HH;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA+EzE;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqCtE;AAED;;GAEG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC,CAM5D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAIvD"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQL Engine for SochDB JavaScript SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides SQL support on top of the KV storage backend.
|
|
5
|
+
* Tables are stored as:
|
|
6
|
+
* - Schema: _sql/tables/{table_name}/schema -> JSON schema definition
|
|
7
|
+
* - Rows: _sql/tables/{table_name}/rows/{row_id} -> JSON row data
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Result of a SQL query execution.
|
|
13
|
+
*/
|
|
14
|
+
export interface SQLQueryResult {
|
|
15
|
+
/** Result rows */
|
|
16
|
+
rows: Array<Record<string, any>>;
|
|
17
|
+
/** Column names */
|
|
18
|
+
columns: string[];
|
|
19
|
+
/** Number of rows affected (for INSERT/UPDATE/DELETE) */
|
|
20
|
+
rowsAffected: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parsed SQL operation result.
|
|
24
|
+
*/
|
|
25
|
+
type ParsedSQL = {
|
|
26
|
+
operation: string;
|
|
27
|
+
data: Record<string, any>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Simple SQL parser for DDL and DML operations.
|
|
31
|
+
*/
|
|
32
|
+
export declare class SQLParser {
|
|
33
|
+
/**
|
|
34
|
+
* Parse a SQL statement.
|
|
35
|
+
*/
|
|
36
|
+
static parse(sql: string): ParsedSQL;
|
|
37
|
+
private static parseCreateTable;
|
|
38
|
+
private static splitColumns;
|
|
39
|
+
private static parseDropTable;
|
|
40
|
+
private static parseCreateIndex;
|
|
41
|
+
private static parseDropIndex;
|
|
42
|
+
private static parseInsert;
|
|
43
|
+
private static parseValues;
|
|
44
|
+
private static parseValue;
|
|
45
|
+
private static parseSelect;
|
|
46
|
+
private static parseWhere;
|
|
47
|
+
private static parseUpdate;
|
|
48
|
+
private static parseDelete;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Interface for database operations required by SQLExecutor.
|
|
52
|
+
*/
|
|
53
|
+
interface DatabaseInterface {
|
|
54
|
+
get(key: Buffer | string): Promise<Buffer | null>;
|
|
55
|
+
put(key: Buffer | string, value: Buffer | string): Promise<void>;
|
|
56
|
+
delete(key: Buffer | string): Promise<void>;
|
|
57
|
+
scan(prefix: string): Promise<Array<{
|
|
58
|
+
key: Buffer;
|
|
59
|
+
value: Buffer;
|
|
60
|
+
}>>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* SQL Executor that operates on a KV database.
|
|
64
|
+
*/
|
|
65
|
+
export declare class SQLExecutor {
|
|
66
|
+
private db;
|
|
67
|
+
private readonly TABLE_PREFIX;
|
|
68
|
+
private readonly SCHEMA_SUFFIX;
|
|
69
|
+
private readonly ROWS_PREFIX;
|
|
70
|
+
private readonly INDEX_PREFIX;
|
|
71
|
+
constructor(db: DatabaseInterface);
|
|
72
|
+
/**
|
|
73
|
+
* Execute a SQL statement.
|
|
74
|
+
*/
|
|
75
|
+
execute(sql: string): Promise<SQLQueryResult>;
|
|
76
|
+
private schemaKey;
|
|
77
|
+
private rowKey;
|
|
78
|
+
private rowPrefix;
|
|
79
|
+
private indexMetaKey;
|
|
80
|
+
private indexPrefix;
|
|
81
|
+
private indexKey;
|
|
82
|
+
private indexValuePrefix;
|
|
83
|
+
private getSchema;
|
|
84
|
+
private getIndexes;
|
|
85
|
+
private hasIndexForColumn;
|
|
86
|
+
private lookupByIndex;
|
|
87
|
+
private updateIndex;
|
|
88
|
+
private findIndexedEqualityCondition;
|
|
89
|
+
private createTable;
|
|
90
|
+
private dropTable;
|
|
91
|
+
private createIndex;
|
|
92
|
+
private dropIndex;
|
|
93
|
+
private insert;
|
|
94
|
+
private select;
|
|
95
|
+
private matchesConditions;
|
|
96
|
+
private update;
|
|
97
|
+
private deleteRows;
|
|
98
|
+
}
|
|
99
|
+
export {};
|
|
100
|
+
//# sourceMappingURL=sql-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql-engine.d.ts","sourceRoot":"","sources":["../../src/sql-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAYH;;GAEG;AACH,MAAM,WAAW,cAAc;IA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C,CAAC;IAC5C,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;CACtE;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,EAAE,CAAoB;IAG9B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkB;IAC/C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAa;IAC3C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAY;IACxC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;gBAEhC,EAAE,EAAE,iBAAiB;IAIjC;;OAEG;IACG,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAyBnD,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,gBAAgB;YAIV,SAAS;YAMT,UAAU;YAqBV,iBAAiB;YAUjB,aAAa;YAMb,WAAW;IA4BzB,OAAO,CAAC,4BAA4B;YAatB,WAAW;YAgBX,SAAS;YA8BT,WAAW;YA8CX,SAAS;YAoBT,MAAM;YAkDN,MAAM;IAwEpB,OAAO,CAAC,iBAAiB;YA2CX,MAAM;YAuFN,UAAU;CA0FzB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sochdb/sochdb",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "SochDB is an AI-native database with token-optimized output, O(|path|) lookups, built-in vector search, and durable transactions.",
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/esm/index.js",
|
|
11
|
+
"require": "./dist/cjs/index.js",
|
|
12
|
+
"types": "./dist/types/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"_bin",
|
|
18
|
+
"bin",
|
|
19
|
+
"scripts/postinstall.js",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"bin": {
|
|
24
|
+
"sochdb-server": "./bin/sochdb-server.js",
|
|
25
|
+
"sochdb-bulk": "./bin/sochdb-bulk.js",
|
|
26
|
+
"sochdb-grpc-server": "./bin/sochdb-grpc-server.js"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "npm run build:cjs && npm run build:esm && npm run build:types && npm run postbuild",
|
|
30
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
31
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
32
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
33
|
+
"postbuild": "node scripts/fix-esm-imports.js",
|
|
34
|
+
"postinstall": "node scripts/postinstall.js",
|
|
35
|
+
"test": "jest",
|
|
36
|
+
"test:coverage": "jest --coverage",
|
|
37
|
+
"lint": "eslint src --ext .ts",
|
|
38
|
+
"lint:fix": "eslint src --ext .ts --fix",
|
|
39
|
+
"format": "prettier --write src/**/*.ts",
|
|
40
|
+
"clean": "rm -rf dist",
|
|
41
|
+
"prepublishOnly": "npm run clean && npm run build && npm test"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"database",
|
|
45
|
+
"llm",
|
|
46
|
+
"ai",
|
|
47
|
+
"vector-search",
|
|
48
|
+
"embedded",
|
|
49
|
+
"key-value",
|
|
50
|
+
"sochdb",
|
|
51
|
+
"context-retrieval",
|
|
52
|
+
"transactions"
|
|
53
|
+
],
|
|
54
|
+
"author": "Sushanth <sushanth@sochdb.dev>",
|
|
55
|
+
"license": "Apache-2.0",
|
|
56
|
+
"repository": {
|
|
57
|
+
"type": "git",
|
|
58
|
+
"url": "https://github.com/sochdb/sochdb.git",
|
|
59
|
+
"directory": "sochdb-nodejs-sdk"
|
|
60
|
+
},
|
|
61
|
+
"homepage": "https://sochdb.dev",
|
|
62
|
+
"bugs": {
|
|
63
|
+
"url": "https://github.com/sochdb/sochdb/issues"
|
|
64
|
+
},
|
|
65
|
+
"engines": {
|
|
66
|
+
"node": ">=18.0.0"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@types/jest": "^29.5.12",
|
|
70
|
+
"@types/node": "^20.11.0",
|
|
71
|
+
"@types/uuid": "^9.0.0",
|
|
72
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
73
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
74
|
+
"eslint": "^8.56.0",
|
|
75
|
+
"eslint-config-prettier": "^9.1.0",
|
|
76
|
+
"jest": "^29.7.0",
|
|
77
|
+
"prettier": "^3.2.0",
|
|
78
|
+
"ts-jest": "^29.1.2",
|
|
79
|
+
"typescript": "^5.3.3"
|
|
80
|
+
},
|
|
81
|
+
"dependencies": {
|
|
82
|
+
"@grpc/grpc-js": "^1.12.4",
|
|
83
|
+
"@grpc/proto-loader": "^0.7.15",
|
|
84
|
+
"koffi": "^2.15.0",
|
|
85
|
+
"uuid": "^9.0.0"
|
|
86
|
+
},
|
|
87
|
+
"optionalDependencies": {
|
|
88
|
+
"posthog-node": "^4.18.0"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Post-install script to ensure native binaries are executable on Unix systems.
|
|
4
|
+
* This is required because npm doesn't preserve executable permissions during publish.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { execSync } = require('child_process');
|
|
10
|
+
|
|
11
|
+
// Only run on Unix-like systems
|
|
12
|
+
if (process.platform === 'win32') {
|
|
13
|
+
console.log('[sochdb] Skipping chmod on Windows');
|
|
14
|
+
process.exit(0);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const binDir = path.join(__dirname, '..', '_bin');
|
|
18
|
+
|
|
19
|
+
if (!fs.existsSync(binDir)) {
|
|
20
|
+
console.log('[sochdb] No _bin directory found, skipping postinstall (will be populated on first use)');
|
|
21
|
+
process.exit(0);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const binaryNames = ['sochdb-server', 'sochdb-bulk', 'sochdb-grpc-server'];
|
|
25
|
+
const targets = [
|
|
26
|
+
'aarch64-apple-darwin',
|
|
27
|
+
'x86_64-apple-darwin',
|
|
28
|
+
'aarch64-unknown-linux-gnu',
|
|
29
|
+
'x86_64-unknown-linux-gnu'
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
let fixed = 0;
|
|
33
|
+
for (const target of targets) {
|
|
34
|
+
for (const binaryName of binaryNames) {
|
|
35
|
+
const binaryPath = path.join(binDir, target, binaryName);
|
|
36
|
+
if (fs.existsSync(binaryPath)) {
|
|
37
|
+
try {
|
|
38
|
+
// Make executable
|
|
39
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
40
|
+
fixed++;
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.warn(`[sochdb] Warning: Could not chmod ${binaryPath}: ${err.message}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (fixed > 0) {
|
|
49
|
+
console.log(`[sochdb] Made ${fixed} native binaries executable`);
|
|
50
|
+
}
|