@sqb/connect 4.10.0 → 4.10.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.
Files changed (46) hide show
  1. package/package.json +3 -2
  2. package/types/client/adapter.d.ts +57 -0
  3. package/types/client/cursor-stream.d.ts +29 -0
  4. package/types/client/cursor.d.ts +116 -0
  5. package/types/client/extensions.d.ts +4 -0
  6. package/types/client/field-info-map.d.ts +12 -0
  7. package/types/client/helpers.d.ts +9 -0
  8. package/types/client/sqb-client.d.ts +65 -0
  9. package/types/client/sqb-connection.d.ts +74 -0
  10. package/types/client/types.d.ts +181 -0
  11. package/types/index.d.ts +34 -0
  12. package/types/orm/backward.d.ts +13 -0
  13. package/types/orm/base-entity.d.ts +8 -0
  14. package/types/orm/commands/command.helper.d.ts +14 -0
  15. package/types/orm/commands/count.command.d.ts +11 -0
  16. package/types/orm/commands/create.command.d.ts +20 -0
  17. package/types/orm/commands/delete.command.d.ts +11 -0
  18. package/types/orm/commands/find.command.d.ts +44 -0
  19. package/types/orm/commands/row-converter.d.ts +55 -0
  20. package/types/orm/commands/update.command.d.ts +22 -0
  21. package/types/orm/decorators/column.decorator.d.ts +4 -0
  22. package/types/orm/decorators/embedded.decorator.d.ts +3 -0
  23. package/types/orm/decorators/entity.decorator.d.ts +38 -0
  24. package/types/orm/decorators/events.decorator.d.ts +6 -0
  25. package/types/orm/decorators/foreignkey.decorator.d.ts +2 -0
  26. package/types/orm/decorators/index.decorator.d.ts +3 -0
  27. package/types/orm/decorators/link.decorator.d.ts +13 -0
  28. package/types/orm/decorators/primarykey.decorator.d.ts +3 -0
  29. package/types/orm/decorators/transform.decorator.d.ts +3 -0
  30. package/types/orm/model/association-field-metadata.d.ts +12 -0
  31. package/types/orm/model/association-node.d.ts +9 -0
  32. package/types/orm/model/association.d.ts +27 -0
  33. package/types/orm/model/column-field-metadata.d.ts +75 -0
  34. package/types/orm/model/embedded-field-metadata.d.ts +14 -0
  35. package/types/orm/model/entity-metadata.d.ts +50 -0
  36. package/types/orm/model/field-metadata.d.ts +16 -0
  37. package/types/orm/model/index-metadata.d.ts +18 -0
  38. package/types/orm/model/link-chain.d.ts +13 -0
  39. package/types/orm/orm.const.d.ts +2 -0
  40. package/types/orm/orm.type.d.ts +20 -0
  41. package/types/orm/repository.class.d.ts +140 -0
  42. package/types/orm/util/apply-mixins.d.ts +1 -0
  43. package/types/orm/util/extract-keyvalues.d.ts +2 -0
  44. package/types/orm/util/orm.helper.d.ts +13 -0
  45. package/types/orm/util/serialize-field.d.ts +2 -0
  46. package/types/types.d.ts +12 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sqb/connect",
3
3
  "description": "Multi-dialect database connection framework written with TypeScript",
4
- "version": "4.10.0",
4
+ "version": "4.10.2",
5
5
  "author": "Panates",
6
6
  "contributors": [
7
7
  "Eray Hanoglu <e.hanoglu@panates.com>",
@@ -50,7 +50,7 @@
50
50
  "@types/lodash": "^4.14.201"
51
51
  },
52
52
  "peerDependencies": {
53
- "@sqb/builder": "^4.10.0"
53
+ "@sqb/builder": "^4.10.2"
54
54
  },
55
55
  "engines": {
56
56
  "node": ">=16.0",
@@ -60,6 +60,7 @@
60
60
  "bin/",
61
61
  "cjs/",
62
62
  "esm/",
63
+ "types/",
63
64
  "LICENSE",
64
65
  "README.md"
65
66
  ],
@@ -0,0 +1,57 @@
1
+ import { Maybe } from 'ts-gems';
2
+ import { classes } from '@sqb/builder';
3
+ import { ClientConfiguration, DataType, QueryRequest, RowType } from './types.js';
4
+ export interface Adapter {
5
+ driver: string;
6
+ dialect: string;
7
+ features?: {
8
+ cursor?: boolean;
9
+ schema?: boolean;
10
+ fetchAsString?: DataType[];
11
+ };
12
+ connect: (config: ClientConfiguration) => Promise<Adapter.Connection>;
13
+ }
14
+ export declare namespace Adapter {
15
+ interface Connection {
16
+ sessionId: any;
17
+ execute: (request: QueryRequest) => Promise<Response>;
18
+ close: () => Promise<void>;
19
+ reset: () => Promise<void>;
20
+ test: () => Promise<void>;
21
+ startTransaction: () => Promise<void>;
22
+ setSavepoint?: (savepoint: string) => Promise<void>;
23
+ releaseSavepoint?: (savepoint: string) => Promise<void>;
24
+ rollbackSavepoint?: (savepoint: string) => Promise<void>;
25
+ commit: () => Promise<void>;
26
+ rollback: () => Promise<void>;
27
+ setSchema?: (schema: string) => Promise<void>;
28
+ getSchema?: () => Promise<string>;
29
+ onGenerateQuery?: (request: QueryRequest, query: classes.Query) => void;
30
+ getInTransaction?: () => boolean;
31
+ }
32
+ interface Cursor {
33
+ readonly isClosed: boolean;
34
+ readonly rowType: RowType;
35
+ close: () => Promise<void>;
36
+ fetch: (rows: number) => Promise<Maybe<any[]>>;
37
+ }
38
+ interface Response {
39
+ fields?: Field[];
40
+ rows?: Record<string, any>[] | any[][];
41
+ rowType?: RowType;
42
+ cursor?: Adapter.Cursor;
43
+ rowsAffected?: number;
44
+ }
45
+ interface Field {
46
+ fieldName: string;
47
+ dataType: string;
48
+ jsType: string;
49
+ isArray?: boolean;
50
+ elementDataType?: string;
51
+ nullable?: boolean;
52
+ fixedLength?: boolean;
53
+ size?: number;
54
+ precision?: number;
55
+ _inf: any;
56
+ }
57
+ }
@@ -0,0 +1,29 @@
1
+ /// <reference types="node" />
2
+ import { Readable } from 'stream';
3
+ import { Cursor } from './cursor.js';
4
+ export interface CursorStreamOptions {
5
+ objectMode?: boolean;
6
+ limit?: number;
7
+ }
8
+ declare const inspect: unique symbol;
9
+ export declare class CursorStream extends Readable {
10
+ private readonly _cursor;
11
+ private readonly _objectMode?;
12
+ private readonly _limit;
13
+ private _rowNum;
14
+ private _eof;
15
+ constructor(cursor: Cursor, options?: CursorStreamOptions);
16
+ /**
17
+ * Returns if stream is closed.
18
+ */
19
+ get isClosed(): boolean;
20
+ /**
21
+ * Closes stream and releases the cursor
22
+ */
23
+ close(): Promise<void>;
24
+ toString(): string;
25
+ [inspect](): string;
26
+ _read(): void;
27
+ emit(event: string | symbol, ...args: any[]): boolean;
28
+ }
29
+ export {};
@@ -0,0 +1,116 @@
1
+ import { Adapter } from './adapter.js';
2
+ import { CursorStream, CursorStreamOptions } from './cursor-stream.js';
3
+ import { FieldInfoMap } from './field-info-map.js';
4
+ import { SqbConnection } from './sqb-connection.js';
5
+ import { ObjectRow, QueryRequest } from './types.js';
6
+ interface CursorEvents {
7
+ close: () => void;
8
+ error: (error: unknown) => void;
9
+ eof: () => void;
10
+ reset: () => void;
11
+ move: (row: any, rowNum: number) => void;
12
+ fetch: (row: any, rowNum: number) => void;
13
+ }
14
+ declare const Cursor_base: import("strict-typed-events").Type<import("strict-typed-events").TypedEventEmitter<any, CursorEvents, CursorEvents>>;
15
+ export declare class Cursor extends Cursor_base {
16
+ private readonly _connection;
17
+ private readonly _fields;
18
+ private readonly _prefetchRows;
19
+ private readonly _request;
20
+ private _intlcur?;
21
+ private _taskQueue;
22
+ private _fetchCache;
23
+ private _rowNum;
24
+ private _fetchedAll;
25
+ private _fetchedRows;
26
+ private _row;
27
+ private _cache?;
28
+ constructor(connection: SqbConnection, fields: FieldInfoMap, adapterCursor: Adapter.Cursor, request: QueryRequest);
29
+ /**
30
+ * Returns the Connection instance
31
+ */
32
+ get connection(): SqbConnection;
33
+ /**
34
+ * Returns if cursor is before first record.
35
+ */
36
+ get isBof(): boolean;
37
+ /**
38
+ * Returns if cursor is closed.
39
+ */
40
+ get isClosed(): boolean;
41
+ /**
42
+ * Returns if cursor is after last record.
43
+ */
44
+ get isEof(): boolean;
45
+ /**
46
+ * Returns number of fetched record count from database.
47
+ */
48
+ get fetchedRows(): number;
49
+ /**
50
+ * Returns object instance which contains information about fields.
51
+ */
52
+ get fields(): FieldInfoMap;
53
+ /**
54
+ * Returns current row
55
+ */
56
+ get row(): any;
57
+ /**
58
+ * Returns current row number.
59
+ */
60
+ get rowNum(): number;
61
+ /**
62
+ * Enables cache
63
+ */
64
+ cached(): void;
65
+ /**
66
+ * Closes cursor
67
+ */
68
+ close(): Promise<void>;
69
+ /**
70
+ * If cache is enabled, this call fetches and keeps all records in the internal cache.
71
+ * Otherwise it throws error. Once all all records fetched,
72
+ * you can close Cursor safely and can continue to use it in memory.
73
+ * Returns number of fetched rows
74
+ */
75
+ fetchAll(): Promise<number>;
76
+ /**
77
+ * Moves cursor to given row number.
78
+ * cursor can move both forward and backward if cache enabled.
79
+ * Otherwise it throws error.
80
+ */
81
+ moveTo(rowNum: number): Promise<ObjectRow>;
82
+ /**
83
+ * Moves cursor forward by one row and returns that row.
84
+ * And also it allows iterating over rows easily.
85
+ */
86
+ next(): Promise<ObjectRow>;
87
+ /**
88
+ * Moves cursor back by one row and returns that row.
89
+ * And also it allows iterating over rows easily.
90
+ */
91
+ prev(): Promise<ObjectRow>;
92
+ /**
93
+ * Moves cursor before first row. (Required cache enabled)
94
+ */
95
+ reset(): void;
96
+ /**
97
+ * Moves cursor by given step. If caching is enabled,
98
+ * cursor can move both forward and backward. Otherwise it throws error.
99
+ */
100
+ seek(step: number): Promise<ObjectRow>;
101
+ /**
102
+ * Creates and returns a readable stream.
103
+ */
104
+ toStream(options?: CursorStreamOptions): CursorStream;
105
+ toString(): string;
106
+ inspect(): string;
107
+ /**
108
+ *
109
+ */
110
+ _seek(step: number, silent?: boolean): Promise<number>;
111
+ /**
112
+ *
113
+ */
114
+ _fetchRows(): Promise<void>;
115
+ }
116
+ export {};
@@ -0,0 +1,4 @@
1
+ import { Adapter } from './adapter.js';
2
+ export declare let adapters: Adapter[];
3
+ export declare function registerAdapter(adapter: Adapter): void;
4
+ export declare function unRegisterAdapter(...adapter: Adapter[]): void;
@@ -0,0 +1,12 @@
1
+ import { FieldInfo } from './types.js';
2
+ export declare class FieldInfoMap {
3
+ private _obj;
4
+ private _arr;
5
+ constructor();
6
+ add(field: FieldInfo): void;
7
+ get(k: string | number): FieldInfo;
8
+ entries(): [string, FieldInfo][];
9
+ keys(): string[];
10
+ values(): FieldInfo[];
11
+ toJSON(): Record<string, FieldInfo>;
12
+ }
@@ -0,0 +1,9 @@
1
+ import { Maybe } from 'ts-gems';
2
+ import { Adapter } from './adapter.js';
3
+ import { FieldInfoMap } from './field-info-map.js';
4
+ import { ArrayRowset, FieldNaming, ObjectRowset, QueryRequest } from './types.js';
5
+ export declare function applyNamingStrategy(value: string, namingStrategy?: FieldNaming): Maybe<string>;
6
+ export declare function wrapAdapterFields(oldFields: Adapter.Field[], fieldNaming?: FieldNaming): FieldInfoMap;
7
+ export declare function normalizeRowsToObjectRows(fields: FieldInfoMap, rowType: 'array' | 'object', oldRows: ObjectRowset | ArrayRowset, options?: Pick<QueryRequest, 'ignoreNulls' | 'transform'>): Record<string, any>[];
8
+ export declare function normalizeRowsToArrayRows(fields: FieldInfoMap, rowType: 'array' | 'object', oldRows: ObjectRowset | ArrayRowset, options?: Pick<QueryRequest, 'ignoreNulls' | 'transform'>): any[][];
9
+ export declare function callFetchHooks(rows: ObjectRowset | ArrayRowset, request: QueryRequest): void;
@@ -0,0 +1,65 @@
1
+ import { Pool as LightningPool } from 'lightning-pool';
2
+ import { Maybe, Type } from 'ts-gems';
3
+ import { classes } from '@sqb/builder';
4
+ import { Repository } from '../orm/repository.class.js';
5
+ import { SqbConnection } from './sqb-connection.js';
6
+ import { ClientConfiguration, ClientDefaults, ConnectionOptions, QueryExecuteOptions, QueryRequest, QueryResult, TransactionFunction } from './types.js';
7
+ declare const inspect: unique symbol;
8
+ interface SqbClientEvents {
9
+ execute: (request: QueryRequest) => void;
10
+ error: (error: Error) => void;
11
+ closing: () => void;
12
+ close: () => void;
13
+ acquire: (connection: SqbConnection) => Promise<void>;
14
+ terminate: () => void;
15
+ 'connection-return': (connection: SqbConnection) => Promise<void>;
16
+ }
17
+ declare const SqbClient_base: Type<import("strict-typed-events").TypedEventEmitter<any, SqbClientEvents, SqbClientEvents>>;
18
+ export declare class SqbClient extends SqbClient_base {
19
+ private readonly _adapter;
20
+ private readonly _pool;
21
+ private readonly _defaults;
22
+ private readonly _entities;
23
+ constructor(config: ClientConfiguration);
24
+ get defaults(): ClientDefaults;
25
+ /**
26
+ * Returns dialect
27
+ */
28
+ get dialect(): string;
29
+ /**
30
+ * Returns database driver name
31
+ */
32
+ get driver(): string;
33
+ /**
34
+ * Returns true if pool is closed
35
+ */
36
+ get isClosed(): boolean;
37
+ get pool(): LightningPool;
38
+ /**
39
+ * Obtains a connection from the connection pool and executes the callback
40
+ */
41
+ acquire(fn: TransactionFunction, options?: ConnectionOptions): Promise<any>;
42
+ /**
43
+ * Obtains a connection from the connection pool.
44
+ */
45
+ acquire(options?: ConnectionOptions): Promise<SqbConnection>;
46
+ /**
47
+ * Shuts down the pool and destroys all resources.
48
+ */
49
+ close(terminateWait?: number): Promise<void>;
50
+ /**
51
+ * Executes a query or callback with a new acquired connection.
52
+ */
53
+ execute(query: string | classes.Query, options?: QueryExecuteOptions): Promise<QueryResult>;
54
+ /**
55
+ * Tests the pool
56
+ */
57
+ test(): Promise<void>;
58
+ getRepository<T>(entity: Type<T> | string, opts?: {
59
+ schema?: string;
60
+ }): Repository<T>;
61
+ getEntity<T>(name: string): Maybe<Type<T>>;
62
+ toString(): string;
63
+ [inspect](): string;
64
+ }
65
+ export {};
@@ -0,0 +1,74 @@
1
+ import { Type } from 'ts-gems';
2
+ import { classes } from '@sqb/builder';
3
+ import { Repository } from '../orm/repository.class.js';
4
+ import { Adapter } from './adapter.js';
5
+ import { SqbClient } from './sqb-client.js';
6
+ import { ConnectionOptions, QueryExecuteOptions, QueryRequest } from './types.js';
7
+ interface SqbConnectionEvents {
8
+ close: () => void;
9
+ execute: (request: QueryRequest) => void;
10
+ error: (error: Error) => void;
11
+ retain: (refCount: number) => void;
12
+ release: (refCount: number) => void;
13
+ 'start-transaction': () => void;
14
+ 'set-savepoint': () => void;
15
+ 'release-savepoint': () => void;
16
+ 'rollback-savepoint': () => void;
17
+ commit: () => void;
18
+ rollback: () => void;
19
+ }
20
+ declare const SqbConnection_base: Type<import("strict-typed-events").TypedEventEmitter<any, SqbConnectionEvents, SqbConnectionEvents>>;
21
+ export declare class SqbConnection extends SqbConnection_base {
22
+ readonly client: SqbClient;
23
+ private _intlcon?;
24
+ private readonly _tasks;
25
+ private readonly _options?;
26
+ private _inTransaction;
27
+ private _refCount;
28
+ constructor(client: SqbClient, adapterConnection: Adapter.Connection, options?: ConnectionOptions);
29
+ /**
30
+ * Returns session id
31
+ */
32
+ get sessionId(): string;
33
+ /**
34
+ * Returns reference counter value
35
+ */
36
+ get refCount(): number;
37
+ /**
38
+ * Returns true if transaction started
39
+ */
40
+ get inTransaction(): boolean;
41
+ /**
42
+ * Increases internal reference counter to keep session alive
43
+ */
44
+ retain(): void;
45
+ /**
46
+ * Decreases the internal reference counter.
47
+ * When reference count is 0, connection returns to the pool.
48
+ * Returns true if connection released.
49
+ */
50
+ release(): boolean;
51
+ /**
52
+ * Immediately releases the connection.
53
+ */
54
+ close(): Promise<void>;
55
+ execute(query: string | classes.Query, options?: QueryExecuteOptions): Promise<any>;
56
+ getRepository<T>(entity: Type<T> | string, opts?: {
57
+ schema?: string;
58
+ }): Repository<T>;
59
+ getSchema(): Promise<string>;
60
+ setSchema(schema: string): Promise<void>;
61
+ /**
62
+ * Executes a query
63
+ */
64
+ protected _execute(query: string | classes.Query, options?: QueryExecuteOptions): Promise<any>;
65
+ startTransaction(): Promise<void>;
66
+ commit(): Promise<void>;
67
+ rollback(): Promise<void>;
68
+ setSavepoint(savepoint: string): Promise<void>;
69
+ releaseSavepoint(savepoint: string): Promise<void>;
70
+ rollbackSavepoint(savepoint: string): Promise<void>;
71
+ test(): Promise<void>;
72
+ private _prepareQueryRequest;
73
+ }
74
+ export {};
@@ -0,0 +1,181 @@
1
+ import type { PoolConfiguration } from 'lightning-pool';
2
+ import { Maybe } from 'ts-gems';
3
+ import { DataType, ParamOptions } from '@sqb/builder';
4
+ import type { Adapter } from './adapter';
5
+ import type { Cursor } from './cursor';
6
+ import type { FieldInfoMap } from './field-info-map';
7
+ import type { SqbConnection } from './sqb-connection';
8
+ export { DataType } from '@sqb/builder';
9
+ export type ExecuteHookFunction = (connection: SqbConnection, request: QueryRequest) => Promise<void>;
10
+ export type FetchFunction = (row: any, request: QueryRequest) => void;
11
+ export type ValueTransformFunction = (value: any, fieldInfo?: FieldInfo) => any;
12
+ export type TransactionFunction = (connection: SqbConnection) => Promise<any>;
13
+ export type RowType = 'array' | 'object';
14
+ export type FieldNaming = 'original' | 'lowercase' | 'uppercase' | 'camelcase' | 'pascalcase' | ((fieldName: string) => Maybe<string>);
15
+ export type ObjectRow = Record<string, any>;
16
+ export type ArrayRow = any[];
17
+ export type ObjectRowset = ObjectRow[];
18
+ export type ArrayRowset = ArrayRow[];
19
+ export interface ClientConfiguration {
20
+ /**
21
+ * Dialect to be used
22
+ */
23
+ dialect?: string;
24
+ /**
25
+ * Database connection driver to be used
26
+ */
27
+ driver?: string;
28
+ /**
29
+ * Connection name
30
+ */
31
+ name?: string;
32
+ /**
33
+ * Database server address or url
34
+ */
35
+ host?: string;
36
+ /**
37
+ * Database listener port number
38
+ *
39
+ */
40
+ port?: number;
41
+ /**
42
+ * Database username.
43
+ */
44
+ user?: string;
45
+ /**
46
+ * Database password.
47
+ */
48
+ password?: string;
49
+ /**
50
+ * Database name
51
+ */
52
+ database?: string;
53
+ /**
54
+ * Database schema
55
+ */
56
+ schema?: string;
57
+ /**
58
+ * Connection options to be passed to the underlying driver
59
+ */
60
+ driverOptions?: any;
61
+ /**
62
+ * Pooling options
63
+ */
64
+ pool?: PoolConfiguration;
65
+ /**
66
+ * Default options
67
+ */
68
+ defaults?: ClientDefaults;
69
+ }
70
+ export interface ClientDefaults {
71
+ autoCommit?: boolean;
72
+ cursor?: boolean;
73
+ objectRows?: boolean;
74
+ fieldNaming?: FieldNaming;
75
+ showSql?: boolean;
76
+ prettyPrint?: boolean;
77
+ ignoreNulls?: boolean;
78
+ /**
79
+ * Sets how many row will be fetched at a time
80
+ * Default = 10
81
+ */
82
+ fetchRows?: number;
83
+ transform?: ValueTransformFunction;
84
+ }
85
+ export interface ConnectionOptions {
86
+ /**
87
+ * If this property is true, the transaction committed at the end of query execution.
88
+ * Default = false
89
+ */
90
+ autoCommit?: boolean;
91
+ }
92
+ export interface QueryExecuteOptions {
93
+ /**
94
+ * Array of values or object that contains param/value pairs.
95
+ */
96
+ params?: Record<string, any> | any[];
97
+ /**
98
+ * If this property is true, the transaction committed at the end of query execution.
99
+ * Default = false
100
+ */
101
+ autoCommit?: boolean;
102
+ /**
103
+ * If this property is true, query returns a Cursor object that works
104
+ * in unidirectional "cursor" mode.
105
+ * Important! Cursor keeps connection open until cursor.close() method is called.
106
+ */
107
+ cursor?: boolean;
108
+ /**
109
+ * Function for converting data before returning response.
110
+ */
111
+ transform?: ValueTransformFunction;
112
+ /**
113
+ * In "cursor" mode; it provides an initial suggested number of rows to prefetch.
114
+ * Prefetching is a tuning option to maximize data transfer efficiency and
115
+ * minimize round-trips to the database. In regular mode;
116
+ * it provides the maximum number of rows that are fetched from Connection instance.
117
+ * Default = 10
118
+ */
119
+ fetchRows?: number;
120
+ /**
121
+ * If set true, NULL fields will be ignored
122
+ * Default = false
123
+ */
124
+ ignoreNulls?: boolean;
125
+ /**
126
+ * Sets the naming strategy for fields. It affects field names in object rows and metadata
127
+ */
128
+ namingStrategy?: FieldNaming;
129
+ /**
130
+ * Determines whether query rows should be returned as Objects or Arrays.
131
+ * This property applies to ResultSet.objectRows property also.
132
+ * Default = driver default
133
+ */
134
+ objectRows?: boolean;
135
+ /**
136
+ * If set true, result object contains executed sql and values.
137
+ * Default = false
138
+ */
139
+ showSql?: boolean;
140
+ prettyPrint?: boolean;
141
+ action?: string;
142
+ fetchAsString?: DataType[];
143
+ }
144
+ export interface QueryResult {
145
+ executeTime: number;
146
+ fields?: FieldInfoMap;
147
+ rows?: any;
148
+ rowType?: RowType;
149
+ query?: QueryRequest;
150
+ returns?: any;
151
+ rowsAffected?: number;
152
+ cursor?: Cursor;
153
+ }
154
+ export type FieldInfo = {
155
+ index: number;
156
+ name: string;
157
+ } & Adapter.Field;
158
+ export interface QueryRequest {
159
+ dialect?: string;
160
+ dialectVersion?: string;
161
+ sql: string;
162
+ params?: any;
163
+ paramOptions?: Record<string, ParamOptions> | ParamOptions[];
164
+ returningFields?: {
165
+ field: string;
166
+ alias?: string;
167
+ }[];
168
+ autoCommit?: boolean;
169
+ cursor?: boolean;
170
+ objectRows?: boolean;
171
+ ignoreNulls?: boolean;
172
+ fetchRows?: number;
173
+ fieldNaming?: FieldNaming;
174
+ transform?: ValueTransformFunction;
175
+ showSql?: boolean;
176
+ prettyPrint?: boolean;
177
+ action?: string;
178
+ fetchAsString?: DataType[];
179
+ executeHooks?: ExecuteHookFunction[];
180
+ fetchHooks?: FetchFunction[];
181
+ }
@@ -0,0 +1,34 @@
1
+ import 'reflect-metadata';
2
+ import { DeepBuildable, DeepPartial, DeepPickWritable, Maybe, Type } from 'ts-gems';
3
+ export { Type, Maybe, DeepPartial, DeepPickWritable, DeepBuildable };
4
+ export * from './types.js';
5
+ export * from './client/types.js';
6
+ export * from './client/adapter.js';
7
+ export * from './client/sqb-client.js';
8
+ export * from './client/sqb-connection.js';
9
+ export * from './client/cursor.js';
10
+ export { registerAdapter, unRegisterAdapter } from './client/extensions.js';
11
+ export * from './orm/orm.type.js';
12
+ export * from './orm/orm.const.js';
13
+ export * from './orm/base-entity.js';
14
+ export * from './orm/repository.class.js';
15
+ export * from './orm/model/entity-metadata.js';
16
+ export * from './orm/model/field-metadata.js';
17
+ export * from './orm/model/column-field-metadata.js';
18
+ export * from './orm/model/embedded-field-metadata.js';
19
+ export * from './orm/model/association-field-metadata.js';
20
+ export * from './orm/model/association.js';
21
+ export * from './orm/model/association-node.js';
22
+ export * from './orm/model/index-metadata.js';
23
+ export * from './orm/model/link-chain.js';
24
+ export * from './orm/decorators/column.decorator.js';
25
+ export * from './orm/decorators/embedded.decorator.js';
26
+ export * from './orm/decorators/entity.decorator.js';
27
+ export * from './orm/decorators/events.decorator.js';
28
+ export * from './orm/decorators/foreignkey.decorator.js';
29
+ export * from './orm/decorators/index.decorator.js';
30
+ export * from './orm/decorators/link.decorator.js';
31
+ export * from './orm/decorators/primarykey.decorator.js';
32
+ export * from './orm/decorators/transform.decorator.js';
33
+ export { isColumnField, isEmbeddedField, isAssociationField, isEntityClass } from './orm/util/orm.helper.js';
34
+ export * from './orm/backward.js';
@@ -0,0 +1,13 @@
1
+ import { PickWritable, Type } from 'ts-gems';
2
+ import { Entity } from './decorators/entity.decorator.js';
3
+ export declare function getInsertColumnNames<T, K extends keyof PickWritable<T>>(ctor: Type<T>): K[];
4
+ export declare function getUpdateColumnNames<T, K extends keyof PickWritable<T>>(ctor: Type<T>): K[];
5
+ export declare function getNonAssociationElementNames<T, K extends keyof PickWritable<T>>(ctor: Type<T>): K[];
6
+ export declare function mixinEntities<A, B>(derivedCtor: Type<A>, baseB: Type<B>): Type<A & B>;
7
+ export declare function mixinEntities<A, B, C>(derivedCtor: Type<A>, baseB: Type<B>, baseC: Type<C>): Type<A & B & C>;
8
+ export declare function mixinEntities<A, B, C, D>(derivedCtor: Type<A>, baseB: Type<B>, baseC: Type<C>, baseD: Type<D>): Type<A & B & C & D>;
9
+ export declare function mixinEntities<A, B, C, D, E>(derivedCtor: Type<A>, baseB: Type<B>, baseC: Type<C>, baseD: Type<D>, baseE: Type<E>): Type<A & B & C & D & E>;
10
+ export declare function mixinEntities<A, B, C, D, E, F>(derivedCtor: Type<A>, baseB: Type<B>, baseC: Type<C>, baseD: Type<D>, baseE: Type<E>, baseF: Type<F>): Type<A & B & C & D & E & F>;
11
+ export declare const OmitEntity: typeof Entity.Omit;
12
+ export declare const PickEntity: typeof Entity.Pick;
13
+ export declare const UnionEntity: typeof Entity.Union;
@@ -0,0 +1,8 @@
1
+ import { REPOSITORY_KEY } from './orm.const.js';
2
+ export declare class BaseEntity {
3
+ private [REPOSITORY_KEY]?;
4
+ constructor(partial?: any);
5
+ destroy(): Promise<boolean>;
6
+ exists(): Promise<boolean>;
7
+ toJSON(): any;
8
+ }
@@ -0,0 +1,14 @@
1
+ import { JoinStatement, LogicalOperator } from '@sqb/builder';
2
+ import { AssociationNode } from '../model/association-node.js';
3
+ import { EntityMetadata } from '../model/entity-metadata.js';
4
+ export interface JoinInfo {
5
+ association: AssociationNode;
6
+ sourceEntity: EntityMetadata;
7
+ targetEntity: EntityMetadata;
8
+ joinAlias: string;
9
+ join: JoinStatement;
10
+ }
11
+ export declare function joinAssociationGetFirst(joinInfos: JoinInfo[], association: AssociationNode, parentAlias: string, innerJoin?: boolean): Promise<JoinInfo>;
12
+ export declare function joinAssociationGetLast(joinInfos: JoinInfo[], association: AssociationNode, parentAlias: string, innerJoin?: boolean): Promise<JoinInfo>;
13
+ export declare function joinAssociation(joinInfos: JoinInfo[], association: AssociationNode, parentAlias: string, innerJoin?: boolean): Promise<JoinInfo[]>;
14
+ export declare function prepareFilter(entityDef: EntityMetadata, filter: any, trgOp: LogicalOperator, tableAlias?: string): Promise<void>;
@@ -0,0 +1,11 @@
1
+ import { SqbConnection } from '../../client/sqb-connection.js';
2
+ import { EntityMetadata } from '../model/entity-metadata.js';
3
+ import { Repository } from '../repository.class.js';
4
+ export type CountCommandArgs = {
5
+ entity: EntityMetadata;
6
+ connection: SqbConnection;
7
+ } & Repository.CountOptions;
8
+ export declare class CountCommand {
9
+ protected constructor();
10
+ static execute(args: CountCommandArgs): Promise<number>;
11
+ }