think-model-sqlite 2.0.0 → 2.0.1

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.
Files changed (2) hide show
  1. package/package.json +3 -2
  2. package/test/index.js +26 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "think-model-sqlite",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "SQLite adapter for ThinkJS 3.x",
5
5
  "scripts": {
6
6
  "test": "npm run eslint && npm run test-cov",
@@ -39,6 +39,7 @@
39
39
  "eslint": "^4.2.0",
40
40
  "eslint-config-think": "^1.0.1",
41
41
  "muk": "^0.5.3",
42
- "nyc": "^10.3.0"
42
+ "nyc": "^10.3.0",
43
+ "think-model": "^1.5.4"
43
44
  }
44
45
  }
package/test/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  const {default: test} = require('ava');
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() {
@@ -52,3 +55,26 @@ test('transaction rollback should keep data unchanged', async t => {
52
55
  await socket.close();
53
56
  }
54
57
  });
58
+
59
+ test('think-model integration', async t => {
60
+ const userModel = new Model('user', {
61
+ handle: SQLite,
62
+ path: '/tmp',
63
+ database: 'test',
64
+ logConnect: false,
65
+ debounce: false
66
+ });
67
+
68
+ await userModel.execute('CREATE TABLE user (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)');
69
+
70
+ const insert1 = await userModel.add({name: 'alice'});
71
+ const insert2 = await userModel.add({name: 'bob'});
72
+ const rows = await userModel.select();
73
+
74
+ t.is(insert1, 1);
75
+ t.is(insert2, 2);
76
+ t.deepEqual(rows, [
77
+ {id: 1, name: 'alice'},
78
+ {id: 2, name: 'bob'}
79
+ ]);
80
+ });