Skip to content
This repository was archived by the owner on Apr 19, 2020. It is now read-only.

Commit 3c6932d

Browse files
committed
Initial commit
0 parents  commit 3c6932d

25 files changed

+8167
-0
lines changed

.bilirc.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
type Config = import('bili').Config
2+
3+
const config: Config = {
4+
input: ['src/index.ts'],
5+
output: {
6+
dir: 'lib',
7+
format: ['cjs', 'esm']
8+
}
9+
}
10+
11+
export default config

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Build directories
2+
lib

.eslintrc.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
extends: [
3+
'standard-with-typescript',
4+
'plugin:prettier/recommended',
5+
'prettier/standard',
6+
'prettier/@typescript-eslint'
7+
],
8+
parserOptions: {
9+
project: './tsconfig.json',
10+
createDefaultProgram: true
11+
},
12+
rules: {
13+
'@typescript-eslint/camelcase': 'warn',
14+
'@typescript-eslint/consistent-type-definitions': 'off',
15+
'@typescript-eslint/no-empty-interface': 'warn',
16+
'@typescript-eslint/no-non-null-assertion': 'warn',
17+
'@typescript-eslint/promise-function-async': 'off',
18+
'@typescript-eslint/require-array-sort-compare': 'off',
19+
'@typescript-eslint/require-await': 'warn',
20+
'@typescript-eslint/strict-boolean-expressions': 'off'
21+
}
22+
}

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Build directories
9+
lib
10+
11+
# Dependency directories
12+
node_modules
13+
14+
# Output of 'npm pack'
15+
*.tgz
16+
17+
# dotenv files
18+
.env
19+
20+
# Others
21+
coverage
22+
package-lock.json
23+
*.local
24+
__fs__

.huskyrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const tasks = taskList => taskList.join(' && ')
2+
3+
module.exports = {
4+
hooks: {
5+
'pre-commit': tasks(['lint-staged', 'pretty-quick --staged'])
6+
}
7+
}

.lintstagedrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
'src/**/*.ts': () => 'tsc -p tsconfig.json --noEmit',
3+
'src/**/*.ts': ['eslint']
4+
}

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Build directories
2+
lib

.prettierrc.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
endOfLine: 'lf',
3+
semi: false,
4+
singleQuote: true
5+
}

.travis.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: node_js
2+
node_js:
3+
- lts/carbon
4+
cache:
5+
directories:
6+
- node_modules
7+
install:
8+
- yarn
9+
script:
10+
- jest --ci --coverage
11+
after_success:
12+
- npx codecov

CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Changelog
2+
3+
## [Unreleased]
4+
5+
- ...
6+
7+
## 0.1.0 - 2020-02-19
8+
9+
- Initial release
10+
11+
[unreleased]: https://github.com/Synor/database-sqlite/compare/0.1.0...HEAD

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Munif Tanjim
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 all
13+
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 THE
21+
SOFTWARE.

README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[![Synor Database](https://img.shields.io/badge/synor-database-blue?style=for-the-badge)](https://github.com/Synor)
2+
[![Version](https://img.shields.io/npm/v/@synor/database-sqlite?style=for-the-badge)](https://npmjs.org/package/@synor/database-sqlite)
3+
[![Test](https://img.shields.io/travis/com/Synor/database-sqlite/master?label=Test&style=for-the-badge)](https://travis-ci.com/Synor/database-sqlite)
4+
[![Coverage](https://img.shields.io/codecov/c/gh/Synor/database-sqlite/master?style=for-the-badge)](https://codecov.io/gh/Synor/database-sqlite)
5+
[![License](https://img.shields.io/github/license/Synor/database-sqlite?style=for-the-badge)](https://github.com/Synor/database-sqlite/blob/master/LICENSE)
6+
7+
# Synor Database SQLite
8+
9+
Synor Database Engine - SQLite
10+
11+
## Installation
12+
13+
```sh
14+
# using yarn:
15+
yarn add @synor/database-sqlite
16+
17+
# using npm:
18+
npm install --save @synor/database-sqlite
19+
```
20+
21+
## URI
22+
23+
**Format**: `sqlite://[.]/path[?param=value&...]`
24+
25+
**Params**:
26+
27+
| Name | Description | Default Value |
28+
| ------------------------------ | -------------------------------------------------------------------- | ------------------------ |
29+
| `schema` | SQLite Schema name | `main` |
30+
| `synor_migration_record_table` | Name for Migration Record Table | `synor_migration_record` |
31+
| `file_must_exist` | Error will be thrown if the database file does not exist | `false` |
32+
| `memory` | Open an in-memory database, rather than a disk-bound one | `false` |
33+
| `readonly` | Open the database connection in readonly mode | `false` |
34+
| `timeout` | Number of milliseconds to wait before throwing a `SQLITE_BUSY` error | `5000` |
35+
36+
**Examples**:
37+
38+
- `sqlite:///path/to/sqlite.db` (Absolute path)
39+
- `sqlite://./path/to/sqlite.db` (Relative path)
40+
- `sqlite://?memory=false` (Open an in-memory database)
41+
42+
## License
43+
44+
Licensed under the MIT License. Check the [LICENSE](./LICENSE) file for details.

jest.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: './jest.env.js'
4+
}

jest.env.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const { execSync } = require('child_process')
2+
const NodeEnvironment = require('jest-environment-node')
3+
const path = require('path')
4+
5+
class SynorDatabaseSQLiteTestEnvironment extends NodeEnvironment {
6+
constructor(config, context) {
7+
super(config, context)
8+
this.docblockPragmas = context.docblockPragmas
9+
}
10+
11+
async setup() {
12+
await super.setup()
13+
14+
execSync(`mkdir -p ${path.resolve('__fs__')}`)
15+
}
16+
17+
async teardown() {
18+
await super.teardown()
19+
}
20+
21+
runScript(script) {
22+
return super.runScript(script)
23+
}
24+
}
25+
26+
module.exports = SynorDatabaseSQLiteTestEnvironment

package.json

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"name": "@synor/database-sqlite",
3+
"version": "0.0.0",
4+
"description": "Synor Database Engine - SQLite",
5+
"keywords": [
6+
"synor",
7+
"synor-database",
8+
"sqlite",
9+
"sqlite3"
10+
],
11+
"homepage": "https://github.com/Synor/database-sqlite#readme",
12+
"bugs": "https://github.com/Synor/database-sqlite/issues",
13+
"license": "MIT",
14+
"author": "Munif Tanjim (https://muniftanjim.dev)",
15+
"files": [
16+
"lib"
17+
],
18+
"main": "lib/index.js",
19+
"module": "lib/index.esm.js",
20+
"types": "lib/index.d.ts",
21+
"repository": "https://github.com/Synor/database-sqlite",
22+
"scripts": {
23+
"prebuild": "npm run clean",
24+
"build": "bili",
25+
"clean": "rimraf lib/*",
26+
"prepack": "npm run build",
27+
"test": "jest"
28+
},
29+
"dependencies": {
30+
"better-sqlite3": "^5.4.3",
31+
"connection-string": "^3.1.1",
32+
"debug": "^4.1.1"
33+
},
34+
"devDependencies": {
35+
"@synor/core": "^0.8.2",
36+
"@types/better-sqlite3": "^5.4.0",
37+
"@types/debug": "^4.1.5",
38+
"@types/jest": "^24.0.25",
39+
"@typescript-eslint/eslint-plugin": "^2.16.0",
40+
"@typescript-eslint/parser": "^2.16.0",
41+
"bili": "^4.8.1",
42+
"eslint": "^6.8.0",
43+
"eslint-config-prettier": "^6.9.0",
44+
"eslint-config-standard-with-typescript": "^11.0.1",
45+
"eslint-plugin-import": "^2.20.0",
46+
"eslint-plugin-node": "^11.0.0",
47+
"eslint-plugin-prettier": "^3.1.2",
48+
"eslint-plugin-promise": "^4.2.1",
49+
"eslint-plugin-standard": "^4.0.1",
50+
"husky": "^3.0.9",
51+
"jest": "^24.9.0",
52+
"lint-staged": "^9.4.2",
53+
"prettier": "^1.18.2",
54+
"pretty-quick": "^2.0.0",
55+
"rimraf": "^3.0.2",
56+
"rollup-plugin-typescript2": "^0.26.0",
57+
"ts-jest": "^24.3.0",
58+
"ts-node": "^8.5.4",
59+
"typescript": "^3.7.4"
60+
},
61+
"peerDependencies": {
62+
"@synor/core": "^0.8.2"
63+
},
64+
"publishConfig": {
65+
"access": "public"
66+
}
67+
}

src/__mocks__/perf_hooks.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const perfHooks = jest.genMockFromModule('perf_hooks')
2+
3+
perfHooks.performance.now = jest.fn().mockImplementation(() => 0)
4+
5+
module.exports = perfHooks

src/__snapshots__/index.test.ts.snap

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`methods records 2`] = `
4+
Array [
5+
Object {
6+
"appliedAt": "2020-01-01T00:00:00.000Z",
7+
"appliedBy": "Synor",
8+
"dirty": false,
9+
"executionTime": 0,
10+
"hash": "",
11+
"id": 1,
12+
"title": "Base Migration",
13+
"type": "do",
14+
"version": "0",
15+
},
16+
Object {
17+
"appliedAt": "2020-01-01T00:00:00.000Z",
18+
"appliedBy": "Jest",
19+
"dirty": false,
20+
"executionTime": 0,
21+
"hash": "hash-01-do",
22+
"id": 2,
23+
"title": "Test One",
24+
"type": "do",
25+
"version": "01",
26+
},
27+
Object {
28+
"appliedAt": "2020-01-01T00:00:00.000Z",
29+
"appliedBy": "Jest",
30+
"dirty": true,
31+
"executionTime": 0,
32+
"hash": "hash-01-undo",
33+
"id": 3,
34+
"title": "Test One",
35+
"type": "undo",
36+
"version": "01",
37+
},
38+
]
39+
`;
40+
41+
exports[`methods repair 2`] = `
42+
Array [
43+
Object {
44+
"applied_at": "2020-01-01T00:00:00.000Z",
45+
"applied_by": "Synor",
46+
"dirty": 0,
47+
"execution_time": 0,
48+
"hash": "",
49+
"id": 1,
50+
"title": "Base Migration",
51+
"type": "do",
52+
"version": "0",
53+
},
54+
Object {
55+
"applied_at": "2020-01-01T00:00:00.000Z",
56+
"applied_by": "Jest",
57+
"dirty": 0,
58+
"execution_time": 0,
59+
"hash": "hash-01-do-repaired",
60+
"id": 2,
61+
"title": "Test One",
62+
"type": "do",
63+
"version": "01",
64+
},
65+
]
66+
`;
67+
68+
exports[`methods run 2`] = `
69+
Array [
70+
Object {
71+
"applied_at": "2020-01-01T00:00:00.000Z",
72+
"applied_by": "Synor",
73+
"dirty": 0,
74+
"execution_time": 0,
75+
"hash": "",
76+
"id": 1,
77+
"title": "Base Migration",
78+
"type": "do",
79+
"version": "0",
80+
},
81+
Object {
82+
"applied_at": "2020-01-01T00:00:00.000Z",
83+
"applied_by": "Jest",
84+
"dirty": 0,
85+
"execution_time": 0,
86+
"hash": "hash-01-do",
87+
"id": 2,
88+
"title": "Test One",
89+
"type": "do",
90+
"version": "01",
91+
},
92+
Object {
93+
"applied_at": "2020-01-01T00:00:00.000Z",
94+
"applied_by": "Jest",
95+
"dirty": 1,
96+
"execution_time": 0,
97+
"hash": "hash-01-undo",
98+
"id": 3,
99+
"title": "Test One",
100+
"type": "undo",
101+
"version": "01",
102+
},
103+
]
104+
`;

0 commit comments

Comments
 (0)