@ghom/orm 1.3.4 → 1.4.0

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.
@@ -29,53 +29,47 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.ORM = void 0;
30
30
  const fs_1 = __importDefault(require("fs"));
31
31
  const url_1 = __importDefault(require("url"));
32
+ const path_1 = __importDefault(require("path"));
32
33
  const handler_1 = require("@ghom/handler");
33
34
  const knex_1 = __importDefault(require("knex"));
34
35
  const table_js_1 = require("./table.js");
35
- const pack = JSON.parse(fs_1.default.readFileSync("./package.json", "utf8"));
36
+ const pack = JSON.parse(fs_1.default.readFileSync(path_1.default.join(process.cwd(), "package.json"), "utf8"));
36
37
  const isCJS = pack.type === "commonjs" || pack.type == void 0;
37
- class ORM extends handler_1.Handler {
38
- /**
39
- * @param ormConfig configuration for table handler or just tablePath (path to directory that contains js files of tables)
40
- * @param knexConfig configuration for connect to database
41
- */
42
- constructor(ormConfig, knexConfig = {
43
- client: "sqlite3",
44
- useNullAsDefault: true,
45
- connection: {
46
- filename: ":memory:",
47
- },
48
- }) {
49
- super(typeof ormConfig === "string" ? ormConfig : ormConfig.tablePath);
50
- this.ormConfig =
51
- typeof ormConfig === "string" ? { tablePath: ormConfig } : ormConfig;
52
- this.db = (0, knex_1.default)(knexConfig);
38
+ class ORM {
39
+ constructor(config) {
40
+ this.config = config;
41
+ this.database = (0, knex_1.default)(config.database ?? {
42
+ client: "sqlite3",
43
+ useNullAsDefault: true,
44
+ connection: {
45
+ filename: ":memory:",
46
+ },
47
+ });
48
+ this.handler = new handler_1.Handler(config.location, {
49
+ loader: (filepath) => Promise.resolve(`${isCJS ? filepath : url_1.default.pathToFileURL(filepath).href}`).then(s => __importStar(require(s))).then((file) => file.default),
50
+ });
53
51
  }
54
52
  async init() {
55
- this.once("finish", async (pathList) => {
56
- const tables = await Promise.all(pathList.map(async (filepath) => {
57
- return Promise.resolve(`${isCJS ? filepath : url_1.default.pathToFileURL(filepath).href}`).then(s => __importStar(require(s))).then((file) => file.default);
58
- }));
59
- const migration = new table_js_1.Table({
60
- name: "migration",
61
- priority: Infinity,
62
- setup: (table) => {
63
- table.string("table").unique().notNullable();
64
- table.integer("version").notNullable();
65
- },
66
- });
67
- migration.orm = this;
68
- await migration.make();
69
- for (const table of tables.sort((a, b) => (b.options.priority ?? 0) - (a.options.priority ?? 0))) {
70
- table.orm = this;
71
- await table.make();
72
- }
73
- });
53
+ await this.handler.init();
54
+ const tables = [...this.handler.elements.values()];
74
55
  try {
75
- await this.db.raw("PRAGMA foreign_keys = ON;");
56
+ await this.database.raw("PRAGMA foreign_keys = ON;");
76
57
  }
77
58
  catch (error) { }
78
- await this.load();
59
+ const migration = new table_js_1.Table({
60
+ name: "migration",
61
+ priority: Infinity,
62
+ setup: (table) => {
63
+ table.string("table").unique().notNullable();
64
+ table.integer("version").notNullable();
65
+ },
66
+ });
67
+ migration.orm = this;
68
+ await migration.make();
69
+ for (const table of tables.sort((a, b) => (b.options.priority ?? 0) - (a.options.priority ?? 0))) {
70
+ table.orm = this;
71
+ await table.make();
72
+ }
79
73
  }
80
74
  }
81
75
  exports.ORM = ORM;
@@ -4,26 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Table = void 0;
7
- const path_1 = __importDefault(require("path"));
8
7
  const chalk_1 = __importDefault(require("chalk"));
9
8
  class Table {
10
9
  constructor(options) {
11
10
  this.options = options;
12
11
  }
13
- get filepath() {
14
- if (!this.orm)
15
- throw new Error("missing ORM");
16
- return path_1.default.relative(process.cwd(), path_1.default.join(this.orm.ormConfig.tablePath, this.options.name + ".ts"));
17
- }
18
- get logger() {
19
- if (!this.orm)
20
- throw new Error("missing ORM");
21
- return this.orm.ormConfig.logger;
22
- }
23
12
  get db() {
24
13
  if (!this.orm)
25
14
  throw new Error("missing ORM");
26
- return this.orm.db;
15
+ return this.orm.database;
27
16
  }
28
17
  get query() {
29
18
  return this.db(this.options.name);
@@ -38,27 +27,29 @@ class Table {
38
27
  .then((rows) => rows.length === 0);
39
28
  }
40
29
  async make() {
30
+ if (!this.orm)
31
+ throw new Error("missing ORM");
41
32
  try {
42
33
  await this.db.schema.createTable(this.options.name, this.options.setup);
43
- this.logger?.log(`created table ${chalk_1.default.blueBright(this.options.name)}`);
34
+ this.orm.config.logger?.log(`created table ${chalk_1.default[this.orm.config.loggerColors?.highlight ?? "blueBright"](this.options.name)}`);
44
35
  }
45
36
  catch (error) {
46
37
  if (error.toString().includes("syntax error")) {
47
- this.logger?.error(`you need to implement the "setup" method in options of your ${chalk_1.default.blueBright(this.options.name)} table!`, this.filepath);
38
+ this.orm.config.logger?.error(`you need to implement the "setup" method in options of your ${chalk_1.default[this.orm.config.loggerColors?.highlight ?? "blueBright"](this.options.name)} table!`);
48
39
  throw error;
49
40
  }
50
41
  else {
51
- this.logger?.log(`loaded table ${chalk_1.default.blueBright(this.options.name)}`);
42
+ this.orm.config.logger?.log(`loaded table ${chalk_1.default[this.orm.config.loggerColors?.highlight ?? "blueBright"](this.options.name)}`);
52
43
  }
53
44
  }
54
45
  try {
55
46
  const migrated = await this.migrate();
56
47
  if (migrated !== false) {
57
- this.logger?.log(`migrated table ${chalk_1.default.blueBright(this.options.name)} to version ${chalk_1.default.magentaBright(migrated)}`);
48
+ this.orm.config.logger?.log(`migrated table ${chalk_1.default[this.orm.config.loggerColors?.highlight ?? "blueBright"](this.options.name)} to version ${chalk_1.default[this.orm.config.loggerColors?.rawValue ?? "magentaBright"](migrated)}`);
58
49
  }
59
50
  }
60
51
  catch (error) {
61
- this.logger?.error(error, this.filepath);
52
+ this.orm.config.logger?.error(error);
62
53
  }
63
54
  await this.options.then?.bind(this)(this);
64
55
  return this;
@@ -1,53 +1,48 @@
1
1
  import fs from "fs";
2
2
  import url from "url";
3
+ import path from "path";
3
4
  import { Handler } from "@ghom/handler";
4
5
  import { default as knex } from "knex";
5
6
  import { Table } from "./table.js";
6
- const pack = JSON.parse(fs.readFileSync("./package.json", "utf8"));
7
+ const pack = JSON.parse(fs.readFileSync(path.join(process.cwd(), "package.json"), "utf8"));
7
8
  const isCJS = pack.type === "commonjs" || pack.type == void 0;
8
- export class ORM extends Handler {
9
- db;
10
- ormConfig;
11
- /**
12
- * @param ormConfig configuration for table handler or just tablePath (path to directory that contains js files of tables)
13
- * @param knexConfig configuration for connect to database
14
- */
15
- constructor(ormConfig, knexConfig = {
16
- client: "sqlite3",
17
- useNullAsDefault: true,
18
- connection: {
19
- filename: ":memory:",
20
- },
21
- }) {
22
- super(typeof ormConfig === "string" ? ormConfig : ormConfig.tablePath);
23
- this.ormConfig =
24
- typeof ormConfig === "string" ? { tablePath: ormConfig } : ormConfig;
25
- this.db = knex(knexConfig);
9
+ export class ORM {
10
+ config;
11
+ database;
12
+ handler;
13
+ constructor(config) {
14
+ this.config = config;
15
+ this.database = knex(config.database ?? {
16
+ client: "sqlite3",
17
+ useNullAsDefault: true,
18
+ connection: {
19
+ filename: ":memory:",
20
+ },
21
+ });
22
+ this.handler = new Handler(config.location, {
23
+ loader: (filepath) => import(isCJS ? filepath : url.pathToFileURL(filepath).href).then((file) => file.default),
24
+ });
26
25
  }
27
26
  async init() {
28
- this.once("finish", async (pathList) => {
29
- const tables = await Promise.all(pathList.map(async (filepath) => {
30
- return import(isCJS ? filepath : url.pathToFileURL(filepath).href).then((file) => file.default);
31
- }));
32
- const migration = new Table({
33
- name: "migration",
34
- priority: Infinity,
35
- setup: (table) => {
36
- table.string("table").unique().notNullable();
37
- table.integer("version").notNullable();
38
- },
39
- });
40
- migration.orm = this;
41
- await migration.make();
42
- for (const table of tables.sort((a, b) => (b.options.priority ?? 0) - (a.options.priority ?? 0))) {
43
- table.orm = this;
44
- await table.make();
45
- }
46
- });
27
+ await this.handler.init();
28
+ const tables = [...this.handler.elements.values()];
47
29
  try {
48
- await this.db.raw("PRAGMA foreign_keys = ON;");
30
+ await this.database.raw("PRAGMA foreign_keys = ON;");
49
31
  }
50
32
  catch (error) { }
51
- await this.load();
33
+ const migration = new Table({
34
+ name: "migration",
35
+ priority: Infinity,
36
+ setup: (table) => {
37
+ table.string("table").unique().notNullable();
38
+ table.integer("version").notNullable();
39
+ },
40
+ });
41
+ migration.orm = this;
42
+ await migration.make();
43
+ for (const table of tables.sort((a, b) => (b.options.priority ?? 0) - (a.options.priority ?? 0))) {
44
+ table.orm = this;
45
+ await table.make();
46
+ }
52
47
  }
53
48
  }
@@ -1,4 +1,3 @@
1
- import path from "path";
2
1
  import chalk from "chalk";
3
2
  export class Table {
4
3
  options;
@@ -6,20 +5,10 @@ export class Table {
6
5
  constructor(options) {
7
6
  this.options = options;
8
7
  }
9
- get filepath() {
10
- if (!this.orm)
11
- throw new Error("missing ORM");
12
- return path.relative(process.cwd(), path.join(this.orm.ormConfig.tablePath, this.options.name + ".ts"));
13
- }
14
- get logger() {
15
- if (!this.orm)
16
- throw new Error("missing ORM");
17
- return this.orm.ormConfig.logger;
18
- }
19
8
  get db() {
20
9
  if (!this.orm)
21
10
  throw new Error("missing ORM");
22
- return this.orm.db;
11
+ return this.orm.database;
23
12
  }
24
13
  get query() {
25
14
  return this.db(this.options.name);
@@ -34,27 +23,29 @@ export class Table {
34
23
  .then((rows) => rows.length === 0);
35
24
  }
36
25
  async make() {
26
+ if (!this.orm)
27
+ throw new Error("missing ORM");
37
28
  try {
38
29
  await this.db.schema.createTable(this.options.name, this.options.setup);
39
- this.logger?.log(`created table ${chalk.blueBright(this.options.name)}`);
30
+ this.orm.config.logger?.log(`created table ${chalk[this.orm.config.loggerColors?.highlight ?? "blueBright"](this.options.name)}`);
40
31
  }
41
32
  catch (error) {
42
33
  if (error.toString().includes("syntax error")) {
43
- this.logger?.error(`you need to implement the "setup" method in options of your ${chalk.blueBright(this.options.name)} table!`, this.filepath);
34
+ this.orm.config.logger?.error(`you need to implement the "setup" method in options of your ${chalk[this.orm.config.loggerColors?.highlight ?? "blueBright"](this.options.name)} table!`);
44
35
  throw error;
45
36
  }
46
37
  else {
47
- this.logger?.log(`loaded table ${chalk.blueBright(this.options.name)}`);
38
+ this.orm.config.logger?.log(`loaded table ${chalk[this.orm.config.loggerColors?.highlight ?? "blueBright"](this.options.name)}`);
48
39
  }
49
40
  }
50
41
  try {
51
42
  const migrated = await this.migrate();
52
43
  if (migrated !== false) {
53
- this.logger?.log(`migrated table ${chalk.blueBright(this.options.name)} to version ${chalk.magentaBright(migrated)}`);
44
+ this.orm.config.logger?.log(`migrated table ${chalk[this.orm.config.loggerColors?.highlight ?? "blueBright"](this.options.name)} to version ${chalk[this.orm.config.loggerColors?.rawValue ?? "magentaBright"](migrated)}`);
54
45
  }
55
46
  }
56
47
  catch (error) {
57
- this.logger?.error(error, this.filepath);
48
+ this.orm.config.logger?.error(error);
58
49
  }
59
50
  await this.options.then?.bind(this)(this);
60
51
  return this;
@@ -1,24 +1,37 @@
1
1
  import { Handler } from "@ghom/handler";
2
2
  import { Knex } from "knex";
3
- export interface ORMLogger {
4
- log: (message: string, section?: string) => void;
5
- error: (text: string | Error, _path: string, full?: boolean) => void;
3
+ import { Table } from "./table.js";
4
+ import { Color } from "chalk";
5
+ export interface ILogger {
6
+ log: (...message: string[]) => void;
7
+ error: (error: Error | string, ...message: string[]) => void;
6
8
  }
7
- /**
8
- * @property tablePath - path to directory that contains js files of tables
9
- * @property verbose - show console logs or not
10
- */
11
9
  export interface ORMConfig {
12
- logger?: ORMLogger;
13
- tablePath: string;
14
- }
15
- export declare class ORM extends Handler {
16
- db: Knex;
17
- ormConfig: ORMConfig;
18
10
  /**
19
- * @param ormConfig configuration for table handler or just tablePath (path to directory that contains js files of tables)
20
- * @param knexConfig configuration for connect to database
11
+ * path to the directory that contains js files of tables
12
+ */
13
+ location: string;
14
+ /**
15
+ * database configuration
16
+ */
17
+ database?: Knex.Config;
18
+ /**
19
+ * Logger used to log the table files loaded or created.
20
+ */
21
+ logger?: ILogger;
22
+ /**
23
+ * Pattern used on logs when the table files are loaded or created. <br>
24
+ * Based on Chalk color-method names.
21
25
  */
22
- constructor(ormConfig: ORMConfig | string, knexConfig?: Knex.Config);
26
+ loggerColors?: {
27
+ highlight: typeof Color;
28
+ rawValue: typeof Color;
29
+ };
30
+ }
31
+ export declare class ORM {
32
+ config: ORMConfig;
33
+ database: Knex;
34
+ handler: Handler<Table<any>>;
35
+ constructor(config: ORMConfig);
23
36
  init(): Promise<void>;
24
37
  }
@@ -17,8 +17,6 @@ export declare class Table<Type extends {}> {
17
17
  readonly options: TableOptions<Type>;
18
18
  orm?: ORM;
19
19
  constructor(options: TableOptions<Type>);
20
- private get filepath();
21
- private get logger();
22
20
  get db(): Knex<any, any[]>;
23
21
  get query(): Knex.QueryBuilder<Type, {
24
22
  _base: Type;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghom/orm",
3
- "version": "1.3.4",
3
+ "version": "1.4.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/esm/index.js",
@@ -20,20 +20,20 @@
20
20
  "prepublishOnly": "npm run format && npm test"
21
21
  },
22
22
  "devDependencies": {
23
- "@types/jest": "^29.5.0",
24
- "@types/node": "^18.15.11",
23
+ "@types/jest": "^29.5.1",
24
+ "@types/node": "^18.16.3",
25
25
  "dotenv": "^16.0.3",
26
26
  "jest": "^29.5.0",
27
- "prettier": "^2.8.7",
27
+ "prettier": "^2.8.8",
28
28
  "typescript": "^5.0.4"
29
29
  },
30
30
  "optionalDependencies": {
31
- "mysql2": "^3.2.1",
31
+ "mysql2": "^3.2.4",
32
32
  "pg": "^8.10.0",
33
33
  "sqlite3": "^5.1.6"
34
34
  },
35
35
  "dependencies": {
36
- "@ghom/handler": "^1.1.0",
36
+ "@ghom/handler": "^1.2.0",
37
37
  "knex": "^2.4.2"
38
38
  }
39
39
  }
package/src/app/orm.ts CHANGED
@@ -1,84 +1,95 @@
1
1
  import fs from "fs"
2
2
  import url from "url"
3
+ import path from "path"
3
4
  import { Handler } from "@ghom/handler"
4
5
  import { Knex, default as knex } from "knex"
5
6
  import { MigrationData, Table } from "./table.js"
7
+ import { Color } from "chalk"
6
8
 
7
- const pack = JSON.parse(fs.readFileSync("./package.json", "utf8"))
9
+ const pack = JSON.parse(
10
+ fs.readFileSync(path.join(process.cwd(), "package.json"), "utf8")
11
+ )
8
12
  const isCJS = pack.type === "commonjs" || pack.type == void 0
9
13
 
10
- export interface ORMLogger {
11
- log: (message: string, section?: string) => void
12
- error: (text: string | Error, _path: string, full?: boolean) => void
14
+ export interface ILogger {
15
+ log: (...message: string[]) => void
16
+ error: (error: Error | string, ...message: string[]) => void
13
17
  }
14
18
 
15
- /**
16
- * @property tablePath - path to directory that contains js files of tables
17
- * @property verbose - show console logs or not
18
- */
19
19
  export interface ORMConfig {
20
- logger?: ORMLogger
21
- tablePath: string
22
- }
20
+ /**
21
+ * path to the directory that contains js files of tables
22
+ */
23
+ location: string
23
24
 
24
- export class ORM extends Handler {
25
- db: Knex
26
- ormConfig: ORMConfig
25
+ /**
26
+ * database configuration
27
+ */
28
+ database?: Knex.Config
27
29
 
28
30
  /**
29
- * @param ormConfig configuration for table handler or just tablePath (path to directory that contains js files of tables)
30
- * @param knexConfig configuration for connect to database
31
+ * Logger used to log the table files loaded or created.
31
32
  */
32
- constructor(
33
- ormConfig: ORMConfig | string,
34
- knexConfig: Knex.Config = {
35
- client: "sqlite3",
36
- useNullAsDefault: true,
37
- connection: {
38
- filename: ":memory:",
39
- },
40
- }
41
- ) {
42
- super(typeof ormConfig === "string" ? ormConfig : ormConfig.tablePath)
43
- this.ormConfig =
44
- typeof ormConfig === "string" ? { tablePath: ormConfig } : ormConfig
45
- this.db = knex(knexConfig)
33
+ logger?: ILogger
34
+
35
+ /**
36
+ * Pattern used on logs when the table files are loaded or created. <br>
37
+ * Based on Chalk color-method names.
38
+ */
39
+ loggerColors?: {
40
+ highlight: typeof Color
41
+ rawValue: typeof Color
46
42
  }
43
+ }
47
44
 
48
- async init() {
49
- this.once("finish", async (pathList) => {
50
- const tables: Table<any>[] = await Promise.all(
51
- pathList.map(async (filepath) => {
52
- return import(
53
- isCJS ? filepath : url.pathToFileURL(filepath).href
54
- ).then((file) => file.default)
55
- })
56
- )
45
+ export class ORM {
46
+ database: Knex
47
+ handler: Handler<Table<any>>
57
48
 
58
- const migration = new Table<MigrationData>({
59
- name: "migration",
60
- priority: Infinity,
61
- setup: (table) => {
62
- table.string("table").unique().notNullable()
63
- table.integer("version").notNullable()
49
+ constructor(public config: ORMConfig) {
50
+ this.database = knex(
51
+ config.database ?? {
52
+ client: "sqlite3",
53
+ useNullAsDefault: true,
54
+ connection: {
55
+ filename: ":memory:",
64
56
  },
65
- })
66
-
67
- migration.orm = this
68
- await migration.make()
69
-
70
- for (const table of tables.sort(
71
- (a, b) => (b.options.priority ?? 0) - (a.options.priority ?? 0)
72
- )) {
73
- table.orm = this
74
- await table.make()
75
57
  }
58
+ )
59
+ this.handler = new Handler(config.location, {
60
+ loader: (filepath) =>
61
+ import(isCJS ? filepath : url.pathToFileURL(filepath).href).then(
62
+ (file) => file.default
63
+ ),
76
64
  })
65
+ }
66
+
67
+ async init() {
68
+ await this.handler.init()
69
+
70
+ const tables = [...this.handler.elements.values()]
77
71
 
78
72
  try {
79
- await this.db.raw("PRAGMA foreign_keys = ON;")
73
+ await this.database.raw("PRAGMA foreign_keys = ON;")
80
74
  } catch (error) {}
81
75
 
82
- await this.load()
76
+ const migration = new Table<MigrationData>({
77
+ name: "migration",
78
+ priority: Infinity,
79
+ setup: (table) => {
80
+ table.string("table").unique().notNullable()
81
+ table.integer("version").notNullable()
82
+ },
83
+ })
84
+
85
+ migration.orm = this
86
+ await migration.make()
87
+
88
+ for (const table of tables.sort(
89
+ (a, b) => (b.options.priority ?? 0) - (a.options.priority ?? 0)
90
+ )) {
91
+ table.orm = this
92
+ await table.make()
93
+ }
83
94
  }
84
95
  }
package/src/app/table.ts CHANGED
@@ -1,4 +1,3 @@
1
- import path from "path"
2
1
  import chalk from "chalk"
3
2
  import { Knex } from "knex"
4
3
  import { ORM } from "./orm.js"
@@ -21,22 +20,9 @@ export class Table<Type extends {}> {
21
20
 
22
21
  constructor(public readonly options: TableOptions<Type>) {}
23
22
 
24
- private get filepath() {
25
- if (!this.orm) throw new Error("missing ORM")
26
- return path.relative(
27
- process.cwd(),
28
- path.join(this.orm.ormConfig.tablePath, this.options.name + ".ts")
29
- )
30
- }
31
-
32
- private get logger() {
33
- if (!this.orm) throw new Error("missing ORM")
34
- return this.orm.ormConfig.logger
35
- }
36
-
37
23
  get db() {
38
24
  if (!this.orm) throw new Error("missing ORM")
39
- return this.orm.db
25
+ return this.orm.database
40
26
  }
41
27
 
42
28
  get query() {
@@ -55,21 +41,31 @@ export class Table<Type extends {}> {
55
41
  }
56
42
 
57
43
  async make(): Promise<this> {
44
+ if (!this.orm) throw new Error("missing ORM")
45
+
58
46
  try {
59
47
  await this.db.schema.createTable(this.options.name, this.options.setup)
60
- this.logger?.log(`created table ${chalk.blueBright(this.options.name)}`)
48
+
49
+ this.orm.config.logger?.log(
50
+ `created table ${chalk[
51
+ this.orm.config.loggerColors?.highlight ?? "blueBright"
52
+ ](this.options.name)}`
53
+ )
61
54
  } catch (error: any) {
62
55
  if (error.toString().includes("syntax error")) {
63
- this.logger?.error(
64
- `you need to implement the "setup" method in options of your ${chalk.blueBright(
65
- this.options.name
66
- )} table!`,
67
- this.filepath
56
+ this.orm.config.logger?.error(
57
+ `you need to implement the "setup" method in options of your ${chalk[
58
+ this.orm.config.loggerColors?.highlight ?? "blueBright"
59
+ ](this.options.name)} table!`
68
60
  )
69
61
 
70
62
  throw error
71
63
  } else {
72
- this.logger?.log(`loaded table ${chalk.blueBright(this.options.name)}`)
64
+ this.orm.config.logger?.log(
65
+ `loaded table ${chalk[
66
+ this.orm.config.loggerColors?.highlight ?? "blueBright"
67
+ ](this.options.name)}`
68
+ )
73
69
  }
74
70
  }
75
71
 
@@ -77,14 +73,16 @@ export class Table<Type extends {}> {
77
73
  const migrated = await this.migrate()
78
74
 
79
75
  if (migrated !== false) {
80
- this.logger?.log(
81
- `migrated table ${chalk.blueBright(
82
- this.options.name
83
- )} to version ${chalk.magentaBright(migrated)}`
76
+ this.orm.config.logger?.log(
77
+ `migrated table ${chalk[
78
+ this.orm.config.loggerColors?.highlight ?? "blueBright"
79
+ ](this.options.name)} to version ${chalk[
80
+ this.orm.config.loggerColors?.rawValue ?? "magentaBright"
81
+ ](migrated)}`
84
82
  )
85
83
  }
86
84
  } catch (error: any) {
87
- this.logger?.error(error, this.filepath)
85
+ this.orm.config.logger?.error(error)
88
86
  }
89
87
 
90
88
  await this.options.then?.bind(this)(this)
package/tests/test.js CHANGED
@@ -10,8 +10,7 @@ import b from "./tables/b"
10
10
  import c from "./tables/c"
11
11
 
12
12
  const orm = new ORM({
13
- tablePath: path.join("tests","tables"),
14
- logger: console,
13
+ location: path.join("tests","tables")
15
14
  })
16
15
 
17
16
  beforeAll(async () => {
@@ -19,18 +18,18 @@ beforeAll(async () => {
19
18
  })
20
19
 
21
20
  test("tables created", async () => {
22
- expect(await orm.db.schema.hasTable("migration")).toBeTruthy()
23
- expect(await orm.db.schema.hasTable("a")).toBeTruthy()
24
- expect(await orm.db.schema.hasTable("b")).toBeTruthy()
25
- expect(await orm.db.schema.hasTable("c")).toBeTruthy()
21
+ expect(await orm.database.schema.hasTable("migration")).toBeTruthy()
22
+ expect(await orm.database.schema.hasTable("a")).toBeTruthy()
23
+ expect(await orm.database.schema.hasTable("b")).toBeTruthy()
24
+ expect(await orm.database.schema.hasTable("c")).toBeTruthy()
26
25
  })
27
26
 
28
27
  test("migrations ran", async () => {
29
- expect(await orm.db.schema.hasColumn("b", "c_id")).toBeTruthy()
28
+ expect(await orm.database.schema.hasColumn("b", "c_id")).toBeTruthy()
30
29
  })
31
30
 
32
31
  test("then ran", async () => {
33
- const rows = await orm.db("a").select()
32
+ const rows = await orm.database("a").select()
34
33
  expect(rows.length).toBe(1)
35
34
  })
36
35
 
@@ -40,5 +39,5 @@ test("cascade delete", async () => {
40
39
  })
41
40
 
42
41
  afterAll(async () => {
43
- await orm.db.destroy()
42
+ await orm.database.destroy()
44
43
  })