UNPKG

8.17 kBTypeScriptView Raw
1/// <reference types="@fxjs/sql-query" />
2/// <reference types="@fxjs/sql-ddl-sync" />
3/// <reference types="@fxjs/knex" />
4
5/// <reference path="_common.d.ts" />
6/// <reference path="property.d.ts" />
7/// <reference path="assoc.d.ts" />
8/// <reference path="query.d.ts" />
9
10declare namespace FxOrmDMLDriver {
11 type DriverUidType = string
12
13 interface QueryDataPayload {
14 [key: string]: any
15 }
16
17 interface QueriedCountDataPayload {
18 c: number
19 }
20
21 interface DMLDriverOptions {
22 // useless now
23 pool?: boolean
24 debug?: boolean
25
26 settings: FxOrmSettings.SettingInstance
27 }
28
29 interface DMLDriverConstructor {
30 new (config: FxDbDriverNS.DBConnectionConfig, connection: FxOrmDb.DatabaseBase, opts: FxOrmDMLDriver.DMLDriverOptions): DMLDriver
31 prototype: DMLDriver
32 }
33
34 interface DMLDriver<ConnType = any> {
35 readonly db: FxOrmDb.DatabaseBase<ConnType>
36 readonly config: FxOrmDb.DatabaseBase<ConnType>['config']
37
38 customTypes: {[key: string]: FxOrmProperty.CustomPropertyType}
39
40 knex: FXJSKnex.FXJSKnexModule.KnexInstance
41
42 readonly query: FxSqlQuery.Class_Query
43 /**
44 * @deprecated
45 */
46 getQuery: {
47 (): FxSqlQuery.Class_Query
48 }
49
50 readonly ddlDialect: FxOrmSqlDDLSync__Dialect.Dialect
51
52 /* shared :start */
53 doSync <T = any>(opts?: FxOrmDMLShared.SyncOptions): this
54 doDrop <T = any>(opts?: FxOrmDMLShared.DropOptions): this
55 /* shared :end */
56
57 connect: {
58 (cb: FxOrmNS.GenericCallback<FxDbDriverNS.Driver>): void
59 (): FxDbDriverNS.Driver
60 }
61 reconnect: {
62 (cb: FxOrmNS.GenericCallback<FxDbDriverNS.Driver>): void
63 (): FxDbDriverNS.Driver
64 }
65 ping: {
66 (cb?: FxOrmNS.VoidCallback): void
67 }
68 on: {
69 <T>(ev: string, cb?: FxOrmNS.GenericCallback<T>): void
70 }
71 close: {
72 (cb?: FxOrmNS.VoidCallback): void
73 }
74 /**
75 * @description
76 * aggregate_functions could be string tuple such as
77 *
78 * [`RANDOM`, `RAND`] ---> FxOrmDb.AGGREGATION_METHOD_TUPLE__COMMON
79 */
80 aggregate_functions: ( (FxOrmDb.AGGREGATION_METHOD_COMPLEX) | FxOrmDb.AGGREGATION_METHOD_TUPLE__COMMON )[]
81 execSimpleQuery: {
82 <T=any>(query: string, cb?: FxOrmNS.GenericCallback<T>): T
83 }
84 /**
85 * @description do eager-query
86 */
87 eagerQuery: {
88 <T = any>(association: FxOrmAssociation.InstanceAssociationItem, opts: FxOrmQuery.ChainFindOptions, keys: string[], cb?: FibOrmNS.GenericCallback<T>): T
89 }
90
91 find: {
92 <T=FxOrmDMLDriver.QueryDataPayload[]>(fields: FxSqlQueryColumns.SelectInputArgType[], table: string, conditions: FxSqlQuerySubQuery.SubQueryConditions, opts: DMLDriver_FindOptions, cb?: FxOrmNS.GenericCallback<T>): T
93 }
94 count: {
95 /**
96 * mysql: {c: number}
97 * sqlite: {c: number}
98 */
99 (table: string, conditions: FxSqlQuerySubQuery.SubQueryConditions, opts: DMLDriver_CountOptions, cb?: FxOrmNS.GenericCallback<FxOrmQuery.CountResult[]>): FxOrmQuery.CountResult[]
100 }
101 insert: {
102 (table: string, data: FxSqlQuerySql.DataToSet, keyProperties: FxOrmProperty.NormalizedProperty[], cb?: FxOrmNS.GenericCallback<FxOrmQuery.InsertResult>): FxOrmQuery.InsertResult
103 }
104 update: {
105 <T=any>(table: string, changes: FxSqlQuerySql.DataToSet, conditions: FxSqlQuerySubQuery.SubQueryConditions, cb?: FxOrmNS.GenericCallback<T>): T
106 }
107 remove: {
108 <T=any>(table: string, conditions: FxSqlQuerySubQuery.SubQueryConditions, cb?: FxOrmNS.GenericCallback<T>): T
109 }
110 clear: {
111 <T=any>(table: string, cb?: FxOrmNS.GenericCallback<T>): T
112 }
113 poolQuery: {
114 <T=any>(query: string, cb?: FxOrmNS.GenericCallback<T>): T
115 }
116 valueToProperty: {
117 (value: any, property: FxOrmProperty.NormalizedProperty): any
118 }
119 propertyToValue: {
120 (value: any, property: FxOrmProperty.NormalizedProperty): any
121 }
122 readonly isSql: boolean
123
124 /* patched :start */
125 // uniq id
126 uid: string
127 hasMany?: {
128 (Model: FxOrmModel.Model, association: FxOrmAssociation.InstanceAssociationItem): any
129 }
130
131 execQuerySync: (query: string, opt: Fibjs.AnyObject) => any
132 /* patched :end */
133
134 [ext_key: string]: any
135 }
136 /* ============================= DMLDriver API Options :start ============================= */
137 // type ChainWhereExistsInfoPayload = {[key: string]: FxOrmQuery.ChainWhereExistsInfo} | FxOrmQuery.ChainWhereExistsInfo[]
138 type ChainWhereExistsInfoPayload = FxOrmQuery.ChainWhereExistsInfo[]
139
140 interface DMLDriver_FindOptions {
141 offset?: number
142 limit?: number
143 order?: FxOrmQuery.OrderNormalizedResult[]
144 merge?: FxOrmQuery.ChainFindMergeInfo[]
145 exists?: ChainWhereExistsInfoPayload
146 }
147 interface DMLDriver_CountOptions {
148 merge?: DMLDriver_FindOptions['merge']
149 exists?: DMLDriver_FindOptions['exists']
150 }
151 /* ============================= DMLDriver API Options :end ============================= */
152
153 /* ============================= typed db :start ============================= */
154
155 interface DMLDriverConstructor_MySQL extends DMLDriverConstructor {
156 (this: DMLDriver_MySQL, config: FxDbDriverNS.DBConnectionConfig, connection: FxOrmDb.DatabaseBase<Class_MySQL>, opts: FxOrmDMLDriver.DMLDriverOptions): void
157 prototype: DMLDriver_MySQL
158 }
159 interface DMLDriver_MySQL extends DMLDriver {
160 db: FxOrmDb.DatabaseBase<Class_MySQL>
161
162 aggregate_functions: (FxOrmDb.AGGREGATION_METHOD_MYSQL | FxOrmDb.AGGREGATION_METHOD_TUPLE__MYSQL)[]
163 }
164 interface DMLDriverConstructor_PostgreSQL extends DMLDriverConstructor {
165 (this: DMLDriver_PostgreSQL, config: FxDbDriverNS.DBConnectionConfig, connection: FxOrmDb.DatabaseBase_PostgreSQL, opts: FxOrmDMLDriver.DMLDriverOptions): void
166 prototype: DMLDriver_PostgreSQL
167 }
168 interface DMLDriver_PostgreSQL extends DMLDriver {
169 db: FxOrmDb.DatabaseBase_PostgreSQL
170
171 aggregate_functions: (FxOrmDb.AGGREGATION_METHOD_POSTGRESQL)[]
172 }
173
174 interface DMLDriverConstructor_SQLite extends DMLDriverConstructor {
175 (this: DMLDriver_SQLite, config: FxDbDriverNS.DBConnectionConfig, connection: FxOrmDb.DatabaseBase_SQLite, opts: FxOrmDMLDriver.DMLDriverOptions): void
176 prototype: DMLDriver_SQLite
177 }
178 interface DMLDriver_SQLite extends DMLDriver {
179 db: FxOrmDb.DatabaseBase_SQLite
180
181 aggregate_functions: (FxOrmDb.AGGREGATION_METHOD_SQLITE)[]
182 }
183
184 /* ============================= typed db :end ============================= */
185 // type DefaultSqlDialect = FxOrmSqlDDLSync__Dialect.Dialect<FxSqlQuery.Class_Query>
186 type DefaultSqlDialect = FxOrmSqlDDLSync__Dialect.Dialect
187}
188
189declare namespace FxOrmDMLShared {
190 interface SyncOptions {
191 id: string[]
192 extension: boolean
193 table: string
194 allProperties: FxOrmProperty.NormalizedPropertyHash
195 indexes: string[]
196 customTypes: {
197 [key: string]: FxOrmProperty.CustomPropertyType;
198 }
199 one_associations: FxOrmAssociation.InstanceAssociationItem_HasOne[]
200 many_associations: FxOrmAssociation.InstanceAssociationItem_HasMany[]
201 extend_associations: FxOrmAssociation.InstanceAssociationItem_ExtendTos[]
202
203 /**
204 * @default true
205 */
206 repair_column?: boolean
207 /**
208 * @default false
209 */
210 allow_drop_column?: boolean
211 }
212
213 interface DropOptions {
214 table: string
215 properties: FxOrmProperty.NormalizedPropertyHash
216 one_associations: FxOrmAssociation.InstanceAssociationItem_HasOne[]
217 many_associations: FxOrmAssociation.InstanceAssociationItem_HasMany[]
218 }
219}
\No newline at end of file