orchid-orm 1.6.16 → 1.6.17
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/index.d.ts +2 -1
- package/dist/index.js +25 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -144,7 +144,7 @@ declare type Table = {
|
|
|
144
144
|
columnTypes: ColumnTypesBase;
|
|
145
145
|
noPrimaryKey?: boolean;
|
|
146
146
|
};
|
|
147
|
-
declare const createBaseTable: <CT extends ColumnTypesBase>(
|
|
147
|
+
declare const createBaseTable: <CT extends ColumnTypesBase>({ columnTypes, snakeCase, }?: {
|
|
148
148
|
columnTypes?: CT | ((t: DefaultColumnTypes) => CT) | undefined;
|
|
149
149
|
snakeCase?: boolean | undefined;
|
|
150
150
|
}) => {
|
|
@@ -265,6 +265,7 @@ declare const createBaseTable: <CT extends ColumnTypesBase>(options?: {
|
|
|
265
265
|
};
|
|
266
266
|
} : CT;
|
|
267
267
|
noPrimaryKey?: boolean | undefined;
|
|
268
|
+
snakeCase: boolean | undefined;
|
|
268
269
|
setColumns: <T_16 extends ColumnsShape>(fn: (t: ColumnTypesBase extends CT ? {
|
|
269
270
|
timestamps: <T extends orchid_core.ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, orchid_core.ColumnDataBase>>(this: {
|
|
270
271
|
name(name: string): {
|
package/dist/index.js
CHANGED
|
@@ -33,24 +33,40 @@ var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
|
33
33
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
34
34
|
var typescript__default = /*#__PURE__*/_interopDefaultLegacy(typescript);
|
|
35
35
|
|
|
36
|
-
const createBaseTable = (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return create(
|
|
36
|
+
const createBaseTable = ({
|
|
37
|
+
columnTypes,
|
|
38
|
+
snakeCase
|
|
39
|
+
} = { columnTypes: pqb.columnTypes }) => {
|
|
40
|
+
const ct = typeof columnTypes === "function" ? columnTypes(pqb.columnTypes) : columnTypes || pqb.columnTypes;
|
|
41
|
+
return create(
|
|
42
|
+
ct,
|
|
43
|
+
snakeCase
|
|
44
|
+
);
|
|
42
45
|
};
|
|
43
|
-
const create = (
|
|
46
|
+
const create = (columnTypes, snakeCase) => {
|
|
44
47
|
return class BaseTable {
|
|
45
48
|
constructor() {
|
|
49
|
+
this.snakeCase = snakeCase;
|
|
46
50
|
this.setColumns = (fn) => {
|
|
47
|
-
|
|
51
|
+
columnTypes[orchidCore.snakeCaseKey] = this.snakeCase;
|
|
52
|
+
const shape = pqb.getColumnTypes(columnTypes, fn);
|
|
53
|
+
if (this.snakeCase) {
|
|
54
|
+
for (const key in shape) {
|
|
55
|
+
const column = shape[key];
|
|
56
|
+
if (column.data.name)
|
|
57
|
+
continue;
|
|
58
|
+
const snakeName = orchidCore.toSnakeCase(key);
|
|
59
|
+
if (snakeName !== key) {
|
|
60
|
+
column.data.name = snakeName;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
48
64
|
return {
|
|
49
65
|
shape,
|
|
50
66
|
type: void 0
|
|
51
67
|
};
|
|
52
68
|
};
|
|
53
|
-
this.columnTypes =
|
|
69
|
+
this.columnTypes = columnTypes;
|
|
54
70
|
}
|
|
55
71
|
belongsTo(fn, options) {
|
|
56
72
|
return {
|