forj 0.1.8 → 0.1.9
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "forj",
|
|
3
3
|
"description": "SQLite ORM and Query Builder whitout dependencies",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.9",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"files": ["src"],
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@aws-sdk/client-dynamodb": "^3.1003.0",
|
|
23
23
|
"@aws-sdk/lib-dynamodb": "^3.1003.0",
|
|
24
|
+
"pathe": "^2.0",
|
|
24
25
|
"pluralize": "^8.0",
|
|
25
26
|
"t0n": "^0.1.12",
|
|
26
27
|
"zod": "^4.3.6"
|
|
@@ -3,7 +3,11 @@ import { sqlName, tableSlug } from '../utils'
|
|
|
3
3
|
import type { ColumnDefinition, IndexDefinition, ForeignKeyDefinition } from './types'
|
|
4
4
|
|
|
5
5
|
export default class SchemaBuilder {
|
|
6
|
-
static create(
|
|
6
|
+
static create(
|
|
7
|
+
blueprint: Blueprint,
|
|
8
|
+
exist: boolean = false,
|
|
9
|
+
rowId: boolean = true
|
|
10
|
+
): string {
|
|
7
11
|
const table = sqlName(blueprint.table)
|
|
8
12
|
const columns = blueprint.columns
|
|
9
13
|
const indexes = blueprint.indexes
|
|
@@ -19,7 +23,9 @@ export default class SchemaBuilder {
|
|
|
19
23
|
...foreignKeyDefinitions
|
|
20
24
|
].filter(Boolean)
|
|
21
25
|
|
|
22
|
-
return `CREATE TABLE ${exist ? 'IF NOT EXISTS ' : ''}${table} (\n ${allDefinitions.join(',\n ')}\n)
|
|
26
|
+
return `CREATE TABLE ${exist ? 'IF NOT EXISTS ' : ''}${table} (\n ${allDefinitions.join(',\n ')}\n)${
|
|
27
|
+
rowId ? '' : ' WITHOUT ROWID'
|
|
28
|
+
};`
|
|
23
29
|
}
|
|
24
30
|
|
|
25
31
|
static alter(blueprint: Blueprint): string[] {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import glob from 'tiny-glob'
|
|
2
2
|
import { mkdirSync, existsSync, writeFileSync } from 'node:fs'
|
|
3
|
-
import { dirname, join
|
|
4
|
-
import { Datte, IMPORT } from 't0n'
|
|
3
|
+
import { dirname, join } from 'pathe'
|
|
4
|
+
import { Datte, Envir, IMPORT } from 't0n'
|
|
5
5
|
import { Schema } from './schema'
|
|
6
6
|
import { MigrationInfo, MigrationClass, Queue } from './types'
|
|
7
7
|
|
|
8
|
-
const
|
|
8
|
+
export const _forj = join(dirname(new URL(import.meta.url).pathname), '..')
|
|
9
|
+
export const _root = Envir.get('npm_config_local_prefix') || Envir.get('PWD') || join(_forj, '../../../')
|
|
9
10
|
|
|
10
11
|
export class Migrator {
|
|
11
12
|
static #input: string
|
|
@@ -24,17 +25,17 @@ export class Migrator {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
static dir(dir?: string) {
|
|
27
|
-
this.#input = join(
|
|
28
|
+
this.#input = join(_root, 'migrations', dir || '')
|
|
28
29
|
this.#output = join(this.#input, 'sql')
|
|
29
30
|
return this
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
static inputDir(dir: string) {
|
|
33
|
-
this.#input = join(
|
|
34
|
+
this.#input = join(_root, dir)
|
|
34
35
|
return this
|
|
35
36
|
}
|
|
36
37
|
static outputDir(dir: string) {
|
|
37
|
-
this.#output = join(
|
|
38
|
+
this.#output = join(_root, dir)
|
|
38
39
|
return this
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -88,7 +89,7 @@ export class Migrator {
|
|
|
88
89
|
if (!match) return null
|
|
89
90
|
const [, year, month, day, hour, minute, second, slugName] = match
|
|
90
91
|
|
|
91
|
-
const input = join(
|
|
92
|
+
const input = join(_root, fileName)
|
|
92
93
|
const output = join(this.#output, name +'.sql')
|
|
93
94
|
const mod = await IMPORT(input)
|
|
94
95
|
const handler = mod.default as MigrationClass
|
package/src/migrations/schema.ts
CHANGED
|
@@ -47,8 +47,8 @@ export class Schema {
|
|
|
47
47
|
return blueprint
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
static create(table: string, fn: BlueprintFn, exist: boolean = false) {
|
|
51
|
-
this.#addStatement(Builder.create(this.#blueprint(table, fn), exist))
|
|
50
|
+
static create(table: string, fn: BlueprintFn, exist: boolean = false, rowId: boolean = true) {
|
|
51
|
+
this.#addStatement(Builder.create(this.#blueprint(table, fn), exist, rowId))
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
static createIfNotExists(table: string, fn: BlueprintFn) {
|
|
@@ -66,7 +66,15 @@ export class Schema {
|
|
|
66
66
|
this.#addStatement(Builder.create(this.#blueprint(table, fn as BlueprintFn, (table: Blueprint) => {
|
|
67
67
|
columns.forEach(column => table.foreignId(column))
|
|
68
68
|
table.primary(table.columns.map(c => c.name))
|
|
69
|
-
})
|
|
69
|
+
}), false, false))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static createWithoutRowId(table: string, fn: BlueprintFn, exist: boolean = false) {
|
|
73
|
+
this.create(table, fn, false, false)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static createIfNotExistsWithoutRowId(table: string, fn: BlueprintFn) {
|
|
77
|
+
this.create(table, fn, true, false)
|
|
70
78
|
}
|
|
71
79
|
|
|
72
80
|
static table(table: string, fn: BlueprintFn) {
|