@ghom/orm 1.7.0 → 1.7.2
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/dist/cjs/app/table.js +6 -2
- package/dist/esm/app/table.js +6 -2
- package/dist/typings/app/orm.d.ts +1 -0
- package/dist/typings/app/table.d.ts +1 -0
- package/package.json +1 -1
- package/readme.md +30 -12
- package/src/app/orm.ts +1 -0
- package/src/app/table.ts +15 -2
package/dist/cjs/app/table.js
CHANGED
|
@@ -43,7 +43,9 @@ class Table {
|
|
|
43
43
|
throw new Error("missing ORM");
|
|
44
44
|
try {
|
|
45
45
|
await this.db.schema.createTable(this.options.name, this.options.setup);
|
|
46
|
-
this.orm.config.logger?.log(`created table ${chalk_1.default[this.orm.config.loggerColors?.highlight ?? "blueBright"](this.options.name)}
|
|
46
|
+
this.orm.config.logger?.log(`created table ${chalk_1.default[this.orm.config.loggerColors?.highlight ?? "blueBright"](this.options.name)}${this.options.description
|
|
47
|
+
? ` ${chalk_1.default[this.orm.config.loggerColors?.description ?? "grey"](this.options.description)}`
|
|
48
|
+
: ""}`);
|
|
47
49
|
}
|
|
48
50
|
catch (error) {
|
|
49
51
|
if (error.toString().includes("syntax error")) {
|
|
@@ -51,7 +53,9 @@ class Table {
|
|
|
51
53
|
throw error;
|
|
52
54
|
}
|
|
53
55
|
else {
|
|
54
|
-
this.orm.config.logger?.log(`loaded table ${chalk_1.default[this.orm.config.loggerColors?.highlight ?? "blueBright"](this.options.name)}
|
|
56
|
+
this.orm.config.logger?.log(`loaded table ${chalk_1.default[this.orm.config.loggerColors?.highlight ?? "blueBright"](this.options.name)}${this.options.description
|
|
57
|
+
? ` ${chalk_1.default[this.orm.config.loggerColors?.description ?? "grey"](this.options.description)}`
|
|
58
|
+
: ""}`);
|
|
55
59
|
}
|
|
56
60
|
}
|
|
57
61
|
try {
|
package/dist/esm/app/table.js
CHANGED
|
@@ -39,7 +39,9 @@ export class Table {
|
|
|
39
39
|
throw new Error("missing ORM");
|
|
40
40
|
try {
|
|
41
41
|
await this.db.schema.createTable(this.options.name, this.options.setup);
|
|
42
|
-
this.orm.config.logger?.log(`created table ${chalk[this.orm.config.loggerColors?.highlight ?? "blueBright"](this.options.name)}
|
|
42
|
+
this.orm.config.logger?.log(`created table ${chalk[this.orm.config.loggerColors?.highlight ?? "blueBright"](this.options.name)}${this.options.description
|
|
43
|
+
? ` ${chalk[this.orm.config.loggerColors?.description ?? "grey"](this.options.description)}`
|
|
44
|
+
: ""}`);
|
|
43
45
|
}
|
|
44
46
|
catch (error) {
|
|
45
47
|
if (error.toString().includes("syntax error")) {
|
|
@@ -47,7 +49,9 @@ export class Table {
|
|
|
47
49
|
throw error;
|
|
48
50
|
}
|
|
49
51
|
else {
|
|
50
|
-
this.orm.config.logger?.log(`loaded table ${chalk[this.orm.config.loggerColors?.highlight ?? "blueBright"](this.options.name)}
|
|
52
|
+
this.orm.config.logger?.log(`loaded table ${chalk[this.orm.config.loggerColors?.highlight ?? "blueBright"](this.options.name)}${this.options.description
|
|
53
|
+
? ` ${chalk[this.orm.config.loggerColors?.description ?? "grey"](this.options.description)}`
|
|
54
|
+
: ""}`);
|
|
51
55
|
}
|
|
52
56
|
}
|
|
53
57
|
try {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -22,9 +22,12 @@ const orm = new ORM({
|
|
|
22
22
|
logger: console,
|
|
23
23
|
loggerColors: { ... }
|
|
24
24
|
})
|
|
25
|
+
|
|
26
|
+
// start handling of tables
|
|
27
|
+
await orm.init()
|
|
25
28
|
```
|
|
26
29
|
|
|
27
|
-
##
|
|
30
|
+
## Add tables
|
|
28
31
|
|
|
29
32
|
The tables are automatically loaded from the `location` directory.
|
|
30
33
|
|
|
@@ -33,7 +36,12 @@ The tables are automatically loaded from the `location` directory.
|
|
|
33
36
|
|
|
34
37
|
import { Table } from "@ghom/orm"
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
interface User {
|
|
40
|
+
username: string
|
|
41
|
+
password: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default new Table<User>({
|
|
37
45
|
name: "user",
|
|
38
46
|
|
|
39
47
|
// the higher the priority, the earlier the table is compiled
|
|
@@ -59,20 +67,30 @@ export default new Table({
|
|
|
59
67
|
})
|
|
60
68
|
```
|
|
61
69
|
|
|
62
|
-
##
|
|
70
|
+
## Launch a query
|
|
63
71
|
|
|
64
|
-
For more information about the query builder, see [knexjs.org](https://knexjs.org/).
|
|
72
|
+
For more information about the query builder, see [knexjs.org](https://knexjs.org/).
|
|
73
|
+
You can launch a SQL query on a table like that
|
|
65
74
|
|
|
66
|
-
|
|
75
|
+
```typescript
|
|
76
|
+
import user from "./tables/user"
|
|
67
77
|
|
|
68
|
-
|
|
78
|
+
export async function compareHash(username, hash): Promise<boolean> {
|
|
79
|
+
const user = await user.query
|
|
80
|
+
.select()
|
|
81
|
+
.where("username", username)
|
|
82
|
+
.first()
|
|
69
83
|
|
|
70
|
-
|
|
71
|
-
|
|
84
|
+
return user && user.password === hash
|
|
85
|
+
}
|
|
72
86
|
```
|
|
73
87
|
|
|
74
|
-
|
|
75
|
-
await orm2.import()
|
|
76
|
-
```
|
|
88
|
+
## Future features
|
|
77
89
|
|
|
78
|
-
|
|
90
|
+
- [ ] Take full control of the table creation
|
|
91
|
+
- [ ] Add backup option
|
|
92
|
+
- [ ] Add admin panel
|
|
93
|
+
- [ ] Add shortcuts for advanced relative queries
|
|
94
|
+
- [ ] Add timed caching system
|
|
95
|
+
- [ ] Make possible to switch the data between all possible clients (pg, mysql, sqlite3)
|
|
96
|
+
- [ ] Add a way to set up timezone directly in the ORM constructor
|
package/src/app/orm.ts
CHANGED
package/src/app/table.ts
CHANGED
|
@@ -9,6 +9,7 @@ export interface MigrationData {
|
|
|
9
9
|
|
|
10
10
|
export interface TableOptions<Type extends object = object> {
|
|
11
11
|
name: string
|
|
12
|
+
description?: string
|
|
12
13
|
priority?: number
|
|
13
14
|
migrations?: { [version: number]: (table: Knex.CreateTableBuilder) => void }
|
|
14
15
|
then?: (this: Table<Type>, table: Table<Type>) => unknown
|
|
@@ -67,7 +68,13 @@ export class Table<Type extends object = object> {
|
|
|
67
68
|
this.orm.config.logger?.log(
|
|
68
69
|
`created table ${chalk[
|
|
69
70
|
this.orm.config.loggerColors?.highlight ?? "blueBright"
|
|
70
|
-
](this.options.name)}
|
|
71
|
+
](this.options.name)}${
|
|
72
|
+
this.options.description
|
|
73
|
+
? ` ${chalk[this.orm.config.loggerColors?.description ?? "grey"](
|
|
74
|
+
this.options.description,
|
|
75
|
+
)}`
|
|
76
|
+
: ""
|
|
77
|
+
}`,
|
|
71
78
|
)
|
|
72
79
|
} catch (error: any) {
|
|
73
80
|
if (error.toString().includes("syntax error")) {
|
|
@@ -82,7 +89,13 @@ export class Table<Type extends object = object> {
|
|
|
82
89
|
this.orm.config.logger?.log(
|
|
83
90
|
`loaded table ${chalk[
|
|
84
91
|
this.orm.config.loggerColors?.highlight ?? "blueBright"
|
|
85
|
-
](this.options.name)}
|
|
92
|
+
](this.options.name)}${
|
|
93
|
+
this.options.description
|
|
94
|
+
? ` ${chalk[this.orm.config.loggerColors?.description ?? "grey"](
|
|
95
|
+
this.options.description,
|
|
96
|
+
)}`
|
|
97
|
+
: ""
|
|
98
|
+
}`,
|
|
86
99
|
)
|
|
87
100
|
}
|
|
88
101
|
}
|