sails-sqlite 0.0.0 โ 0.2.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/.github/FUNDING.yml +1 -0
- package/.github/workflows/prettier.yml +16 -0
- package/.github/workflows/test.yml +16 -0
- package/.husky/pre-commit +1 -0
- package/.prettierrc.js +5 -0
- package/CHANGELOG.md +161 -0
- package/LICENSE +21 -0
- package/README.md +247 -0
- package/lib/index.js +1104 -0
- package/lib/private/build-std-adapter-method.js +69 -0
- package/lib/private/constants/connection.input.js +15 -0
- package/lib/private/constants/dry-orm.input.js +23 -0
- package/lib/private/constants/meta.input.js +14 -0
- package/lib/private/constants/not-unique.exit.js +16 -0
- package/lib/private/constants/query.input.js +15 -0
- package/lib/private/constants/table-name.input.js +12 -0
- package/lib/private/machines/avg-records.js +74 -0
- package/lib/private/machines/begin-transaction.js +51 -0
- package/lib/private/machines/commit-transaction.js +50 -0
- package/lib/private/machines/count-records.js +78 -0
- package/lib/private/machines/create-each-record.js +163 -0
- package/lib/private/machines/create-manager.js +174 -0
- package/lib/private/machines/create-record.js +126 -0
- package/lib/private/machines/define-physical-model.js +111 -0
- package/lib/private/machines/destroy-manager.js +87 -0
- package/lib/private/machines/destroy-records.js +114 -0
- package/lib/private/machines/drop-physical-model.js +51 -0
- package/lib/private/machines/find-records.js +120 -0
- package/lib/private/machines/get-connection.js +54 -0
- package/lib/private/machines/join.js +259 -0
- package/lib/private/machines/lease-connection.js +58 -0
- package/lib/private/machines/private/build-sqlite-where-clause.js +91 -0
- package/lib/private/machines/private/compile-statement.js +334 -0
- package/lib/private/machines/private/generate-join-sql-query.js +385 -0
- package/lib/private/machines/private/process-each-record.js +106 -0
- package/lib/private/machines/private/process-native-error.js +104 -0
- package/lib/private/machines/private/process-native-record.js +104 -0
- package/lib/private/machines/private/reify-values-to-set.js +83 -0
- package/lib/private/machines/release-connection.js +70 -0
- package/lib/private/machines/rollback-transaction.js +50 -0
- package/lib/private/machines/set-physical-sequence.js +77 -0
- package/lib/private/machines/sum-records.js +75 -0
- package/lib/private/machines/update-records.js +162 -0
- package/lib/private/machines/verify-model-def.js +38 -0
- package/package.json +58 -5
- package/tests/index.js +88 -0
- package/tests/runner.js +99 -0
- package/tests/transaction.test.js +562 -0
package/tests/index.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require('node:child_process')
|
|
4
|
+
const path = require('node:path')
|
|
5
|
+
const fs = require('node:fs')
|
|
6
|
+
|
|
7
|
+
// __dirname is automatically available in CommonJS
|
|
8
|
+
|
|
9
|
+
const testFiles = ['transaction.test.js']
|
|
10
|
+
|
|
11
|
+
function cleanupTestDatabases() {
|
|
12
|
+
try {
|
|
13
|
+
const testDir = __dirname
|
|
14
|
+
const files = fs.readdirSync(testDir)
|
|
15
|
+
|
|
16
|
+
// Remove all test database files (*.sqlite, *.sqlite-wal, *.sqlite-shm)
|
|
17
|
+
const dbFiles = files.filter((file) => {
|
|
18
|
+
return file.match(/\.(sqlite|sqlite-wal|sqlite-shm)$/)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
dbFiles.forEach((file) => {
|
|
22
|
+
const filePath = path.join(testDir, file)
|
|
23
|
+
fs.unlinkSync(filePath)
|
|
24
|
+
console.log(`๐๏ธ Cleaned up: ${file}`)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
if (dbFiles.length === 0) {
|
|
28
|
+
console.log('๐งน No test database files to clean up')
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.warn(
|
|
32
|
+
'โ ๏ธ Warning: Failed to clean up test database files:',
|
|
33
|
+
error.message
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function runTest(testFile) {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
const testPath = path.join(__dirname, testFile)
|
|
41
|
+
const child = spawn('node', ['--test', testPath], {
|
|
42
|
+
stdio: 'inherit'
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
child.on('close', (code) => {
|
|
46
|
+
if (code === 0) {
|
|
47
|
+
resolve()
|
|
48
|
+
} else {
|
|
49
|
+
reject(new Error(`Test ${testFile} failed with code ${code}`))
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
child.on('error', reject)
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function runAllTests() {
|
|
58
|
+
console.log('๐งช Running sails-sqlite adapter tests...\n')
|
|
59
|
+
|
|
60
|
+
// Clean up any leftover database files before starting
|
|
61
|
+
console.log('๐งน Cleaning up any existing test database files...')
|
|
62
|
+
cleanupTestDatabases()
|
|
63
|
+
|
|
64
|
+
for (const testFile of testFiles) {
|
|
65
|
+
console.log(`\n๐ Running ${testFile}...`)
|
|
66
|
+
try {
|
|
67
|
+
await runTest(testFile)
|
|
68
|
+
console.log(`โ
${testFile} passed`)
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error(`โ ${testFile} failed:`, error.message)
|
|
71
|
+
// Clean up before exiting
|
|
72
|
+
console.log('\n๐งน Cleaning up test database files after failure...')
|
|
73
|
+
cleanupTestDatabases()
|
|
74
|
+
process.exit(1)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
console.log('\n๐ All tests passed!')
|
|
79
|
+
|
|
80
|
+
// Clean up after successful test run
|
|
81
|
+
console.log('\n๐งน Cleaning up test database files...')
|
|
82
|
+
cleanupTestDatabases()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
runAllTests().catch((error) => {
|
|
86
|
+
console.error('โ Test runner failed:', error)
|
|
87
|
+
process.exit(1)
|
|
88
|
+
})
|
package/tests/runner.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run integration tests
|
|
3
|
+
*
|
|
4
|
+
* Uses the `waterline-adapter-tests` module to
|
|
5
|
+
* run mocha tests against the appropriate version
|
|
6
|
+
* of Waterline. Only the interfaces explicitly
|
|
7
|
+
* declared in this adapter's `package.json` file
|
|
8
|
+
* are tested. (e.g. `queryable`, `semantic`, etc.)
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Module dependencies
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
var util = require('util')
|
|
16
|
+
var TestRunner = require('waterline-adapter-tests')
|
|
17
|
+
var Adapter = require('../')
|
|
18
|
+
|
|
19
|
+
// Grab targeted interfaces from this adapter's `package.json` file:
|
|
20
|
+
var package = {}
|
|
21
|
+
var interfaces = []
|
|
22
|
+
var features = []
|
|
23
|
+
try {
|
|
24
|
+
package = require('../package.json')
|
|
25
|
+
interfaces = package.waterlineAdapter.interfaces
|
|
26
|
+
features = package.waterlineAdapter.features
|
|
27
|
+
} catch (e) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
'\n' +
|
|
30
|
+
'Could not read supported interfaces from `waterlineAdapter.interfaces`' +
|
|
31
|
+
'\n' +
|
|
32
|
+
"in this adapter's `package.json` file ::" +
|
|
33
|
+
'\n' +
|
|
34
|
+
util.inspect(e)
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
console.log('Testing `' + package.name + '`, a Sails/Waterline adapter.')
|
|
39
|
+
console.log(
|
|
40
|
+
'Running `waterline-adapter-tests` against ' +
|
|
41
|
+
interfaces.length +
|
|
42
|
+
' interfaces...'
|
|
43
|
+
)
|
|
44
|
+
console.log('( ' + interfaces.join(', ') + ' )')
|
|
45
|
+
console.log()
|
|
46
|
+
console.log('Latest draft of Waterline adapter interface spec:')
|
|
47
|
+
console.log(
|
|
48
|
+
'http://sailsjs.com/documentation/concepts/extending-sails/adapters'
|
|
49
|
+
)
|
|
50
|
+
console.log()
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Integration Test Runner
|
|
54
|
+
*
|
|
55
|
+
* Uses the `waterline-adapter-tests` module to
|
|
56
|
+
* run mocha tests against the specified interfaces
|
|
57
|
+
* of the currently-implemented Waterline adapter API.
|
|
58
|
+
*/
|
|
59
|
+
new TestRunner({
|
|
60
|
+
// Mocha opts
|
|
61
|
+
mocha: {
|
|
62
|
+
bail: true
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
// Load the adapter module.
|
|
66
|
+
adapter: Adapter,
|
|
67
|
+
|
|
68
|
+
// Default connection config to use.
|
|
69
|
+
config: {
|
|
70
|
+
url: '.tmp/test-db.sqlite',
|
|
71
|
+
schema: false
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
// The set of adapter interfaces to test against.
|
|
75
|
+
// (grabbed these from this adapter's package.json file above)
|
|
76
|
+
interfaces: interfaces,
|
|
77
|
+
|
|
78
|
+
// The set of adapter features to test against.
|
|
79
|
+
// (grabbed these from this adapter's package.json file above)
|
|
80
|
+
features: features
|
|
81
|
+
|
|
82
|
+
// Most databases implement 'semantic' and 'queryable'.
|
|
83
|
+
//
|
|
84
|
+
// As of Sails/Waterline v0.10, the 'associations' interface
|
|
85
|
+
// is also available. If you don't implement 'associations',
|
|
86
|
+
// it will be polyfilled for you by Waterline core. The core
|
|
87
|
+
// implementation will always be used for cross-adapter / cross-connection
|
|
88
|
+
// joins.
|
|
89
|
+
//
|
|
90
|
+
// In future versions of Sails/Waterline, 'queryable' may be also
|
|
91
|
+
// be polyfilled by core.
|
|
92
|
+
//
|
|
93
|
+
// These polyfilled implementations can usually be further optimized at the
|
|
94
|
+
// adapter level, since most databases provide optimizations for internal
|
|
95
|
+
// operations.
|
|
96
|
+
//
|
|
97
|
+
// Full interface reference:
|
|
98
|
+
// https://github.com/balderdashy/sails-docs/blob/master/adapter-specification.md
|
|
99
|
+
})
|