velocious 1.0.5 → 1.0.7
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/bin/{velocious.mjs → velocious.js} +1 -1
- package/package.json +7 -5
- package/peak_flow.yml +1 -1
- package/spec/cli/commands/db/{create-spec.mjs → create-spec.js} +3 -3
- package/spec/cli/commands/db/{migrate-spec.mjs → migrate-spec.js} +4 -2
- package/spec/cli/commands/destroy/{migration-spec.mjs → migration-spec.js} +2 -2
- package/spec/cli/commands/generate/{migration-spec.mjs → migration-spec.js} +3 -3
- package/spec/cli/commands/{init-spec.mjs → init-spec.js} +6 -6
- package/spec/cli/commands/test/{test-files-finder-spec.mjs → test-files-finder-spec.js} +2 -2
- package/spec/database/connection/drivers/mysql/{query-parser-spec.mjs → query-parser-spec.js} +6 -6
- package/spec/database/drivers/mysql/{connection-spec.mjs → connection-spec.js} +2 -2
- package/spec/database/record/create-spec.js +23 -0
- package/spec/database/record/{destroy-spec.mjs → destroy-spec.js} +2 -2
- package/spec/database/record/{find-spec.mjs → find-spec.js} +2 -3
- package/spec/database/record/query-spec.js +37 -0
- package/spec/database/record/{update-spec.mjs → update-spec.js} +2 -2
- package/spec/dummy/{index.mjs → index.js} +16 -4
- package/spec/dummy/src/config/configuration.example.js +36 -0
- package/spec/dummy/src/config/configuration.peakflow.js +37 -0
- package/spec/dummy/src/config/{routes.mjs → routes.js} +1 -1
- package/spec/dummy/src/database/migrations/{20230728075328-create-projects.mjs → 20230728075328-create-projects.js} +1 -2
- package/spec/dummy/src/database/migrations/{20230728075329-create-tasks.mjs → 20230728075329-create-tasks.js} +1 -2
- package/spec/dummy/src/database/migrations/20250605133926-create-project-translations.js +16 -0
- package/spec/dummy/src/models/project.js +9 -0
- package/spec/dummy/src/models/task.js +8 -0
- package/spec/dummy/src/routes/tasks/{controller.mjs → controller.js} +2 -2
- package/spec/http-server/{client-spec.mjs → client-spec.js} +3 -3
- package/spec/http-server/{get-spec.mjs → get-spec.js} +1 -1
- package/spec/http-server/{post-spec.mjs → post-spec.js} +2 -2
- package/spec/support/jasmine.json +2 -2
- package/src/{application.mjs → application.js} +3 -3
- package/src/big-brother.js +37 -0
- package/src/cli/commands/db/{create.mjs → create.js} +9 -7
- package/src/cli/commands/db/{migrate.mjs → migrate.js} +4 -5
- package/src/cli/commands/destroy/{migration.mjs → migration.js} +2 -2
- package/src/cli/commands/generate/{migration.mjs → migration.js} +5 -5
- package/src/cli/commands/generate/{model.mjs → model.js} +5 -5
- package/src/cli/commands/{init.mjs → init.js} +6 -6
- package/src/cli/commands/{server.mjs → server.js} +1 -1
- package/src/cli/commands/test/{index.mjs → index.js} +3 -3
- package/src/cli/commands/test/{test-files-finder.mjs → test-files-finder.js} +1 -1
- package/src/cli/{index.mjs → index.js} +4 -4
- package/src/{configuration-resolver.mjs → configuration-resolver.js} +2 -2
- package/src/{configuration.mjs → configuration.js} +39 -3
- package/src/database/drivers/{base.mjs → base.js} +23 -4
- package/src/database/drivers/mysql/column.js +8 -0
- package/src/database/drivers/mysql/{index.mjs → index.js} +44 -12
- package/src/database/drivers/{sqlite/options.mjs → mysql/options.js} +2 -1
- package/src/database/drivers/mysql/query-parser.js +4 -0
- package/src/database/drivers/mysql/sql/{create-database.mjs → create-database.js} +1 -1
- package/src/database/drivers/{sqlite/sql/create-table.mjs → mysql/sql/create-table.js} +1 -1
- package/src/database/drivers/mysql/sql/{delete.mjs → delete.js} +1 -1
- package/src/database/drivers/{sqlite/sql/insert.mjs → mysql/sql/insert.js} +1 -1
- package/src/database/drivers/mysql/sql/{update.mjs → update.js} +1 -1
- package/src/database/drivers/mysql/table.js +25 -0
- package/src/database/drivers/sqlite/base.js +108 -0
- package/src/database/drivers/sqlite/column.js +10 -0
- package/src/database/drivers/sqlite/{index.native.mjs → index.native.js} +19 -22
- package/src/database/drivers/sqlite/index.web.js +55 -0
- package/src/database/drivers/{mysql/options.mjs → sqlite/options.js} +3 -2
- package/src/database/drivers/sqlite/query-parser.js +4 -0
- package/src/database/drivers/sqlite/query.native.js +24 -0
- package/src/database/drivers/sqlite/query.web.js +34 -0
- package/src/database/drivers/sqlite/sql/create-index.js +4 -0
- package/src/database/drivers/{mysql/sql/create-table.mjs → sqlite/sql/create-table.js} +1 -1
- package/src/database/drivers/sqlite/sql/{delete.mjs → delete.js} +1 -1
- package/src/database/drivers/{mysql/sql/insert.mjs → sqlite/sql/insert.js} +1 -1
- package/src/database/drivers/sqlite/sql/{update.mjs → update.js} +1 -1
- package/src/database/drivers/sqlite/table.js +24 -0
- package/src/database/initializer-from-require-context.js +21 -0
- package/src/database/{migrate-from-require-context.mjs → migrate-from-require-context.js} +2 -2
- package/src/database/migration/index.js +50 -0
- package/src/database/{migrator.mjs → migrator.js} +4 -2
- package/src/database/pool/{async-tracked-multi-connection.mjs → async-tracked-multi-connection.js} +1 -1
- package/src/database/pool/{base.mjs → base.js} +6 -1
- package/src/database/pool/{single-multi-use.mjs → single-multi-use.js} +1 -1
- package/src/database/query/{base.mjs → base.js} +2 -1
- package/src/database/query/{create-database-base.mjs → create-database-base.js} +1 -1
- package/src/database/query/create-index-base.js +50 -0
- package/src/database/query/create-table-base.js +92 -0
- package/src/database/query/{delete-base.mjs → delete-base.js} +1 -1
- package/src/database/query/{from-plain.mjs → from-plain.js} +1 -1
- package/src/database/query/{from-table.mjs → from-table.js} +1 -1
- package/src/database/query/index.js +206 -0
- package/src/database/query/{join-plain.mjs → join-plain.js} +1 -1
- package/src/database/query/{order-plain.mjs → order-plain.js} +1 -1
- package/src/database/query/preloader/belongs-to.js +52 -0
- package/src/database/query/preloader/has-many.js +55 -0
- package/src/database/query/preloader.js +41 -0
- package/src/database/query/{select-plain.mjs → select-plain.js} +1 -1
- package/src/database/query/{select-table-and-column.mjs → select-table-and-column.js} +1 -1
- package/src/database/query/where-base.js +9 -0
- package/src/database/query/where-hash.js +35 -0
- package/src/database/query/where-plain.js +13 -0
- package/src/database/query-parser/base-query-parser.js +33 -0
- package/src/database/query-parser/group-parser.js +40 -0
- package/src/database/query-parser/joins-parser.js +71 -0
- package/src/database/query-parser/limit-parser.js +40 -0
- package/src/database/query-parser/{options.mjs → options.js} +2 -1
- package/src/database/query-parser/order-parser.js +39 -0
- package/src/database/query-parser/{select-parser.mjs → select-parser.js} +5 -1
- package/src/database/query-parser/where-parser.js +39 -0
- package/src/database/record/index.js +622 -0
- package/src/database/record/instance-relationships/base.js +28 -0
- package/src/database/record/instance-relationships/belongs-to.js +20 -0
- package/src/database/record/instance-relationships/has-many.js +47 -0
- package/src/database/record/relationships/base.js +32 -0
- package/src/database/record/relationships/belongs-to.js +12 -0
- package/src/database/record/relationships/has-many.js +12 -0
- package/src/database/table-data/{index.mjs → index.js} +15 -25
- package/src/http-server/client/{index.mjs → index.js} +3 -3
- package/src/http-server/client/request-buffer/{index.mjs → index.js} +4 -4
- package/src/http-server/client/{request-parser.mjs → request-parser.js} +2 -2
- package/src/http-server/client/{request-runner.mjs → request-runner.js} +3 -3
- package/src/http-server/client/{request.mjs → request.js} +1 -1
- package/src/http-server/{index.mjs → index.js} +3 -3
- package/src/http-server/{server-client.mjs → server-client.js} +1 -1
- package/src/http-server/worker-handler/{index.mjs → index.js} +2 -2
- package/src/http-server/worker-handler/{worker-script.mjs → worker-script.js} +1 -1
- package/src/http-server/worker-handler/{worker-thread.mjs → worker-thread.js} +12 -9
- package/src/routes/{app-routes.mjs → app-routes.js} +1 -1
- package/src/routes/{base-route.mjs → base-route.js} +2 -2
- package/src/routes/{get-route.mjs → get-route.js} +1 -1
- package/src/routes/{index.mjs → index.js} +1 -1
- package/src/routes/{resolver.mjs → resolver.js} +1 -1
- package/src/routes/{resource-route.mjs → resource-route.js} +1 -1
- package/src/routes/{root-route.mjs → root-route.js} +1 -1
- package/src/templates/{configuration.mjs → configuration.js} +3 -3
- package/src/templates/{generate-migration.mjs → generate-migration.js} +1 -1
- package/src/templates/generate-model.js +6 -0
- package/src/templates/{routes.mjs → routes.js} +1 -1
- package/src/utils/rest-args-error.js +9 -0
- package/spec/database/record/create-spec.mjs +0 -14
- package/spec/dummy/src/config/configuration.example.mjs +0 -21
- package/spec/dummy/src/config/configuration.peakflow.mjs +0 -22
- package/spec/dummy/src/models/task.mjs +0 -4
- package/src/database/drivers/mysql/query-parser.mjs +0 -25
- package/src/database/drivers/sqlite/base.mjs +0 -36
- package/src/database/drivers/sqlite/index.web.mjs +0 -45
- package/src/database/drivers/sqlite/query-parser.mjs +0 -25
- package/src/database/drivers/sqlite/query.native.mjs +0 -9
- package/src/database/drivers/sqlite/query.web.mjs +0 -9
- package/src/database/drivers/sqlite/table.mjs +0 -9
- package/src/database/migration/index.mjs +0 -18
- package/src/database/query/create-table-base.mjs +0 -69
- package/src/database/query/index.mjs +0 -144
- package/src/database/query-parser/joins-parser.mjs +0 -30
- package/src/database/record/index.mjs +0 -187
- package/src/templates/generate-model.mjs +0 -4
- /package/{index.mjs → index.js} +0 -0
- /package/spec/dummy/{dummy-directory.mjs → dummy-directory.js} +0 -0
- /package/src/cli/{base-command.mjs → base-command.js} +0 -0
- /package/src/cli/commands/test/{test-runner.mjs → test-runner.js} +0 -0
- /package/src/{controller.mjs → controller.js} +0 -0
- /package/src/database/drivers/mysql/{connect-connection.mjs → connect-connection.js} +0 -0
- /package/src/database/drivers/mysql/{query.mjs → query.js} +0 -0
- /package/src/database/{handler.mjs → handler.js} +0 -0
- /package/src/database/query/{from-base.mjs → from-base.js} +0 -0
- /package/src/database/query/{insert-base.mjs → insert-base.js} +0 -0
- /package/src/database/query/{join-base.mjs → join-base.js} +0 -0
- /package/src/database/query/{order-base.mjs → order-base.js} +0 -0
- /package/src/database/query/{select-base.mjs → select-base.js} +0 -0
- /package/src/database/query/{update-base.mjs → update-base.js} +0 -0
- /package/src/database/query-parser/{from-parser.mjs → from-parser.js} +0 -0
- /package/src/database/record/{record-not-found-error.mjs → record-not-found-error.js} +0 -0
- /package/src/{error-logger.mjs → error-logger.js} +0 -0
- /package/src/http-server/client/{params-to-object.mjs → params-to-object.js} +0 -0
- /package/src/http-server/client/request-buffer/{form-data-part.mjs → form-data-part.js} +0 -0
- /package/src/http-server/client/request-buffer/{header.mjs → header.js} +0 -0
- /package/src/http-server/client/{response.mjs → response.js} +0 -0
- /package/src/{logger.mjs → logger.js} +0 -0
- /package/src/spec/{index.mjs → index.js} +0 -0
- /package/src/utils/{file-exists.mjs → file-exists.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import BaseCommand from "../../base-command.
|
|
1
|
+
import BaseCommand from "../../base-command.js"
|
|
2
2
|
import fs from "node:fs/promises"
|
|
3
3
|
|
|
4
4
|
export default class DbDestroyMigration extends BaseCommand {
|
|
@@ -9,7 +9,7 @@ export default class DbDestroyMigration extends BaseCommand {
|
|
|
9
9
|
const destroyed = []
|
|
10
10
|
|
|
11
11
|
for (const migrationFile of migrationFiles) {
|
|
12
|
-
const match = migrationFile.match(/^(\d{14})-(.+)\.
|
|
12
|
+
const match = migrationFile.match(/^(\d{14})-(.+)\.js$/)
|
|
13
13
|
|
|
14
14
|
if (!match) {
|
|
15
15
|
continue
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import BaseCommand from "../../base-command.
|
|
1
|
+
import BaseCommand from "../../base-command.js"
|
|
2
2
|
import {dirname} from "path"
|
|
3
3
|
import {fileURLToPath} from "url"
|
|
4
|
-
import fileExists from "../../../utils/file-exists.
|
|
4
|
+
import fileExists from "../../../utils/file-exists.js"
|
|
5
5
|
import fs from "node:fs/promises"
|
|
6
|
-
import inflection from "inflection"
|
|
6
|
+
import * as inflection from "inflection"
|
|
7
7
|
import strftime from "strftime"
|
|
8
8
|
|
|
9
9
|
export default class DbGenerateMigration extends BaseCommand {
|
|
@@ -12,10 +12,10 @@ export default class DbGenerateMigration extends BaseCommand {
|
|
|
12
12
|
const migrationNameCamelized = inflection.camelize(migrationName.replaceAll("-", "_"))
|
|
13
13
|
const date = new Date()
|
|
14
14
|
const migrationNumber = strftime("%Y%m%d%H%M%S")
|
|
15
|
-
const migrationFileName = `${migrationNumber}-${migrationName}.
|
|
15
|
+
const migrationFileName = `${migrationNumber}-${migrationName}.js`
|
|
16
16
|
const __filename = fileURLToPath(`${import.meta.url}/../../..`)
|
|
17
17
|
const __dirname = dirname(__filename)
|
|
18
|
-
const templateFilePath = `${__dirname}/templates/generate-migration.
|
|
18
|
+
const templateFilePath = `${__dirname}/templates/generate-migration.js`
|
|
19
19
|
const migrationContentBuffer = await fs.readFile(templateFilePath)
|
|
20
20
|
const migrationContent = migrationContentBuffer.toString().replaceAll("__MIGRATION_NAME__", migrationNameCamelized)
|
|
21
21
|
const migrationDir = `${process.cwd()}/src/database/migrations`
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import BaseCommand from "../../base-command.
|
|
1
|
+
import BaseCommand from "../../base-command.js"
|
|
2
2
|
import {dirname} from "path"
|
|
3
3
|
import {fileURLToPath} from "url"
|
|
4
|
-
import fileExists from "../../../utils/file-exists.
|
|
4
|
+
import fileExists from "../../../utils/file-exists.js"
|
|
5
5
|
import fs from "node:fs/promises"
|
|
6
|
-
import inflection from "inflection"
|
|
6
|
+
import * as inflection from "inflection"
|
|
7
7
|
|
|
8
8
|
export default class DbGenerateModel extends BaseCommand {
|
|
9
9
|
async execute() {
|
|
10
10
|
const modelName = this.processArgs[1]
|
|
11
11
|
const modelNameCamelized = inflection.camelize(modelName.replaceAll("-", "_"))
|
|
12
12
|
const date = new Date()
|
|
13
|
-
const modelFileName = `${inflection.dasherize(inflection.underscore(modelName))}.
|
|
13
|
+
const modelFileName = `${inflection.dasherize(inflection.underscore(modelName))}.js`
|
|
14
14
|
const __filename = fileURLToPath(`${import.meta.url}/../../..`)
|
|
15
15
|
const __dirname = dirname(__filename)
|
|
16
|
-
const templateFilePath = `${__dirname}/templates/generate-model.
|
|
16
|
+
const templateFilePath = `${__dirname}/templates/generate-model.js`
|
|
17
17
|
const modelContentBuffer = await fs.readFile(templateFilePath)
|
|
18
18
|
const modelContent = modelContentBuffer.toString().replaceAll("__MODEL_NAME__", modelNameCamelized)
|
|
19
19
|
const modelsDir = `${process.cwd()}/src/models`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import BaseCommand from "../base-command.
|
|
1
|
+
import BaseCommand from "../base-command.js"
|
|
2
2
|
import {dirname} from "path"
|
|
3
|
-
import fileExists from "../../utils/file-exists.
|
|
3
|
+
import fileExists from "../../utils/file-exists.js"
|
|
4
4
|
import {fileURLToPath} from "url"
|
|
5
5
|
import fs from "node:fs/promises"
|
|
6
6
|
|
|
@@ -12,12 +12,12 @@ export default class VelociousCliCommandsInit extends BaseCommand {
|
|
|
12
12
|
const projectConfigPath = `${projectPath}/src/config`
|
|
13
13
|
const fileMappings = [
|
|
14
14
|
{
|
|
15
|
-
source: `${velocipusPath}/src/templates/configuration.
|
|
16
|
-
target: `${projectConfigPath}/configuration.
|
|
15
|
+
source: `${velocipusPath}/src/templates/configuration.js`,
|
|
16
|
+
target: `${projectConfigPath}/configuration.js`
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
|
-
source: `${velocipusPath}/src/templates/routes.
|
|
20
|
-
target: `${projectConfigPath}/routes.
|
|
19
|
+
source: `${velocipusPath}/src/templates/routes.js`,
|
|
20
|
+
target: `${projectConfigPath}/routes.js`
|
|
21
21
|
}
|
|
22
22
|
]
|
|
23
23
|
const paths = [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import BaseCommand from "../../base-command.
|
|
2
|
-
import TestFilesFinder from "./test-files-finder.
|
|
3
|
-
import TestRunner from "./test-runner.
|
|
1
|
+
import BaseCommand from "../../base-command.js"
|
|
2
|
+
import TestFilesFinder from "./test-files-finder.js"
|
|
3
|
+
import TestRunner from "./test-runner.js"
|
|
4
4
|
|
|
5
5
|
export default class VelociousCliCommandsInit extends BaseCommand {
|
|
6
6
|
async execute() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import configurationResolver from "../configuration-resolver.
|
|
1
|
+
import configurationResolver from "../configuration-resolver.js"
|
|
2
2
|
import {dirname} from "path"
|
|
3
3
|
import {fileURLToPath} from "url"
|
|
4
|
-
import fileExists from "../utils/file-exists.
|
|
4
|
+
import fileExists from "../utils/file-exists.js"
|
|
5
5
|
|
|
6
6
|
export default class VelociousCli {
|
|
7
7
|
constructor(args = {}) {
|
|
@@ -23,8 +23,8 @@ export default class VelociousCli {
|
|
|
23
23
|
filePath += `/${commandPart}`
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
filePaths.push(`${filePath}/index.
|
|
27
|
-
filePath += ".
|
|
26
|
+
filePaths.push(`${filePath}/index.js`)
|
|
27
|
+
filePath += ".js"
|
|
28
28
|
filePaths.push(filePath)
|
|
29
29
|
|
|
30
30
|
let fileFound
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Configuration from "./configuration.
|
|
1
|
+
import Configuration from "./configuration.js"
|
|
2
2
|
|
|
3
3
|
const configurationResolver = async (args) => {
|
|
4
4
|
if (Configuration.current(false)) {
|
|
@@ -6,7 +6,7 @@ const configurationResolver = async (args) => {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
const directory = args.directory || process.cwd()
|
|
9
|
-
const configurationPath = `${directory}/src/config/configuration.
|
|
9
|
+
const configurationPath = `${directory}/src/config/configuration.js`
|
|
10
10
|
let configuration
|
|
11
11
|
|
|
12
12
|
try {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {digg} from "diggerize"
|
|
2
|
+
import restArgsError from "./utils/rest-args-error.js"
|
|
2
3
|
|
|
3
4
|
export default class VelociousConfiguration {
|
|
4
5
|
static current(throwError = true) {
|
|
@@ -7,10 +8,19 @@ export default class VelociousConfiguration {
|
|
|
7
8
|
return this.velociousConfiguration
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
constructor({database, debug, directory}) {
|
|
11
|
+
constructor({database, debug, directory, initializeModels, locale, locales, ...restArgs}) {
|
|
12
|
+
restArgsError(restArgs)
|
|
13
|
+
|
|
14
|
+
if (!initializeModels) throw new Error("initializeModels wasn't given")
|
|
15
|
+
|
|
11
16
|
this.database = database
|
|
12
17
|
this.debug = debug
|
|
13
18
|
this._directory = directory
|
|
19
|
+
this._initializeModels = initializeModels
|
|
20
|
+
this._isInitialized = false
|
|
21
|
+
this.locale = locale
|
|
22
|
+
this.locales = locales
|
|
23
|
+
this.modelClasses = {}
|
|
14
24
|
}
|
|
15
25
|
|
|
16
26
|
getDatabasePool() {
|
|
@@ -39,6 +49,26 @@ export default class VelociousConfiguration {
|
|
|
39
49
|
return this._directory
|
|
40
50
|
}
|
|
41
51
|
|
|
52
|
+
getLocale() {
|
|
53
|
+
if (typeof this.locale == "function") {
|
|
54
|
+
return this.locale()
|
|
55
|
+
} else if (this.locale) {
|
|
56
|
+
return this.locale
|
|
57
|
+
} else {
|
|
58
|
+
return this.getLocales()[0]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getLocales = () => digg(this, "locales")
|
|
63
|
+
|
|
64
|
+
getModelClass(name) {
|
|
65
|
+
const modelClass = this.modelClasses[name]
|
|
66
|
+
|
|
67
|
+
if (!modelClass) throw new Error(`No such model class ${name} in ${Object.keys(this.modelClasses).join(", ")}}`)
|
|
68
|
+
|
|
69
|
+
return modelClass
|
|
70
|
+
}
|
|
71
|
+
|
|
42
72
|
initializeDatabasePool() {
|
|
43
73
|
if (!this.database) throw new Error("No 'database' was given")
|
|
44
74
|
if (this.databasePool) throw new Error("DatabasePool has already been initialized")
|
|
@@ -50,9 +80,15 @@ export default class VelociousConfiguration {
|
|
|
50
80
|
}
|
|
51
81
|
|
|
52
82
|
isDatabasePoolInitialized = () => Boolean(this.databasePool)
|
|
83
|
+
isInitialized = () => this._isInitialized
|
|
84
|
+
|
|
85
|
+
async initialize() {
|
|
86
|
+
await this._initializeModels({configuration: this})
|
|
87
|
+
this._isInitialized = true
|
|
88
|
+
}
|
|
53
89
|
|
|
54
|
-
|
|
55
|
-
|
|
90
|
+
registerModelClass(modelClass) {
|
|
91
|
+
this.modelClasses[modelClass.name] = modelClass
|
|
56
92
|
}
|
|
57
93
|
|
|
58
94
|
setCurrent() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Query from "../query/index.
|
|
2
|
-
import Handler from "../handler.
|
|
1
|
+
import Query from "../query/index.js"
|
|
2
|
+
import Handler from "../handler.js"
|
|
3
3
|
|
|
4
4
|
export default class VelociousDatabaseDriversBase {
|
|
5
5
|
constructor(args) {
|
|
@@ -7,9 +7,11 @@ export default class VelociousDatabaseDriversBase {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
async createTable(...args) {
|
|
10
|
-
const
|
|
10
|
+
const sqls = this.createTableSql(...args)
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
for (const sql of sqls) {
|
|
13
|
+
await this.query(sql)
|
|
14
|
+
}
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
async delete(...args) {
|
|
@@ -26,12 +28,29 @@ export default class VelociousDatabaseDriversBase {
|
|
|
26
28
|
return this.idSeq
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
getTables() {
|
|
32
|
+
throw new Error(`${this.constructor.name}#getTables not implemented`)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async getTableByName(name) {
|
|
36
|
+
const tables = await this.getTables()
|
|
37
|
+
const table = tables.find((table) => table.getName() == name)
|
|
38
|
+
|
|
39
|
+
if (!table) throw new Error(`Couldn't find a table by that name: ${name}`)
|
|
40
|
+
|
|
41
|
+
return table
|
|
42
|
+
}
|
|
43
|
+
|
|
29
44
|
async insert(...args) {
|
|
30
45
|
const sql = this.insertSql(...args)
|
|
31
46
|
|
|
32
47
|
await this.query(sql)
|
|
33
48
|
}
|
|
34
49
|
|
|
50
|
+
lastInsertID() {
|
|
51
|
+
throw new Error(`${this.constructor.name}#lastInsertID not implemented`)
|
|
52
|
+
}
|
|
53
|
+
|
|
35
54
|
async select(tableName) {
|
|
36
55
|
const handler = new Handler()
|
|
37
56
|
const query = new Query({
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import Base from "../base.
|
|
2
|
-
import connectConnection from "./connect-connection.
|
|
3
|
-
import CreateDatabase from "./sql/create-database.
|
|
4
|
-
import CreateTable from "./sql/create-table.
|
|
5
|
-
import Delete from "./sql/delete.
|
|
1
|
+
import Base from "../base.js"
|
|
2
|
+
import connectConnection from "./connect-connection.js"
|
|
3
|
+
import CreateDatabase from "./sql/create-database.js"
|
|
4
|
+
import CreateTable from "./sql/create-table.js"
|
|
5
|
+
import Delete from "./sql/delete.js"
|
|
6
6
|
import {digg} from "diggerize"
|
|
7
|
-
import Insert from "./sql/insert.
|
|
8
|
-
import Options from "./options.
|
|
7
|
+
import Insert from "./sql/insert.js"
|
|
8
|
+
import Options from "./options.js"
|
|
9
9
|
import mysql from "mysql"
|
|
10
|
-
import query from "./query.
|
|
11
|
-
import QueryParser from "./query-parser.
|
|
12
|
-
import
|
|
10
|
+
import query from "./query.js"
|
|
11
|
+
import QueryParser from "./query-parser.js"
|
|
12
|
+
import Table from "./table.js"
|
|
13
|
+
import Update from "./sql/update.js"
|
|
13
14
|
|
|
14
15
|
export default class VelociousDatabaseDriversMysql extends Base{
|
|
15
16
|
async connect() {
|
|
@@ -64,13 +65,25 @@ export default class VelociousDatabaseDriversMysql extends Base{
|
|
|
64
65
|
return new QueryParser({query}).toSql()
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
|
|
68
|
+
escape(string) {
|
|
68
69
|
if (!this.connection) throw new Error("Can't escape before connected")
|
|
69
70
|
|
|
70
71
|
return this.connection.escape(string)
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
|
|
74
|
+
quote(string) {
|
|
75
|
+
return `${this.escape(string)}`
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
quoteColumn = (string) => {
|
|
79
|
+
if (string.includes("`")) throw new Error(`Possible SQL injection in column name: ${string}`)
|
|
80
|
+
|
|
81
|
+
return `\`${string}\``
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
quoteTable = (string) => {
|
|
85
|
+
if (string.includes("`")) throw new Error(`Possible SQL injection in table name: ${string}`)
|
|
86
|
+
|
|
74
87
|
return `\`${string}\``
|
|
75
88
|
}
|
|
76
89
|
|
|
@@ -86,6 +99,25 @@ export default class VelociousDatabaseDriversMysql extends Base{
|
|
|
86
99
|
return insert.toSql()
|
|
87
100
|
}
|
|
88
101
|
|
|
102
|
+
async getTables() {
|
|
103
|
+
const result = await this.query("SHOW FULL TABLES")
|
|
104
|
+
const tables = []
|
|
105
|
+
|
|
106
|
+
for (const row of result) {
|
|
107
|
+
const table = new Table(this, row)
|
|
108
|
+
|
|
109
|
+
tables.push(table)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return tables
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async lastInsertID() {
|
|
116
|
+
const result = await this.query("SELECT LAST_INSERT_ID() AS last_insert_id")
|
|
117
|
+
|
|
118
|
+
return digg(result, 0, "last_insert_id")
|
|
119
|
+
}
|
|
120
|
+
|
|
89
121
|
options() {
|
|
90
122
|
if (!this._options) {
|
|
91
123
|
this._options = new Options({driver: this})
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import QueryParserOptions from "../../query-parser/options.
|
|
1
|
+
import QueryParserOptions from "../../query-parser/options.js"
|
|
2
2
|
|
|
3
3
|
export default class VelociousDatabaseDriversMysqlOptions extends QueryParserOptions {
|
|
4
4
|
constructor(options) {
|
|
5
5
|
options.columnQuote = "`"
|
|
6
|
+
options.indexQuote = "`"
|
|
6
7
|
options.stringQuote = "'"
|
|
7
8
|
options.tableQuote = "`"
|
|
8
9
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Column from "./column.js"
|
|
2
|
+
|
|
3
|
+
export default class VelociousDatabaseDriversMysqlTable {
|
|
4
|
+
constructor(driver, data) {
|
|
5
|
+
this.data = data
|
|
6
|
+
this.driver = driver
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async getColumns() {
|
|
10
|
+
const result = await this.driver.query(`SHOW FULL COLUMNS FROM \`${this.getName()}\``)
|
|
11
|
+
const columns = []
|
|
12
|
+
|
|
13
|
+
for (const data of result) {
|
|
14
|
+
const column = new Column(this, data)
|
|
15
|
+
|
|
16
|
+
columns.push(column)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return columns
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getName() {
|
|
23
|
+
return Object.values(this.data)[0]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {digg} from "diggerize"
|
|
2
|
+
|
|
3
|
+
import Base from "../base.js"
|
|
4
|
+
import CreateIndex from "../sqlite/sql/create-index.js"
|
|
5
|
+
import CreateTable from "../sqlite/sql/create-table.js"
|
|
6
|
+
import Delete from "../sqlite/sql/delete.js"
|
|
7
|
+
import escapeString from "sql-string-escape"
|
|
8
|
+
import Insert from "../sqlite/sql/insert.js"
|
|
9
|
+
import Options from "../sqlite/options.js"
|
|
10
|
+
import QueryParser from "../sqlite/query-parser.js"
|
|
11
|
+
import Table from "./table"
|
|
12
|
+
import Update from "../sqlite/sql/update.js"
|
|
13
|
+
|
|
14
|
+
export default class VelociousDatabaseDriversSqliteBase extends Base {
|
|
15
|
+
createIndexSql(indexData) {
|
|
16
|
+
const createArgs = Object.assign({driver: this}, indexData)
|
|
17
|
+
const createIndex = new CreateIndex(createArgs)
|
|
18
|
+
|
|
19
|
+
return createIndex.toSql()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
createTableSql(tableData) {
|
|
23
|
+
const createArgs = Object.assign({tableData, driver: this, indexInCreateTable: false})
|
|
24
|
+
const createTable = new CreateTable(createArgs)
|
|
25
|
+
|
|
26
|
+
return createTable.toSql()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
deleteSql = ({tableName, conditions}) => new Delete({conditions, driver: this, tableName}).toSql()
|
|
30
|
+
insertSql = ({tableName, data}) => new Insert({driver: this, tableName, data}).toSql()
|
|
31
|
+
|
|
32
|
+
async getTableByName(tableName) {
|
|
33
|
+
const result = await this.query(`SELECT name FROM sqlite_master WHERE type = 'table' AND name = ${this.quote(tableName)} LIMIT 1`)
|
|
34
|
+
const row = result[0]
|
|
35
|
+
|
|
36
|
+
if (!row) {
|
|
37
|
+
const tables = await this.getTables()
|
|
38
|
+
const tableNames = tables.map((table) => table.getName())
|
|
39
|
+
|
|
40
|
+
throw new Error(`No table by that name: ${tableName} in ${tableNames.join(", ")}`)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return new Table({driver: this, row})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async getTables() {
|
|
47
|
+
const result = await this.query("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name")
|
|
48
|
+
const tables = []
|
|
49
|
+
|
|
50
|
+
for (const row of result) {
|
|
51
|
+
const table = new Table({driver: this, row})
|
|
52
|
+
|
|
53
|
+
tables.push(table)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return tables
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async lastInsertID() {
|
|
60
|
+
const result = await this.query("SELECT LAST_INSERT_ROWID() AS last_insert_id")
|
|
61
|
+
|
|
62
|
+
return digg(result, 0, "last_insert_id")
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
options() {
|
|
66
|
+
if (!this._options) {
|
|
67
|
+
this._options = new Options({driver: this})
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return this._options
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
queryToSql = (query) => new QueryParser({query}).toSql()
|
|
74
|
+
|
|
75
|
+
escape(value) {
|
|
76
|
+
const type = typeof value
|
|
77
|
+
|
|
78
|
+
if (type != "string") value = `${value}`
|
|
79
|
+
|
|
80
|
+
const resultWithQuotes = escapeString(value)
|
|
81
|
+
const result = resultWithQuotes.substring(1, resultWithQuotes.length - 1)
|
|
82
|
+
|
|
83
|
+
return result
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
quote(value) {
|
|
87
|
+
const type = typeof value
|
|
88
|
+
|
|
89
|
+
if (type == "number") return value
|
|
90
|
+
if (type != "string") value = `${value}`
|
|
91
|
+
|
|
92
|
+
return escapeString(value)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
quoteColumn = (string) => {
|
|
96
|
+
if (string.includes("`")) throw new Error(`Possible SQL injection in column name: ${string}`)
|
|
97
|
+
|
|
98
|
+
return `\`${string}\``
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
quoteTable = (string) => {
|
|
102
|
+
if (string.includes("`")) throw new Error(`Possible SQL injection in table name: ${string}`)
|
|
103
|
+
|
|
104
|
+
return `\`${string}\``
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
updateSql = ({conditions, data, tableName}) => new Update({conditions, data, driver: this, tableName}).toSql()
|
|
108
|
+
}
|
|
@@ -1,19 +1,31 @@
|
|
|
1
|
-
import Base from "./base"
|
|
2
1
|
import {digg} from "diggerize"
|
|
3
|
-
import escapeString from "sql-string-escape"
|
|
4
|
-
import Options from "../sqlite/options.mjs"
|
|
5
2
|
import query from "./query"
|
|
6
3
|
import * as SQLite from "expo-sqlite"
|
|
7
4
|
|
|
5
|
+
import Base from "./base"
|
|
6
|
+
|
|
8
7
|
export default class VelociousDatabaseDriversSqliteNative extends Base {
|
|
9
8
|
async connect() {
|
|
10
|
-
const
|
|
9
|
+
const args = this.getArgs()
|
|
10
|
+
const databaseName = digg(args, "name")
|
|
11
|
+
|
|
12
|
+
if (args.reset) {
|
|
13
|
+
try {
|
|
14
|
+
await SQLite.deleteDatabaseAsync(databaseName)
|
|
15
|
+
} catch (error) {
|
|
16
|
+
if (error.message.match(/Database '(.+)' not found/)) {
|
|
17
|
+
// Ignore not found
|
|
18
|
+
} else {
|
|
19
|
+
throw error
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
11
23
|
|
|
12
|
-
this.connection =
|
|
24
|
+
this.connection = await SQLite.openDatabaseAsync(databaseName)
|
|
13
25
|
}
|
|
14
26
|
|
|
15
|
-
disconnect() {
|
|
16
|
-
this.connection.
|
|
27
|
+
async disconnect() {
|
|
28
|
+
await this.connection.closeAsync()
|
|
17
29
|
}
|
|
18
30
|
|
|
19
31
|
connectArgs() {
|
|
@@ -36,19 +48,4 @@ export default class VelociousDatabaseDriversSqliteNative extends Base {
|
|
|
36
48
|
}
|
|
37
49
|
|
|
38
50
|
query = async (sql) => await query(this.connection, sql)
|
|
39
|
-
|
|
40
|
-
quote(string) {
|
|
41
|
-
const type = typeof string
|
|
42
|
-
|
|
43
|
-
if (type == "number") return string
|
|
44
|
-
if (type != "string") string = `${string}`
|
|
45
|
-
|
|
46
|
-
return escapeString(string)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
options() {
|
|
50
|
-
if (!this._options) this._options = new Options({driver: this})
|
|
51
|
-
|
|
52
|
-
return this._options
|
|
53
|
-
}
|
|
54
51
|
}
|