metal-orm 1.0.94 → 1.0.95
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.cjs +29 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +4 -3
- package/src/orm/column-introspection.ts +43 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -33,9 +33,10 @@ export * from './core/functions/array.js';
|
|
|
33
33
|
export * from './orm/als.js';
|
|
34
34
|
export * from './orm/hydration.js';
|
|
35
35
|
export * from './codegen/typescript.js';
|
|
36
|
-
export * from './orm/orm-session.js';
|
|
37
|
-
export * from './orm/orm.js';
|
|
38
|
-
export * from './orm/
|
|
36
|
+
export * from './orm/orm-session.js';
|
|
37
|
+
export * from './orm/orm.js';
|
|
38
|
+
export * from './orm/column-introspection.js';
|
|
39
|
+
export * from './orm/entity.js';
|
|
39
40
|
export * from './orm/lazy-batch.js';
|
|
40
41
|
export * from './orm/relations/has-many.js';
|
|
41
42
|
export * from './orm/relations/belongs-to.js';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { normalizeColumnType } from '../schema/column-types.js';
|
|
2
|
+
import type { ColumnType } from '../schema/column-types.js';
|
|
3
|
+
import type { TableDef } from '../schema/table.js';
|
|
4
|
+
import type { ColumnDefLike, EntityConstructor } from './entity-metadata.js';
|
|
5
|
+
import { getEntityMetadata } from './entity-metadata.js';
|
|
6
|
+
|
|
7
|
+
type ColumnTarget = TableDef | EntityConstructor;
|
|
8
|
+
|
|
9
|
+
const getColumnDefFromTarget = (
|
|
10
|
+
target: ColumnTarget,
|
|
11
|
+
column: string
|
|
12
|
+
): ColumnDefLike | undefined => {
|
|
13
|
+
if (typeof target === 'function') {
|
|
14
|
+
const meta = getEntityMetadata(target);
|
|
15
|
+
if (!meta?.columns) return undefined;
|
|
16
|
+
return meta.columns[column];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const table = target as TableDef;
|
|
20
|
+
return table.columns[column];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const getColumnType = (
|
|
24
|
+
target: ColumnTarget,
|
|
25
|
+
column: string
|
|
26
|
+
): ColumnType | undefined => {
|
|
27
|
+
const col = getColumnDefFromTarget(target, column);
|
|
28
|
+
if (!col?.type) return undefined;
|
|
29
|
+
return normalizeColumnType(col.type);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const getDateKind = (
|
|
33
|
+
target: ColumnTarget,
|
|
34
|
+
column: string
|
|
35
|
+
): 'date' | 'date-time' | undefined => {
|
|
36
|
+
const type = getColumnType(target, column);
|
|
37
|
+
if (!type) return undefined;
|
|
38
|
+
if (type === 'date') return 'date';
|
|
39
|
+
if (type === 'datetime' || type === 'timestamp' || type === 'timestamptz') {
|
|
40
|
+
return 'date-time';
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
};
|