forj 0.0.8 → 0.0.10

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.0.8",
4
+ "version": "0.0.10",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
7
7
  "files": ["src"],
@@ -53,6 +53,9 @@ export default class SchemaBuilder {
53
53
  if (column.length && !column.type.includes('('))
54
54
  sql += `(${column.length})`
55
55
 
56
+ if (column.primary)
57
+ sql += ' PRIMARY KEY'
58
+
56
59
  if (column.autoIncrement)
57
60
  sql += ' AUTOINCREMENT'
58
61
 
@@ -68,9 +71,9 @@ export default class SchemaBuilder {
68
71
  if (column.default !== undefined) {
69
72
  if (column.default === null) {
70
73
  sql += ' DEFAULT NULL'
71
- } else if (typeof column.default === 'string') {
74
+ } else if (typeof column.default == 'string') {
72
75
  sql += ` DEFAULT '${column.default}'`
73
- } else if (typeof column.default === 'boolean') {
76
+ } else if (typeof column.default == 'boolean') {
74
77
  sql += ` DEFAULT ${column.default ? 1 : 0}`
75
78
  } else {
76
79
  sql += ` DEFAULT ${column.default}`
@@ -80,9 +83,6 @@ export default class SchemaBuilder {
80
83
  if (column.unique)
81
84
  sql += ' UNIQUE'
82
85
 
83
- if (column.primary)
84
- sql += ' PRIMARY KEY'
85
-
86
86
  // if (column.comment)
87
87
  // sql += ` COMMENT '${column.comment.replace(/'/g, "''")}'`
88
88
 
@@ -8,8 +8,8 @@ import { MigrationInfo, MigrationClass, Queue } from './types'
8
8
  const __root = resolve(dirname(new URL(import.meta.url).pathname), '../../../..')
9
9
 
10
10
  export class Migrator {
11
- static #input = join(__root, 'migrations')
12
- static #output = join(__root, 'migrations', 'sql')
11
+ static #input: string
12
+ static #output: string
13
13
  static #createPatterns = [
14
14
  /^create_(\w+)_table$/,
15
15
  /^create_(\w+)$/,
@@ -19,6 +19,16 @@ export class Migrator {
19
19
  /.+_(to|from|in)_(\w+)$/,
20
20
  ]
21
21
 
22
+ static {
23
+ this.dir()
24
+ }
25
+
26
+ static dir(dir?: string) {
27
+ this.#input = join(__root, 'migrations', dir || '')
28
+ this.#output = join(this.#input, 'sql')
29
+ return this
30
+ }
31
+
22
32
  static inputDir(dir: string) {
23
33
  this.#input = join(__root, dir)
24
34
  return this
@@ -31,7 +41,7 @@ export class Migrator {
31
41
  static async queue() {
32
42
  this.#ensureDir(this.#input)
33
43
  const files = await glob(join(this.#input, '/*.{ts,js}'))
34
- const list: Queue = {'pending': [], 'migrated': []}
44
+ const list: Queue = {pending: [], migrated: []}
35
45
 
36
46
  for (const file of files) {
37
47
  if (file.includes('.d.')) continue