orchid-orm 1.6.16 → 1.6.18

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.mjs CHANGED
@@ -1,29 +1,45 @@
1
1
  import { columnTypes, getColumnTypes, addQueryOn, VirtualColumn, pushQueryValue, isQueryReturnsAll, getQueryAs, toSqlCacheKey, NotFoundError, relationQueryKey, Db, Adapter, anyShape, getClonedQueryData, columnsShapeToCode, primaryKeyToCode, indexToCode, foreignKeyToCode, columnIndexesToCode, columnForeignKeysToCode, columnCheckToCode } from 'pqb';
2
2
  export { columnTypes } from 'pqb';
3
- import { snakeCaseKey, emptyObject, pathToLog, singleQuote, codeToString, quoteObjectKey, addCode, columnDefaultArgumentToCode } from 'orchid-core';
3
+ import { snakeCaseKey, toSnakeCase, emptyObject, pathToLog, singleQuote, codeToString, quoteObjectKey, addCode, columnDefaultArgumentToCode } from 'orchid-core';
4
4
  import * as path from 'path';
5
5
  import path__default from 'path';
6
6
  import fs from 'fs/promises';
7
7
  import typescript from 'typescript';
8
8
 
9
- const createBaseTable = (options = { columnTypes }) => {
10
- const ct = typeof options.columnTypes === "function" ? options.columnTypes(columnTypes) : options.columnTypes || columnTypes;
11
- if (options.snakeCase) {
12
- ct[snakeCaseKey] = true;
13
- }
14
- return create(ct);
9
+ const createBaseTable = ({
10
+ columnTypes: columnTypes$1,
11
+ snakeCase
12
+ } = { columnTypes: columnTypes }) => {
13
+ const ct = typeof columnTypes$1 === "function" ? columnTypes$1(columnTypes) : columnTypes$1 || columnTypes;
14
+ return create(
15
+ ct,
16
+ snakeCase
17
+ );
15
18
  };
16
- const create = (columnTypes2) => {
19
+ const create = (columnTypes, snakeCase) => {
17
20
  return class BaseTable {
18
21
  constructor() {
22
+ this.snakeCase = snakeCase;
19
23
  this.setColumns = (fn) => {
20
- const shape = getColumnTypes(columnTypes2, fn);
24
+ columnTypes[snakeCaseKey] = this.snakeCase;
25
+ const shape = getColumnTypes(columnTypes, fn);
26
+ if (this.snakeCase) {
27
+ for (const key in shape) {
28
+ const column = shape[key];
29
+ if (column.data.name)
30
+ continue;
31
+ const snakeName = toSnakeCase(key);
32
+ if (snakeName !== key) {
33
+ column.data.name = snakeName;
34
+ }
35
+ }
36
+ }
21
37
  return {
22
38
  shape,
23
39
  type: void 0
24
40
  };
25
41
  };
26
- this.columnTypes = columnTypes2;
42
+ this.columnTypes = columnTypes;
27
43
  }
28
44
  belongsTo(fn, options) {
29
45
  return {