-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support browser and support sql.js driver (#386)
* feat: support browser * chore: update * chore: update * chore: export Raw directly * fix: remove useless import * feat: sql.js driver * feat: update tsconfig * test: 增加 sql.js 相关测试用例 * feat: implements for association * feat: follow sqlite condition * feat: test cases * fix: import performance from perf_hooks * test: add mocha -R dot * chore: update * fix: update after review * fix: lint-staged for .js and .ts * Update src/drivers/sqljs/sqljs-connection.ts Co-authored-by: JimmyDaddy <[email protected]> * chore: update gitignore * chore: update * feat: compile browser to dist * fix: update files * feat: remove assert * fix: 修复单测并增加 vscode 调试配置 --------- Co-authored-by: JimmyDaddy <[email protected]>
- Loading branch information
1 parent
7bb5cf2
commit ddcefbc
Showing
26 changed files
with
932 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'use strict'; | ||
|
||
const eslintConfig = { | ||
overrides: [], | ||
'parser': '@babel/eslint-parser', | ||
'parserOptions': { | ||
'sourceType': 'script', | ||
'ecmaVersion': 2020, | ||
'requireConfigFile': false | ||
}, | ||
'env': { | ||
'node': true, | ||
'es6': true | ||
}, | ||
'plugins': [ | ||
'no-only-tests' | ||
], | ||
'rules': { | ||
'curly': [2, 'multi-line'], | ||
'consistent-return': 0, | ||
'quotes': [2, 'single', { 'avoidEscape': true, 'allowTemplateLiterals': true }], | ||
'semi': [2, 'always'], | ||
'strict': ['error', 'safe'], | ||
'no-const-assign': 'error', | ||
'no-undef': 2, | ||
'no-underscore-dangle': 0, | ||
'no-use-before-define': [2, 'nofunc'], | ||
'no-unused-vars': [2, { 'vars': 'all', 'args': 'none', 'ignoreRestSiblings': true }], | ||
'no-shadow': 2, | ||
'keyword-spacing': 'error', | ||
'eol-last': 'error', | ||
'prefer-const': 'error', | ||
'no-only-tests/no-only-tests': 'error', | ||
'no-trailing-spaces': 'error', | ||
'space-before-blocks': 'error', | ||
'space-in-parens': 'error' | ||
} | ||
}; | ||
|
||
const tslintConfig = { | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended', | ||
], | ||
parser: '@typescript-eslint/parser', | ||
files: ['*.ts'], | ||
plugins: [ | ||
'@typescript-eslint', | ||
'no-only-tests', | ||
], | ||
rules: { | ||
...eslintConfig.rules, | ||
'@typescript-eslint/no-var-requires': 0, | ||
'@typescript-eslint/no-use-before-define': ['error'], | ||
strict: 0, | ||
'@typescript-eslint/ban-ts-comment': ['warn'], | ||
'no-shadow': 'off', | ||
'@typescript-eslint/no-shadow': ['warn'], | ||
'no-unused-vars': 'off', | ||
'@typescript-eslint/no-unused-vars': 'warn', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
}, | ||
}; | ||
|
||
eslintConfig.overrides.push(tslintConfig); | ||
|
||
module.exports = eslintConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,8 @@ test/models/photo.js* | |
src/decorators.js* | ||
src/data_types.js* | ||
src/raw.js* | ||
|
||
# Logs | ||
logs | ||
*.log | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npm run lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Mocha Current File", | ||
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", | ||
"args": [ | ||
"--timeout", | ||
"999999", | ||
"--colors", | ||
"${file}" | ||
], | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen", | ||
"preLaunchTask": "npm: pretest", | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Mocha All", | ||
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", | ||
"args": [ | ||
"--timeout", | ||
"999999", | ||
"--colors", | ||
"${workspaceFolder}/test" | ||
], | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen", | ||
"preLaunchTask": "npm: pretest", | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"type": "npm", | ||
"script": "pretest", | ||
"problemMatcher": [], | ||
"label": "npm: pretest", | ||
"detail": "tsc && ./test/prepare.sh", | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
} | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const Logger = require('./drivers/abstract/logger'); | ||
const Spell = require('./spell'); | ||
const Bone = require('./bone'); | ||
const Collection = require('./collection'); | ||
const { invokable: DataTypes, LENGTH_VARIANTS } = require('./data_types'); | ||
const sequelize = require('./adapters/sequelize'); | ||
const { heresql } = require('./utils/string'); | ||
|
||
const Realm = require('./realm/base'); | ||
const AbstractDriver = require('./drivers/abstract'); | ||
const { isBone } = require('./utils'); | ||
|
||
/** | ||
* @typedef {Object} RawSql | ||
* @property {boolean} __raw | ||
* @property {string} value | ||
* @property {string} type | ||
*/ | ||
|
||
|
||
/** | ||
* Connect models to database. Need to provide both connect options and models. | ||
* @alias module:index.connect | ||
* @param {Object} opts | ||
* @param {string} opts.client - client name | ||
* @param {string|Bone[]} opts.models - an array of models | ||
* @returns {Pool} the connection pool in case we need to perform raw query | ||
*/ | ||
export const connect = async function connect(opts) { | ||
opts = { Bone, ...opts }; | ||
if (opts.Bone.driver) throw new Error('connected already'); | ||
const realm = new Realm(opts); | ||
await realm.connect(); | ||
return realm; | ||
}; | ||
|
||
export const disconnect = async function disconnect(realm, ...args) { | ||
if (realm instanceof Realm && realm.connected) { | ||
return await realm.disconnect(...args); | ||
} | ||
}; | ||
|
||
Object.assign(Realm.prototype, { DataTypes }); | ||
export default Realm; | ||
|
||
export { Bone }; | ||
export { Collection }; | ||
export { DataTypes }; | ||
export { Logger }; | ||
export { Spell }; | ||
export { sequelize }; | ||
export { heresql }; | ||
export * from './hint'; | ||
export * from './decorators'; | ||
export { AbstractDriver }; | ||
export { default as Raw } from './raw'; | ||
export { LENGTH_VARIANTS }; | ||
export { isBone }; | ||
|
||
// TODO: missing migrations and MYSQL, PG, SQLITE drivers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.