velocious 1.0.3 → 1.0.5
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/dependabot.yml +1 -1
- package/README.md +7 -1
- package/bin/velocious.mjs +2 -2
- package/index.mjs +1 -21
- package/package.json +3 -1
- package/peak_flow.yml +1 -1
- package/spec/cli/commands/db/create-spec.mjs +1 -1
- package/spec/database/connection/drivers/mysql/query-parser-spec.mjs +6 -5
- package/spec/database/drivers/mysql/connection-spec.mjs +2 -3
- package/spec/dummy/index.mjs +6 -4
- package/spec/dummy/src/config/configuration.example.mjs +5 -3
- package/spec/dummy/src/config/configuration.peakflow.mjs +5 -3
- package/spec/dummy/src/models/task.mjs +2 -2
- package/spec/http-server/client-spec.mjs +5 -0
- package/src/application.mjs +5 -0
- package/src/cli/base-command.mjs +1 -1
- package/src/cli/commands/db/migrate.mjs +52 -5
- package/src/cli/commands/destroy/migration.mjs +1 -1
- package/src/cli/commands/generate/migration.mjs +1 -1
- package/src/cli/commands/generate/model.mjs +36 -0
- package/src/cli/commands/init.mjs +1 -1
- package/src/cli/commands/server.mjs +15 -0
- package/src/cli/index.mjs +1 -0
- package/src/configuration-resolver.mjs +2 -2
- package/src/configuration.mjs +35 -19
- package/src/controller.mjs +1 -1
- package/src/database/drivers/base.mjs +41 -0
- package/src/database/drivers/sqlite/base.mjs +36 -0
- package/src/database/drivers/sqlite/index.native.mjs +54 -0
- package/src/database/drivers/sqlite/index.web.mjs +45 -0
- package/src/database/drivers/sqlite/query.web.mjs +9 -0
- package/src/database/drivers/sqlite/table.mjs +9 -0
- package/src/database/migrate-from-require-context.mjs +62 -0
- package/src/database/migration/index.mjs +1 -1
- package/src/database/migrator.mjs +73 -0
- package/src/database/pool/async-tracked-multi-connection.mjs +81 -0
- package/src/database/pool/base.mjs +60 -0
- package/src/database/pool/single-multi-use.mjs +40 -0
- package/src/database/query/create-database-base.mjs +3 -1
- package/src/database/query/insert-base.mjs +4 -0
- package/src/database/query-parser/options.mjs +2 -2
- package/src/database/record/index.mjs +2 -2
- package/src/http-server/worker-handler/index.mjs +2 -1
- package/src/http-server/worker-handler/worker-thread.mjs +0 -1
- package/src/routes/app-routes.mjs +10 -0
- package/src/routes/resolver.mjs +1 -1
- package/src/templates/configuration.mjs +6 -4
- package/src/templates/generate-migration.mjs +2 -2
- package/src/templates/generate-model.mjs +4 -0
- package/src/templates/routes.mjs +1 -1
- package/src/database/drivers/index.mjs +0 -5
- package/src/database/drivers/sqlite/sql/create-database.mjs +0 -4
- package/src/database/drivers/sqlite-expo/index.mjs +0 -100
- package/src/database/index.mjs +0 -15
- package/src/database/migrator/index.mjs +0 -15
- package/src/database/pool/index.mjs +0 -112
- /package/src/database/drivers/{sqlite-expo/query.mjs → sqlite/query.native.mjs} +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import Base from "./base"
|
|
2
|
+
import {digg} from "diggerize"
|
|
3
|
+
import escapeString from "sql-string-escape"
|
|
4
|
+
import Options from "../sqlite/options.mjs"
|
|
5
|
+
import query from "./query"
|
|
6
|
+
import * as SQLite from "expo-sqlite"
|
|
7
|
+
|
|
8
|
+
export default class VelociousDatabaseDriversSqliteNative extends Base {
|
|
9
|
+
async connect() {
|
|
10
|
+
const connection = await SQLite.openDatabaseAsync(digg(this.getArgs(), "name"))
|
|
11
|
+
|
|
12
|
+
this.connection = connection
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
disconnect() {
|
|
16
|
+
this.connection.end()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
connectArgs() {
|
|
20
|
+
const args = this.getArgs()
|
|
21
|
+
const connectArgs = []
|
|
22
|
+
const forward = ["database", "host", "password"]
|
|
23
|
+
|
|
24
|
+
for (const forwardValue of forward) {
|
|
25
|
+
if (forwardValue in args) connectArgs[forwardValue] = digg(args, forwardValue)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if ("username" in args) connectArgs["user"] = args["username"]
|
|
29
|
+
|
|
30
|
+
return connectArgs
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async close() {
|
|
34
|
+
await this.connection.end()
|
|
35
|
+
this.connection = undefined
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
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
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import Base from "./base.mjs"
|
|
2
|
+
import {digg} from "diggerize"
|
|
3
|
+
import Options from "../sqlite/options.mjs"
|
|
4
|
+
import query from "./query"
|
|
5
|
+
|
|
6
|
+
import initSqlJs from "sql.js"
|
|
7
|
+
|
|
8
|
+
export default class VelociousDatabaseDriversSqliteWeb extends Base {
|
|
9
|
+
async connect() {
|
|
10
|
+
const SQL = await initSqlJs({
|
|
11
|
+
// Required to load the wasm binary asynchronously. Of course, you can host it wherever you want you can omit locateFile completely when running in Node.
|
|
12
|
+
locateFile: (file) => `https://sql.js.org/dist/${file}`
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const databaseContent = localStorage.getItem(this.localStorageName())
|
|
16
|
+
|
|
17
|
+
this.connection = new SQL.Database(databaseContent)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
localStorageName = () => `VelociousDatabaseDriversSqliteWeb---${digg(this.getArgs(), "name")}`
|
|
21
|
+
disconnect = () => this.saveDatabase()
|
|
22
|
+
saveDatabase = () => localStorage.setItem(this.localStorageName(), this.connection.export())
|
|
23
|
+
|
|
24
|
+
async close() {
|
|
25
|
+
this.saveDatabase()
|
|
26
|
+
await this.connection.end()
|
|
27
|
+
this.connection = undefined
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
query = async (sql) => await query(this.connection, sql)
|
|
31
|
+
|
|
32
|
+
quote(string) {
|
|
33
|
+
if (!this.connection) throw new Error("Can't escape before connected")
|
|
34
|
+
|
|
35
|
+
return this.connection.escape(string)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
options() {
|
|
39
|
+
if (!this._options) {
|
|
40
|
+
this._options = new Options({driver: this})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return this._options
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import Configuration from "../configuration.mjs"
|
|
2
|
+
import * as inflection from "inflection"
|
|
3
|
+
import Migrator from "./migrator"
|
|
4
|
+
|
|
5
|
+
export default class VelociousDatabaseMigrateFromRequireContext {
|
|
6
|
+
constructor(configuration) {
|
|
7
|
+
this.configuration = configuration || Configuration.current()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async execute(requireContext) {
|
|
11
|
+
const migrator = new Migrator({configuration: this.configuration})
|
|
12
|
+
|
|
13
|
+
await migrator.prepare()
|
|
14
|
+
|
|
15
|
+
const files = requireContext.keys()
|
|
16
|
+
.map((file) => {
|
|
17
|
+
const match = file.match(/^\.\/(\d{14})-(.+)\.mjs$/)
|
|
18
|
+
|
|
19
|
+
if (!match) return null
|
|
20
|
+
|
|
21
|
+
const date = parseInt(match[1])
|
|
22
|
+
const migrationName = match[2]
|
|
23
|
+
const migrationClassName = inflection.camelize(migrationName)
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
file,
|
|
27
|
+
date,
|
|
28
|
+
migrationClassName
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
.filter((migration) => Boolean(migration))
|
|
32
|
+
.sort((migration1, migration2) => migration1.date - migration2.date)
|
|
33
|
+
|
|
34
|
+
for (const migration of files) {
|
|
35
|
+
if (!migrator.hasRunMigrationVersion(migration.date)) {
|
|
36
|
+
await this.runMigrationFile(migration, requireContext)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async runMigrationFile(migration, requireContext) {
|
|
42
|
+
if (!this.configuration) throw new Error("No configuration set")
|
|
43
|
+
if (!this.configuration.isDatabasePoolInitialized()) await this.configuration.initializeDatabasePool()
|
|
44
|
+
|
|
45
|
+
await this.configuration.getDatabasePool().withConnection(async (db) => {
|
|
46
|
+
const MigrationClass = requireContext(migration.file).default
|
|
47
|
+
const migrationInstance = new MigrationClass({
|
|
48
|
+
configuration: this.configuration
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
if (migrationInstance.change) {
|
|
52
|
+
await migrationInstance.change()
|
|
53
|
+
} else if (migrationInstance.up) {
|
|
54
|
+
await migrationInstance.up()
|
|
55
|
+
} else {
|
|
56
|
+
throw new Error(`'change' or 'up' didn't exist on migration: ${migration.file}`)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
await db.insert({tableName: "schema_migrations", data: {version: migration.date}})
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -10,7 +10,7 @@ export default class VelociousDatabaseMigration {
|
|
|
10
10
|
|
|
11
11
|
callback(tableData)
|
|
12
12
|
|
|
13
|
-
const databasePool = this.configuration.
|
|
13
|
+
const databasePool = this.configuration.getDatabasePool()
|
|
14
14
|
const sql = databasePool.createTableSql(tableData)
|
|
15
15
|
|
|
16
16
|
await databasePool.query(sql)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {digg} from "diggerize"
|
|
2
|
+
import TableData from "./table-data/index"
|
|
3
|
+
|
|
4
|
+
export default class VelociousDatabaseMigrator {
|
|
5
|
+
constructor({configuration}) {
|
|
6
|
+
this.configuration = configuration
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async prepare() {
|
|
10
|
+
const exists = await this.migrationsTableExist()
|
|
11
|
+
|
|
12
|
+
if (!exists) await this.createMigrationsTable()
|
|
13
|
+
|
|
14
|
+
await this.loadMigrationsVersions()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async createMigrationsTable() {
|
|
18
|
+
const schemaMigrationsTable = new TableData("schema_migrations", {ifNotExists: true})
|
|
19
|
+
|
|
20
|
+
schemaMigrationsTable.string("version", {null: false, primaryKey: true})
|
|
21
|
+
|
|
22
|
+
await this.configuration.getDatabasePool().withConnection(async (db) => {
|
|
23
|
+
const createSchemaMigrationsTableSql = db.createTableSql(schemaMigrationsTable)
|
|
24
|
+
|
|
25
|
+
await db.query(createSchemaMigrationsTableSql)
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
hasRunMigrationVersion(version) {
|
|
30
|
+
if (!this.migrationsVersions) {
|
|
31
|
+
throw new Error("Migrations versions hasn't been loaded yet")
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (version in this.migrationsVersions) {
|
|
35
|
+
return true
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async loadMigrationsVersions() {
|
|
42
|
+
const db = this.configuration.getDatabasePool()
|
|
43
|
+
|
|
44
|
+
this.migrationsVersions = {}
|
|
45
|
+
|
|
46
|
+
await db.withConnection(async () => {
|
|
47
|
+
const rows = await db.select("schema_migrations")
|
|
48
|
+
|
|
49
|
+
for (const row of rows) {
|
|
50
|
+
const version = digg(row, "version")
|
|
51
|
+
|
|
52
|
+
this.migrationsVersions[version] = true
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async migrationsTableExist() {
|
|
58
|
+
let exists = false
|
|
59
|
+
|
|
60
|
+
await this.configuration.getDatabasePool().withConnection(async (db) => {
|
|
61
|
+
const tables = await db.getTables()
|
|
62
|
+
|
|
63
|
+
for (const table of tables) {
|
|
64
|
+
if (table.getName() == "schema_migrations") {
|
|
65
|
+
exists = true
|
|
66
|
+
break
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
return exists
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {AsyncLocalStorage} from "async_hooks"
|
|
2
|
+
import BasePool from "./base.mjs"
|
|
3
|
+
|
|
4
|
+
let idSeq = 0
|
|
5
|
+
|
|
6
|
+
export default class VelociousDatabasePoolAsyncTrackedMultiConnection extends BasePool {
|
|
7
|
+
static current() {
|
|
8
|
+
if (!this.velociousDatabasePoolAsyncTrackedMultiConnection) {
|
|
9
|
+
this.velociousDatabasePoolAsyncTrackedMultiConnection = new VelociousDatabasePoolAsyncTrackedMultiConnection()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return this.velociousDatabasePoolAsyncTrackedMultiConnection
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
constructor(args = {}) {
|
|
16
|
+
super(args)
|
|
17
|
+
this.connections = []
|
|
18
|
+
this.connectionsInUse = {}
|
|
19
|
+
this.asyncLocalStorage = new AsyncLocalStorage()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
checkin = (connection) => {
|
|
23
|
+
const id = connection.getIdSeq()
|
|
24
|
+
|
|
25
|
+
if (id in this.connectionsInUse) {
|
|
26
|
+
delete this.connectionsInUse[id]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
connection.setIdSeq(undefined)
|
|
30
|
+
|
|
31
|
+
this.connections.push(connection)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async checkout() {
|
|
35
|
+
let connection = this.connections.shift()
|
|
36
|
+
|
|
37
|
+
if (!connection) {
|
|
38
|
+
connection = await this.spawnConnection()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (connection.getIdSeq() !== undefined) throw new Error(`Connection already has an ID-seq - is it in use? ${connection.getIdSeq()}`)
|
|
42
|
+
|
|
43
|
+
const id = idSeq++
|
|
44
|
+
|
|
45
|
+
connection.setIdSeq(id)
|
|
46
|
+
this.connectionsInUse[id] = connection
|
|
47
|
+
|
|
48
|
+
return connection
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
setCurrent() {
|
|
52
|
+
this.constructor.velociousDatabasePoolAsyncTrackedMultiConnection = this
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async withConnection(callback) {
|
|
56
|
+
const connection = await this.checkout()
|
|
57
|
+
const id = connection.getIdSeq()
|
|
58
|
+
|
|
59
|
+
await this.asyncLocalStorage.run(id, async () => {
|
|
60
|
+
try {
|
|
61
|
+
await callback(connection)
|
|
62
|
+
} finally {
|
|
63
|
+
this.checkin(connection)
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getCurrentConnection() {
|
|
69
|
+
const id = this.asyncLocalStorage.getStore()
|
|
70
|
+
|
|
71
|
+
if (id === undefined) {
|
|
72
|
+
throw new Error("ID hasn't been set for this async context")
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!(id in this.connectionsInUse)) {
|
|
76
|
+
throw new Error(`Connection ${id} doesn't exist any more - has it been checked in again?`)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return this.connectionsInUse[id]
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import Configuration from "../../configuration.mjs"
|
|
2
|
+
import {digg} from "diggerize"
|
|
3
|
+
|
|
4
|
+
class VelociousDatabasePoolBase {
|
|
5
|
+
constructor(args = {}) {
|
|
6
|
+
this.configuration = args.configuration || Configuration.current()
|
|
7
|
+
this.connections = []
|
|
8
|
+
this.connectionsInUse = {}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
getConfiguration = () => digg(this, "configuration", "database", "default", "master")
|
|
12
|
+
|
|
13
|
+
setDriverClass(driverClass) {
|
|
14
|
+
this.driverClass = driverClass
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async spawnConnection() {
|
|
18
|
+
const defaultConfig = this.getConfiguration()
|
|
19
|
+
const connection = await this.spawnConnectionWithConfiguration(defaultConfig)
|
|
20
|
+
|
|
21
|
+
return connection
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async spawnConnectionWithConfiguration(config) {
|
|
25
|
+
const DriverClass = config.driver || this.driverClass
|
|
26
|
+
|
|
27
|
+
if (!DriverClass) throw new Error("No driver class set in database pool or in given config")
|
|
28
|
+
|
|
29
|
+
const connection = new DriverClass(config)
|
|
30
|
+
|
|
31
|
+
await connection.connect()
|
|
32
|
+
|
|
33
|
+
return connection
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const forwardMethods = [
|
|
38
|
+
"createTable",
|
|
39
|
+
"createTableSql",
|
|
40
|
+
"delete",
|
|
41
|
+
"deleteSql",
|
|
42
|
+
"getTables",
|
|
43
|
+
"insert",
|
|
44
|
+
"insertSql",
|
|
45
|
+
"query",
|
|
46
|
+
"quote",
|
|
47
|
+
"select",
|
|
48
|
+
"update",
|
|
49
|
+
"updateSql"
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
for (const forwardMethod of forwardMethods) {
|
|
53
|
+
VelociousDatabasePoolBase.prototype[forwardMethod] = function(...args) {
|
|
54
|
+
const connection = this.getCurrentConnection()
|
|
55
|
+
|
|
56
|
+
return connection[forwardMethod](...args)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default VelociousDatabasePoolBase
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import BasePool from "./base.mjs"
|
|
2
|
+
|
|
3
|
+
export default class VelociousDatabasePoolSingleMultiUser extends BasePool {
|
|
4
|
+
static current() {
|
|
5
|
+
if (!this.velociousDatabasePoolSingleMultiUser) {
|
|
6
|
+
this.velociousDatabasePoolSingleMultiUser = new VelociousDatabasePoolSingleMultiUser()
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return this.velociousDatabasePoolSingleMultiUser
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
checkin = (connection) => {
|
|
13
|
+
// Do nothing
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async checkout() {
|
|
17
|
+
if (!this.connection) {
|
|
18
|
+
this.connection = await this.spawnConnection()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return this.connection
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
setCurrent() {
|
|
25
|
+
this.constructor.velociousDatabasePoolSingleMultiUser = this
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async withConnection(callback) {
|
|
29
|
+
await this.checkout() // Ensure a connection is present
|
|
30
|
+
await callback(this.connection)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
getCurrentConnection() {
|
|
34
|
+
if (!this.connection) {
|
|
35
|
+
throw new Error("A connection hasn't been made yet")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return this.connection
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {digs} from "diggerize"
|
|
1
2
|
import QueryBase from "./base.mjs"
|
|
2
3
|
|
|
3
4
|
export default class VelociousDatabaseQueryCreateDatabaseBase extends QueryBase {
|
|
@@ -9,11 +10,12 @@ export default class VelociousDatabaseQueryCreateDatabaseBase extends QueryBase
|
|
|
9
10
|
|
|
10
11
|
toSql() {
|
|
11
12
|
const {databaseName} = this
|
|
13
|
+
const {tableQuote} = digs(this.getOptions(), "tableQuote")
|
|
12
14
|
let sql = "CREATE DATABASE"
|
|
13
15
|
|
|
14
16
|
if (this.ifNotExists) sql += " IF NOT EXISTS"
|
|
15
17
|
|
|
16
|
-
sql += ` ${databaseName}`
|
|
18
|
+
sql += ` ${tableQuote}${databaseName}${tableQuote}`
|
|
17
19
|
|
|
18
20
|
return sql
|
|
19
21
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export default class VelociousDatabaseQueryInsertBase {
|
|
2
2
|
constructor({driver, tableName, data}) {
|
|
3
|
+
if (!driver) throw new Error("No driver given to insert base")
|
|
4
|
+
if (!tableName) throw new Error(`Invalid table name given to insert base: ${tableName}`)
|
|
5
|
+
if (!data) throw new Error("No data given to insert base")
|
|
6
|
+
|
|
3
7
|
this.data = data
|
|
4
8
|
this.driver = driver
|
|
5
9
|
this.tableName = tableName
|
|
@@ -11,13 +11,13 @@ export default class VelociousDatabaseQueryParserOptions {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
quoteColumnName(columnName) {
|
|
14
|
-
if (columnName.includes(this.columnQuote)) throw new Error(`Invalid column name: ${columnName}`)
|
|
14
|
+
if (!columnName || columnName.includes(this.columnQuote)) throw new Error(`Invalid column name: ${columnName}`)
|
|
15
15
|
|
|
16
16
|
return `${this.columnQuote}${columnName}${this.columnQuote}`
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
quoteTableName(tableName) {
|
|
20
|
-
if (tableName.includes(this.tableQuote)) throw new Error(`Invalid table name: ${tableName}`)
|
|
20
|
+
if (!tableName || tableName.includes(this.tableQuote)) throw new Error(`Invalid table name: ${tableName}`)
|
|
21
21
|
|
|
22
22
|
return `${this.tableQuote}${tableName}${this.tableQuote}`
|
|
23
23
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Configuration from "../../configuration.mjs"
|
|
2
2
|
import Handler from "../handler.mjs"
|
|
3
3
|
import inflection from "inflection"
|
|
4
4
|
import Query from "../query/index.mjs"
|
|
@@ -6,7 +6,7 @@ import RecordNotFoundError from "./record-not-found-error.mjs"
|
|
|
6
6
|
|
|
7
7
|
export default class VelociousDatabaseRecord {
|
|
8
8
|
static connection() {
|
|
9
|
-
const connection =
|
|
9
|
+
const connection = Configuration.current().getDatabasePoolType().current().getCurrentConnection()
|
|
10
10
|
|
|
11
11
|
if (!connection) throw new Error("No connection?")
|
|
12
12
|
|
|
@@ -13,7 +13,8 @@ export default class VelociousHttpServerWorker {
|
|
|
13
13
|
|
|
14
14
|
async start() {
|
|
15
15
|
return new Promise((resolve) => {
|
|
16
|
-
const {debug
|
|
16
|
+
const {debug} = digs(this.configuration, "debug")
|
|
17
|
+
const directory = this.configuration.getDirectory()
|
|
17
18
|
const __filename = fileURLToPath(import.meta.url)
|
|
18
19
|
const __dirname = dirname(__filename)
|
|
19
20
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Application from "../../application.mjs"
|
|
2
2
|
import Client from "../client/index.mjs"
|
|
3
|
-
import DatabasePool from "../../database/pool/index.mjs"
|
|
4
3
|
import {digg, digs} from "diggerize"
|
|
5
4
|
import errorLogger from "../../error-logger.mjs"
|
|
6
5
|
import logger from "../../logger.mjs"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {digg} from "diggerize"
|
|
2
|
+
|
|
3
|
+
export default class VelociousRoutesAppRoutes {
|
|
4
|
+
static async getRoutes(configuration) {
|
|
5
|
+
// Every client need to make their own routes because they probably can't be shared across different worker threads
|
|
6
|
+
const routesImport = await import(`${configuration.getDirectory()}/src/config/routes.mjs`)
|
|
7
|
+
|
|
8
|
+
return digg(routesImport, "default", "routes")
|
|
9
|
+
}
|
|
10
|
+
}
|
package/src/routes/resolver.mjs
CHANGED
|
@@ -21,7 +21,7 @@ export default class VelociousRoutesResolver {
|
|
|
21
21
|
if (!matchResult) throw new Error(`Couldn't match a route with the given path: ${currentPath}`)
|
|
22
22
|
|
|
23
23
|
if (this.params.action && this.params.controller) {
|
|
24
|
-
const controllerPath = `${
|
|
24
|
+
const controllerPath = `${this.configuration.getDirectory()}/src/routes/${digg(this, "params", "controller")}/controller.mjs`
|
|
25
25
|
const controllerClassImport = await import(controllerPath)
|
|
26
26
|
const controllerClass = controllerClassImport.default
|
|
27
27
|
const controllerInstance = new controllerClass({
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import AsyncTrackedMultiConnection from "velocious/src/database/pool/async-tracked-multi-connection.mjs"
|
|
2
|
+
import Configuration from "velocious/src/configuration.mjs"
|
|
3
|
+
import MysqlDriver from "velocious/src/database/drivers/mysql/index.mjs"
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
export default new Configuration({
|
|
4
6
|
database: {
|
|
5
7
|
default: {
|
|
6
8
|
master: {
|
|
9
|
+
driver: MysqlDriver,
|
|
10
|
+
poolType: AsyncTrackedMultiConnection,
|
|
7
11
|
type: "mysql",
|
|
8
12
|
host: "mariadb",
|
|
9
13
|
username: "username",
|
|
@@ -13,5 +17,3 @@ const configuration = new Configuration({
|
|
|
13
17
|
}
|
|
14
18
|
}
|
|
15
19
|
})
|
|
16
|
-
|
|
17
|
-
export default configuration
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Migration from "velocious/src/database/migration/index.mjs"
|
|
2
2
|
|
|
3
|
-
export default class __MIGRATION_NAME__ extends
|
|
3
|
+
export default class __MIGRATION_NAME__ extends Migration {
|
|
4
4
|
async up() {
|
|
5
5
|
await this.connection().execute("...")
|
|
6
6
|
}
|
package/src/templates/routes.mjs
CHANGED