think-model-sqlite 2.0.0 → 2.1.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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "think-model-sqlite",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "SQLite adapter for ThinkJS 3.x",
5
5
  "scripts": {
6
- "test": "npm run eslint && npm run test-cov",
7
- "test-cov": "nyc ava test/ && nyc report --reporter=html",
6
+ "test": "pnpm run eslint && pnpm run test-cov",
7
+ "test-cov": "node --test --test-concurrency=1 --experimental-test-coverage test/index.js",
8
8
  "eslint": "eslint ./lib index.js",
9
- "prepublish": "npm test"
9
+ "prepublish": "pnpm test"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/thinkjs/think-model-sqlite#readme",
29
29
  "dependencies": {
30
- "better-sqlite3": "^11.10.0",
30
+ "better-sqlite3": "^13.0.3",
31
31
  "generic-pool": "^3.1.7",
32
32
  "think-debounce": "^1.0.3",
33
33
  "think-helper": "^1.1.3",
@@ -35,10 +35,11 @@
35
35
  "think-model-abstract": "^1.6.5"
36
36
  },
37
37
  "devDependencies": {
38
- "ava": "^8.0.0",
39
- "eslint": "^4.2.0",
40
- "eslint-config-think": "^1.0.1",
38
+ "eslint": "^10.8.0",
41
39
  "muk": "^0.5.3",
42
- "nyc": "^10.3.0"
40
+ "think-model": "^1.5.4"
41
+ },
42
+ "engines": {
43
+ "node": ">=22"
43
44
  }
44
45
  }
package/test/index.js CHANGED
@@ -1,4 +1,7 @@
1
- const {default: test} = require('ava');
1
+ const {test} = require('node:test');
2
+ const Model = require('think-model/lib/model');
3
+ const SQLite = require('../');
4
+
2
5
  const Socket = require('../lib/socket');
3
6
 
4
7
  function createMemorySocket() {
@@ -20,10 +23,10 @@ test('socket execute & query with better-sqlite3', async t => {
20
23
  const insert2 = await socket.execute("INSERT INTO user(name) VALUES ('bob')");
21
24
  const rows = await socket.query('SELECT id, name FROM user ORDER BY id ASC');
22
25
 
23
- t.true(insert1.insertId > 0);
24
- t.is(insert1.affectedRows, 1);
25
- t.is(insert2.affectedRows, 1);
26
- t.deepEqual(rows, [
26
+ t.assert.strictEqual(insert1.insertId > 0, true);
27
+ t.assert.strictEqual(insert1.affectedRows, 1);
28
+ t.assert.strictEqual(insert2.affectedRows, 1);
29
+ t.assert.deepStrictEqual(rows, [
27
30
  {id: 1, name: 'alice'},
28
31
  {id: 2, name: 'bob'}
29
32
  ]);
@@ -38,17 +41,44 @@ test('transaction rollback should keep data unchanged', async t => {
38
41
  try {
39
42
  await socket.execute('CREATE TABLE item (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)');
40
43
 
41
- const err = await t.throwsAsync(async () => {
44
+ let err;
45
+ await t.assert.rejects(async () => {
42
46
  await socket.transaction(async connection => {
43
47
  await socket.execute("INSERT INTO item(name) VALUES ('rollback-me')", connection);
44
48
  throw new Error('mock failure');
45
49
  });
50
+ }, caughtError => {
51
+ err = caughtError;
52
+ return true;
46
53
  });
47
54
 
48
55
  const rows = await socket.query('SELECT COUNT(1) AS cnt FROM item');
49
- t.is(err.message, 'mock failure');
50
- t.is(rows[0].cnt, 0);
56
+ t.assert.strictEqual(err.message, 'mock failure');
57
+ t.assert.strictEqual(rows[0].cnt, 0);
51
58
  } finally {
52
59
  await socket.close();
53
60
  }
54
61
  });
62
+
63
+ test('think-model integration', async t => {
64
+ const userModel = new Model('user', {
65
+ handle: SQLite,
66
+ path: true,
67
+ database: 'test',
68
+ logConnect: false,
69
+ debounce: false
70
+ });
71
+
72
+ await userModel.execute('CREATE TABLE user (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)');
73
+
74
+ const insert1 = await userModel.add({name: 'alice'});
75
+ const insert2 = await userModel.add({name: 'bob'});
76
+ const rows = await userModel.select();
77
+
78
+ t.assert.strictEqual(insert1, 1);
79
+ t.assert.strictEqual(insert2, 2);
80
+ t.assert.deepStrictEqual(rows, [
81
+ {id: 1, name: 'alice'},
82
+ {id: 2, name: 'bob'}
83
+ ]);
84
+ });
package/.eslintrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "think"
3
- }
package/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - '6'
4
- sudo: false
5
- script:
6
- - "npm test"
7
- after_success:
8
- - 'npm install coveralls && ./node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls'