@bibliotek/sqlite 0.0.5 → 0.0.7
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 +21 -0
- package/README.md +40 -0
- package/package.json +5 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2022-2026 Richard Remer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
The **@bibliotek/sqlite** library is a light async/await wrapper around the
|
|
2
|
+
**sqlite3** library.
|
|
3
|
+
|
|
4
|
+
@bibliotek/sqlite
|
|
5
|
+
=================
|
|
6
|
+
For more detailed information, check the unit tests in the **./test**
|
|
7
|
+
directory.
|
|
8
|
+
|
|
9
|
+
Examples
|
|
10
|
+
--------
|
|
11
|
+
```js
|
|
12
|
+
import {Database, Statement} from "@bibliotek/sqlite";
|
|
13
|
+
|
|
14
|
+
let result = null;
|
|
15
|
+
let stmt = null;
|
|
16
|
+
|
|
17
|
+
const db = Database.memory(); // in-memory DB
|
|
18
|
+
// new Database("./my.db"); // ...or load from file
|
|
19
|
+
|
|
20
|
+
// use .run to execute DML statements
|
|
21
|
+
await db.run(`create table thing (id integer primary key autoincrement, value text)`);
|
|
22
|
+
result = await db.run(`insert into thing (value) values ('foo')`);
|
|
23
|
+
result = await db.run(`insert into thing (value) values ('bar')`);
|
|
24
|
+
console.log("insert id", result.lastID);
|
|
25
|
+
console.log("inserted", result.changes, "rows");
|
|
26
|
+
|
|
27
|
+
// use .each to iterate over results
|
|
28
|
+
for await (const row of db.each(`select * from thing`)) {
|
|
29
|
+
console.log(row);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// use .get to fetch a single row
|
|
33
|
+
console.log(await db.get("select * from thing where id = 1"));
|
|
34
|
+
|
|
35
|
+
// use .prepare for prepared statements
|
|
36
|
+
stmt = db.prepare("select * from thing where id = ?");
|
|
37
|
+
|
|
38
|
+
// pass params to statement methods to bind data to statement
|
|
39
|
+
result = await stmt.get(1); // bind 1 to id in prepared statement
|
|
40
|
+
```
|
package/package.json
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bibliotek/sqlite",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Sqlite3 database using async/await",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./sqlite.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "mocha"
|
|
9
9
|
},
|
|
10
|
+
"license": "MIT",
|
|
10
11
|
"dependencies": {
|
|
11
12
|
"@bibliotek/synch": "^0.0.1",
|
|
12
|
-
"sqlite3": "^
|
|
13
|
+
"sqlite3": "^6.0.1"
|
|
13
14
|
},
|
|
14
15
|
"devDependencies": {
|
|
15
16
|
"expect.js": "^0.3.1",
|
|
16
|
-
"mocha": "^
|
|
17
|
-
"sinon": "^
|
|
17
|
+
"mocha": "^12.0.0",
|
|
18
|
+
"sinon": "^22.1.0"
|
|
18
19
|
}
|
|
19
20
|
}
|