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.
Files changed (48) hide show
  1. package/.github/FUNDING.yml +1 -0
  2. package/.github/workflows/prettier.yml +16 -0
  3. package/.github/workflows/test.yml +16 -0
  4. package/.husky/pre-commit +1 -0
  5. package/.prettierrc.js +5 -0
  6. package/CHANGELOG.md +161 -0
  7. package/LICENSE +21 -0
  8. package/README.md +247 -0
  9. package/lib/index.js +1104 -0
  10. package/lib/private/build-std-adapter-method.js +69 -0
  11. package/lib/private/constants/connection.input.js +15 -0
  12. package/lib/private/constants/dry-orm.input.js +23 -0
  13. package/lib/private/constants/meta.input.js +14 -0
  14. package/lib/private/constants/not-unique.exit.js +16 -0
  15. package/lib/private/constants/query.input.js +15 -0
  16. package/lib/private/constants/table-name.input.js +12 -0
  17. package/lib/private/machines/avg-records.js +74 -0
  18. package/lib/private/machines/begin-transaction.js +51 -0
  19. package/lib/private/machines/commit-transaction.js +50 -0
  20. package/lib/private/machines/count-records.js +78 -0
  21. package/lib/private/machines/create-each-record.js +163 -0
  22. package/lib/private/machines/create-manager.js +174 -0
  23. package/lib/private/machines/create-record.js +126 -0
  24. package/lib/private/machines/define-physical-model.js +111 -0
  25. package/lib/private/machines/destroy-manager.js +87 -0
  26. package/lib/private/machines/destroy-records.js +114 -0
  27. package/lib/private/machines/drop-physical-model.js +51 -0
  28. package/lib/private/machines/find-records.js +120 -0
  29. package/lib/private/machines/get-connection.js +54 -0
  30. package/lib/private/machines/join.js +259 -0
  31. package/lib/private/machines/lease-connection.js +58 -0
  32. package/lib/private/machines/private/build-sqlite-where-clause.js +91 -0
  33. package/lib/private/machines/private/compile-statement.js +334 -0
  34. package/lib/private/machines/private/generate-join-sql-query.js +385 -0
  35. package/lib/private/machines/private/process-each-record.js +106 -0
  36. package/lib/private/machines/private/process-native-error.js +104 -0
  37. package/lib/private/machines/private/process-native-record.js +104 -0
  38. package/lib/private/machines/private/reify-values-to-set.js +83 -0
  39. package/lib/private/machines/release-connection.js +70 -0
  40. package/lib/private/machines/rollback-transaction.js +50 -0
  41. package/lib/private/machines/set-physical-sequence.js +77 -0
  42. package/lib/private/machines/sum-records.js +75 -0
  43. package/lib/private/machines/update-records.js +162 -0
  44. package/lib/private/machines/verify-model-def.js +38 -0
  45. package/package.json +58 -5
  46. package/tests/index.js +88 -0
  47. package/tests/runner.js +99 -0
  48. 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
+ })
@@ -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
+ })