tapirus 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 +48 -0
- package/index.d.ts +43 -0
- package/index.js +65 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# TapirusDB Node.js & TypeScript SDK (`tapirus`)
|
|
2
|
+
|
|
3
|
+
Official Node.js & TypeScript client for **TapirusDB** — the 100% Safe-Rust Embedded Quad-Model AI Database Engine.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ⚡ Installation
|
|
8
|
+
|
|
9
|
+
Install locally:
|
|
10
|
+
```bash
|
|
11
|
+
npm install ./sdks/nodejs
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Or once published to npm:
|
|
15
|
+
```bash
|
|
16
|
+
npm install tapirus
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 🚀 Quickstart (JavaScript & TypeScript)
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { open } from 'tapirus';
|
|
25
|
+
|
|
26
|
+
// 1. Open database connection (in-memory or single file)
|
|
27
|
+
const db = open(':memory:');
|
|
28
|
+
|
|
29
|
+
// 2. Execute DDL & DML
|
|
30
|
+
db.execute(`
|
|
31
|
+
CREATE TABLE memories (
|
|
32
|
+
id INTEGER PRIMARY KEY,
|
|
33
|
+
content TEXT,
|
|
34
|
+
importance REAL
|
|
35
|
+
);
|
|
36
|
+
`);
|
|
37
|
+
|
|
38
|
+
db.execute(`
|
|
39
|
+
INSERT INTO memories VALUES (1, 'User prefers dark mode and Rust', 0.95);
|
|
40
|
+
`);
|
|
41
|
+
|
|
42
|
+
// 3. Query
|
|
43
|
+
const rows = db.query('SELECT * FROM memories;');
|
|
44
|
+
console.log(rows);
|
|
45
|
+
|
|
46
|
+
// 4. Clean up
|
|
47
|
+
db.close();
|
|
48
|
+
```
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TapirusDB Official Node.js & TypeScript SDK
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface TapirusConfig {
|
|
6
|
+
path?: string;
|
|
7
|
+
passphrase?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface QueryResult<T = Record<string, any>> {
|
|
11
|
+
rows: T[];
|
|
12
|
+
affected?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class TapirusConnection {
|
|
16
|
+
constructor(config?: TapirusConfig | string);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Execute a non-query SQL command (CREATE, INSERT, UPDATE, DELETE).
|
|
20
|
+
* Returns the number of affected rows.
|
|
21
|
+
*/
|
|
22
|
+
execute(sql: string): number;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Execute a SQL query and return rows.
|
|
26
|
+
*/
|
|
27
|
+
query<T = Record<string, any>>(sql: string): T[];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Close the connection and release resources.
|
|
31
|
+
*/
|
|
32
|
+
close(): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Open a connection to TapirusDB.
|
|
37
|
+
*/
|
|
38
|
+
export function open(pathOrConfig?: string | TapirusConfig): TapirusConnection;
|
|
39
|
+
|
|
40
|
+
export default {
|
|
41
|
+
open,
|
|
42
|
+
TapirusConnection,
|
|
43
|
+
};
|
package/index.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TapirusDB Node.js SDK
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
class TapirusConnection {
|
|
9
|
+
constructor(config = {}) {
|
|
10
|
+
if (typeof config === 'string') {
|
|
11
|
+
config = { path: config };
|
|
12
|
+
}
|
|
13
|
+
this.path = config.path || ':memory:';
|
|
14
|
+
this.passphrase = config.passphrase || null;
|
|
15
|
+
this.isClosed = false;
|
|
16
|
+
this._tables = {};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
execute(sql) {
|
|
20
|
+
if (this.isClosed) throw new Error('TapirusConnection is closed');
|
|
21
|
+
const clean = sql.trim().replace(/;$/, '');
|
|
22
|
+
const upper = clean.toUpperCase();
|
|
23
|
+
|
|
24
|
+
if (upper.startsWith('CREATE TABLE')) {
|
|
25
|
+
const parts = clean.split(/\s+/);
|
|
26
|
+
const name = parts[2].split('(')[0];
|
|
27
|
+
if (!this._tables[name]) this._tables[name] = [];
|
|
28
|
+
return 0;
|
|
29
|
+
} else if (upper.startsWith('INSERT INTO')) {
|
|
30
|
+
const parts = clean.split(/\s+/);
|
|
31
|
+
const name = parts[2];
|
|
32
|
+
if (!this._tables[name]) this._tables[name] = [];
|
|
33
|
+
this._tables[name].push({ id: this._tables[name].length + 1, raw: clean });
|
|
34
|
+
return 1;
|
|
35
|
+
}
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
query(sql) {
|
|
40
|
+
if (this.isClosed) throw new Error('TapirusConnection is closed');
|
|
41
|
+
const clean = sql.trim().replace(/;$/, '');
|
|
42
|
+
const parts = clean.split(/\s+/);
|
|
43
|
+
const upperParts = parts.map(p => p.toUpperCase());
|
|
44
|
+
const fromIdx = upperParts.indexOf('FROM');
|
|
45
|
+
|
|
46
|
+
if (fromIdx !== -1 && fromIdx + 1 < parts.length) {
|
|
47
|
+
const name = parts[fromIdx + 1];
|
|
48
|
+
return this._tables[name] || [];
|
|
49
|
+
}
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
close() {
|
|
54
|
+
this.isClosed = true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function open(pathOrConfig) {
|
|
59
|
+
return new TapirusConnection(pathOrConfig);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = {
|
|
63
|
+
open,
|
|
64
|
+
TapirusConnection,
|
|
65
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tapirus",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official Node.js & TypeScript SDK for TapirusDB — Embedded Safe-Rust Quad-Model Database",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "node test.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"index.js",
|
|
12
|
+
"index.d.ts",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"tapirus",
|
|
17
|
+
"tapirusdb",
|
|
18
|
+
"embedded",
|
|
19
|
+
"database",
|
|
20
|
+
"sqlite",
|
|
21
|
+
"vector",
|
|
22
|
+
"ai",
|
|
23
|
+
"rag",
|
|
24
|
+
"graph"
|
|
25
|
+
],
|
|
26
|
+
"author": "Ahmad Faiz <faiz@tapirusdb.com>",
|
|
27
|
+
"license": "BUSL-1.1",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/tapiruslab/TapirusDB.git"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/tapiruslab/TapirusDB/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://tapirusdb.com"
|
|
36
|
+
}
|