node-mybatis-plus 0.1.0
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/README.md +426 -0
- package/dist/index.d.mts +302 -0
- package/dist/index.d.ts +302 -0
- package/dist/index.js +1051 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1006 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +72 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
interface ColumnMeta {
|
|
2
|
+
propertyName: string;
|
|
3
|
+
columnName: string;
|
|
4
|
+
isPrimary: boolean;
|
|
5
|
+
idType?: 'auto' | 'uuid' | 'snowflake' | 'input';
|
|
6
|
+
exist: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface EntityMeta {
|
|
9
|
+
tableName: string;
|
|
10
|
+
columns: ColumnMeta[];
|
|
11
|
+
idColumn: ColumnMeta | null;
|
|
12
|
+
target: Function;
|
|
13
|
+
}
|
|
14
|
+
interface Condition {
|
|
15
|
+
column: string;
|
|
16
|
+
op: '=' | '!=' | '>' | '>=' | '<' | '<=' | 'LIKE' | 'IN' | 'NOT IN' | 'BETWEEN' | 'IS NULL' | 'IS NOT NULL';
|
|
17
|
+
value?: any;
|
|
18
|
+
value2?: any;
|
|
19
|
+
}
|
|
20
|
+
interface ConditionGroup {
|
|
21
|
+
logic: 'AND' | 'OR';
|
|
22
|
+
items: (Condition | ConditionGroup)[];
|
|
23
|
+
}
|
|
24
|
+
interface OrderByItem {
|
|
25
|
+
column: string;
|
|
26
|
+
direction: 'ASC' | 'DESC';
|
|
27
|
+
}
|
|
28
|
+
interface SelectNode {
|
|
29
|
+
type: 'select';
|
|
30
|
+
table: string;
|
|
31
|
+
columns: string[];
|
|
32
|
+
where: ConditionGroup | null;
|
|
33
|
+
orderBy: OrderByItem[];
|
|
34
|
+
groupBy: string[];
|
|
35
|
+
having: ConditionGroup | null;
|
|
36
|
+
limit: {
|
|
37
|
+
offset: number;
|
|
38
|
+
count: number;
|
|
39
|
+
} | null;
|
|
40
|
+
}
|
|
41
|
+
interface InsertNode {
|
|
42
|
+
type: 'insert';
|
|
43
|
+
table: string;
|
|
44
|
+
columns: string[];
|
|
45
|
+
values: any[][];
|
|
46
|
+
}
|
|
47
|
+
interface UpdateNode {
|
|
48
|
+
type: 'update';
|
|
49
|
+
table: string;
|
|
50
|
+
sets: {
|
|
51
|
+
column: string;
|
|
52
|
+
value: any;
|
|
53
|
+
}[];
|
|
54
|
+
where: ConditionGroup | null;
|
|
55
|
+
}
|
|
56
|
+
interface DeleteNode {
|
|
57
|
+
type: 'delete';
|
|
58
|
+
table: string;
|
|
59
|
+
where: ConditionGroup | null;
|
|
60
|
+
}
|
|
61
|
+
type SqlNode = SelectNode | InsertNode | UpdateNode | DeleteNode;
|
|
62
|
+
interface Dialect {
|
|
63
|
+
placeholder(index: number): string;
|
|
64
|
+
quote(identifier: string): string;
|
|
65
|
+
paginate(sql: string, offset: number, limit: number): string;
|
|
66
|
+
insertReturningId(table: string, columns: string[], idColumn: string): string | null;
|
|
67
|
+
}
|
|
68
|
+
interface PluginContext {
|
|
69
|
+
node: SqlNode;
|
|
70
|
+
sql: string;
|
|
71
|
+
params: any[];
|
|
72
|
+
entityMeta: EntityMeta;
|
|
73
|
+
}
|
|
74
|
+
interface Plugin {
|
|
75
|
+
name: string;
|
|
76
|
+
order: number;
|
|
77
|
+
beforeExecute?(ctx: PluginContext): Promise<void> | void;
|
|
78
|
+
afterExecute?(ctx: PluginContext, result: any): Promise<any> | any;
|
|
79
|
+
}
|
|
80
|
+
interface PoolConfig {
|
|
81
|
+
min?: number;
|
|
82
|
+
max?: number;
|
|
83
|
+
idleTimeout?: number;
|
|
84
|
+
acquireTimeout?: number;
|
|
85
|
+
}
|
|
86
|
+
interface DataSourceConfig {
|
|
87
|
+
type: 'mysql' | 'postgres' | 'sqlite';
|
|
88
|
+
host?: string;
|
|
89
|
+
port?: number;
|
|
90
|
+
database: string;
|
|
91
|
+
username?: string;
|
|
92
|
+
password?: string;
|
|
93
|
+
pool?: PoolConfig;
|
|
94
|
+
plugins?: Plugin[];
|
|
95
|
+
namingStrategy?: 'camelToSnake' | ((name: string) => string);
|
|
96
|
+
}
|
|
97
|
+
interface Connection {
|
|
98
|
+
query(sql: string, params: any[]): Promise<any>;
|
|
99
|
+
release(): void;
|
|
100
|
+
}
|
|
101
|
+
interface DataSource {
|
|
102
|
+
config: DataSourceConfig;
|
|
103
|
+
dialect: Dialect;
|
|
104
|
+
plugins: Plugin[];
|
|
105
|
+
getConnection(): Promise<Connection>;
|
|
106
|
+
execute(sql: string, params: any[]): Promise<any>;
|
|
107
|
+
close(): Promise<void>;
|
|
108
|
+
transaction<T>(fn: (tx: TransactionContext) => Promise<T>): Promise<T>;
|
|
109
|
+
}
|
|
110
|
+
interface TransactionContext {
|
|
111
|
+
connection: Connection;
|
|
112
|
+
commit(): Promise<void>;
|
|
113
|
+
rollback(): Promise<void>;
|
|
114
|
+
}
|
|
115
|
+
interface Page<T> {
|
|
116
|
+
records: T[];
|
|
117
|
+
total: number;
|
|
118
|
+
page: number;
|
|
119
|
+
size: number;
|
|
120
|
+
pages: number;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
declare function Table(tableName: string): ClassDecorator;
|
|
124
|
+
interface IdOptions {
|
|
125
|
+
type?: 'auto' | 'uuid' | 'snowflake' | 'input';
|
|
126
|
+
}
|
|
127
|
+
declare function Id(options?: IdOptions): PropertyDecorator;
|
|
128
|
+
interface ColumnOptions {
|
|
129
|
+
name?: string;
|
|
130
|
+
exist?: boolean;
|
|
131
|
+
}
|
|
132
|
+
declare function Column(nameOrOptions?: string | ColumnOptions): PropertyDecorator;
|
|
133
|
+
|
|
134
|
+
declare function createDataSource(config: DataSourceConfig): DataSource;
|
|
135
|
+
|
|
136
|
+
/** 编程式事务(配合 AsyncLocalStorage 自动传播) */
|
|
137
|
+
declare function withTransaction<T>(ds: DataSource, fn: () => Promise<T>): Promise<T>;
|
|
138
|
+
declare function setDefaultDataSource(ds: DataSource): void;
|
|
139
|
+
declare function getDefaultDataSource(): DataSource;
|
|
140
|
+
interface TransactionalOptions {
|
|
141
|
+
datasource?: DataSource;
|
|
142
|
+
}
|
|
143
|
+
declare function Transactional(options?: TransactionalOptions): MethodDecorator;
|
|
144
|
+
|
|
145
|
+
declare class MysqlDialect implements Dialect {
|
|
146
|
+
placeholder(_index: number): string;
|
|
147
|
+
quote(identifier: string): string;
|
|
148
|
+
paginate(sql: string, offset: number, limit: number): string;
|
|
149
|
+
insertReturningId(): null;
|
|
150
|
+
}
|
|
151
|
+
declare class PostgresDialect implements Dialect {
|
|
152
|
+
placeholder(index: number): string;
|
|
153
|
+
quote(identifier: string): string;
|
|
154
|
+
paginate(sql: string, offset: number, limit: number): string;
|
|
155
|
+
insertReturningId(_table: string, _columns: string[], idColumn: string): string;
|
|
156
|
+
}
|
|
157
|
+
declare class SqliteDialect implements Dialect {
|
|
158
|
+
placeholder(_index: number): string;
|
|
159
|
+
quote(identifier: string): string;
|
|
160
|
+
paginate(sql: string, offset: number, limit: number): string;
|
|
161
|
+
insertReturningId(): null;
|
|
162
|
+
}
|
|
163
|
+
declare function createDialect(type: string): Dialect;
|
|
164
|
+
|
|
165
|
+
declare class AbstractWrapper<T, Self extends AbstractWrapper<T, Self>> {
|
|
166
|
+
protected entityMeta: EntityMeta;
|
|
167
|
+
protected conditionGroup: ConditionGroup;
|
|
168
|
+
protected _orderBy: OrderByItem[];
|
|
169
|
+
protected _groupBy: string[];
|
|
170
|
+
protected _having: ConditionGroup | null;
|
|
171
|
+
constructor(entityMeta: EntityMeta);
|
|
172
|
+
eq(column: keyof T & string, value: any): Self;
|
|
173
|
+
eq(condition: boolean, column: keyof T & string, value: any): Self;
|
|
174
|
+
ne(column: keyof T & string, value: any): Self;
|
|
175
|
+
ne(condition: boolean, column: keyof T & string, value: any): Self;
|
|
176
|
+
gt(column: keyof T & string, value: any): Self;
|
|
177
|
+
gt(condition: boolean, column: keyof T & string, value: any): Self;
|
|
178
|
+
ge(column: keyof T & string, value: any): Self;
|
|
179
|
+
ge(condition: boolean, column: keyof T & string, value: any): Self;
|
|
180
|
+
lt(column: keyof T & string, value: any): Self;
|
|
181
|
+
lt(condition: boolean, column: keyof T & string, value: any): Self;
|
|
182
|
+
le(column: keyof T & string, value: any): Self;
|
|
183
|
+
le(condition: boolean, column: keyof T & string, value: any): Self;
|
|
184
|
+
like(column: keyof T & string, value: string): Self;
|
|
185
|
+
like(condition: boolean, column: keyof T & string, value: string): Self;
|
|
186
|
+
likeLeft(column: keyof T & string, value: string): Self;
|
|
187
|
+
likeLeft(condition: boolean, column: keyof T & string, value: string): Self;
|
|
188
|
+
likeRight(column: keyof T & string, value: string): Self;
|
|
189
|
+
likeRight(condition: boolean, column: keyof T & string, value: string): Self;
|
|
190
|
+
between(column: keyof T & string, val1: any, val2: any): Self;
|
|
191
|
+
between(condition: boolean, column: keyof T & string, val1: any, val2: any): Self;
|
|
192
|
+
in(column: keyof T & string, values: any[]): Self;
|
|
193
|
+
in(condition: boolean, column: keyof T & string, values: any[]): Self;
|
|
194
|
+
notIn(column: keyof T & string, values: any[]): Self;
|
|
195
|
+
notIn(condition: boolean, column: keyof T & string, values: any[]): Self;
|
|
196
|
+
isNull(column: keyof T & string): Self;
|
|
197
|
+
isNull(condition: boolean, column: keyof T & string): Self;
|
|
198
|
+
isNotNull(column: keyof T & string): Self;
|
|
199
|
+
isNotNull(condition: boolean, column: keyof T & string): Self;
|
|
200
|
+
or(fn: (w: Self) => void): Self;
|
|
201
|
+
and(fn: (w: Self) => void): Self;
|
|
202
|
+
orderByAsc(...columns: (keyof T & string)[]): Self;
|
|
203
|
+
orderByDesc(...columns: (keyof T & string)[]): Self;
|
|
204
|
+
groupBy(...columns: (keyof T & string)[]): Self;
|
|
205
|
+
protected resolveColumn(propertyName: string): string;
|
|
206
|
+
getConditionGroup(): ConditionGroup;
|
|
207
|
+
getOrderBy(): OrderByItem[];
|
|
208
|
+
getGroupBy(): string[];
|
|
209
|
+
getHaving(): ConditionGroup | null;
|
|
210
|
+
private addCondition;
|
|
211
|
+
private parseArgs;
|
|
212
|
+
private createNested;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
declare class LambdaQueryWrapper<T> extends AbstractWrapper<T, LambdaQueryWrapper<T>> {
|
|
216
|
+
private _columns;
|
|
217
|
+
private _limit;
|
|
218
|
+
private _datasource;
|
|
219
|
+
constructor(entityMeta: EntityMeta);
|
|
220
|
+
/** 绑定数据源(由 BaseMapper 调用) */
|
|
221
|
+
bindDataSource(ds: DataSource): this;
|
|
222
|
+
select(...columns: (keyof T & string)[]): this;
|
|
223
|
+
page(page: number, size: number): this;
|
|
224
|
+
/** 构建 SelectNode AST */
|
|
225
|
+
buildSelectNode(): SelectNode;
|
|
226
|
+
/** 终结操作:执行查询返回列表 */
|
|
227
|
+
list(): Promise<T[]>;
|
|
228
|
+
/** 终结操作:查询单条 */
|
|
229
|
+
one(): Promise<T | null>;
|
|
230
|
+
/** 终结操作:查询数量 */
|
|
231
|
+
count(): Promise<number>;
|
|
232
|
+
/** 终结操作:分页查询 */
|
|
233
|
+
pageResult(page: number, size: number): Promise<Page<T>>;
|
|
234
|
+
private requireDs;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
declare class LambdaUpdateWrapper<T> extends AbstractWrapper<T, LambdaUpdateWrapper<T>> {
|
|
238
|
+
private _sets;
|
|
239
|
+
private _datasource;
|
|
240
|
+
constructor(entityMeta: EntityMeta);
|
|
241
|
+
bindDataSource(ds: DataSource): this;
|
|
242
|
+
set(column: keyof T & string, value: any): this;
|
|
243
|
+
set(condition: boolean, column: keyof T & string, value: any): this;
|
|
244
|
+
buildUpdateNode(): UpdateNode;
|
|
245
|
+
execute(): Promise<number>;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
declare class BaseMapper<T extends object> {
|
|
249
|
+
protected entityMeta: EntityMeta;
|
|
250
|
+
protected ds: DataSource;
|
|
251
|
+
constructor(entityClass: Function, datasource: DataSource);
|
|
252
|
+
lambdaQuery(): LambdaQueryWrapper<T>;
|
|
253
|
+
lambdaUpdate(): LambdaUpdateWrapper<T>;
|
|
254
|
+
insert(entity: Partial<T>): Promise<number>;
|
|
255
|
+
insertBatch(entities: Partial<T>[]): Promise<number>;
|
|
256
|
+
deleteById(id: any): Promise<number>;
|
|
257
|
+
deleteBatchIds(ids: any[]): Promise<number>;
|
|
258
|
+
delete(wrapper: LambdaQueryWrapper<T>): Promise<number>;
|
|
259
|
+
updateById(entity: Partial<T>): Promise<number>;
|
|
260
|
+
update(entity: Partial<T>, wrapper: LambdaQueryWrapper<T>): Promise<number>;
|
|
261
|
+
selectById(id: any): Promise<T | null>;
|
|
262
|
+
selectBatchIds(ids: any[]): Promise<T[]>;
|
|
263
|
+
selectOne(wrapper: LambdaQueryWrapper<T>): Promise<T | null>;
|
|
264
|
+
selectList(wrapper?: LambdaQueryWrapper<T>): Promise<T[]>;
|
|
265
|
+
selectCount(wrapper?: LambdaQueryWrapper<T>): Promise<number>;
|
|
266
|
+
selectPage(page: number, size: number, wrapper?: LambdaQueryWrapper<T>): Promise<Page<T>>;
|
|
267
|
+
rawQuery(sql: string, params?: Record<string, any>): Promise<any>;
|
|
268
|
+
private extractColumns;
|
|
269
|
+
private getInsertableColumns;
|
|
270
|
+
private requireIdColumn;
|
|
271
|
+
private parseNamedParams;
|
|
272
|
+
/** 通过插件链路执行 SQL */
|
|
273
|
+
private executeWithPlugins;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
interface CompiledSql {
|
|
277
|
+
sql: string;
|
|
278
|
+
params: any[];
|
|
279
|
+
}
|
|
280
|
+
declare class SqlBuilder {
|
|
281
|
+
private dialect;
|
|
282
|
+
private params;
|
|
283
|
+
private paramIndex;
|
|
284
|
+
constructor(dialect: Dialect);
|
|
285
|
+
build(node: SqlNode): CompiledSql;
|
|
286
|
+
private buildSelect;
|
|
287
|
+
private buildInsert;
|
|
288
|
+
private buildUpdate;
|
|
289
|
+
private buildDelete;
|
|
290
|
+
private buildConditionGroup;
|
|
291
|
+
private buildCondition;
|
|
292
|
+
private addParam;
|
|
293
|
+
private q;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* 按 order 排序后依次执行插件的 beforeExecute,
|
|
298
|
+
* 执行 SQL,再依次执行 afterExecute,返回最终结果。
|
|
299
|
+
*/
|
|
300
|
+
declare function runPlugins(ds: DataSource, node: SqlNode, sql: string, params: any[], entityMeta: EntityMeta): Promise<any>;
|
|
301
|
+
|
|
302
|
+
export { AbstractWrapper, BaseMapper, Column, type ColumnMeta, type ColumnOptions, type CompiledSql, type Condition, type ConditionGroup, type Connection, type DataSource, type DataSourceConfig, type DeleteNode, type Dialect, type EntityMeta, Id, type IdOptions, type InsertNode, LambdaQueryWrapper, LambdaUpdateWrapper, MysqlDialect, type OrderByItem, type Page, type Plugin, type PluginContext, type PoolConfig, PostgresDialect, type SelectNode, SqlBuilder, type SqlNode, SqliteDialect, Table, type TransactionContext, Transactional, type TransactionalOptions, type UpdateNode, createDataSource, createDialect, getDefaultDataSource, runPlugins, setDefaultDataSource, withTransaction };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
interface ColumnMeta {
|
|
2
|
+
propertyName: string;
|
|
3
|
+
columnName: string;
|
|
4
|
+
isPrimary: boolean;
|
|
5
|
+
idType?: 'auto' | 'uuid' | 'snowflake' | 'input';
|
|
6
|
+
exist: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface EntityMeta {
|
|
9
|
+
tableName: string;
|
|
10
|
+
columns: ColumnMeta[];
|
|
11
|
+
idColumn: ColumnMeta | null;
|
|
12
|
+
target: Function;
|
|
13
|
+
}
|
|
14
|
+
interface Condition {
|
|
15
|
+
column: string;
|
|
16
|
+
op: '=' | '!=' | '>' | '>=' | '<' | '<=' | 'LIKE' | 'IN' | 'NOT IN' | 'BETWEEN' | 'IS NULL' | 'IS NOT NULL';
|
|
17
|
+
value?: any;
|
|
18
|
+
value2?: any;
|
|
19
|
+
}
|
|
20
|
+
interface ConditionGroup {
|
|
21
|
+
logic: 'AND' | 'OR';
|
|
22
|
+
items: (Condition | ConditionGroup)[];
|
|
23
|
+
}
|
|
24
|
+
interface OrderByItem {
|
|
25
|
+
column: string;
|
|
26
|
+
direction: 'ASC' | 'DESC';
|
|
27
|
+
}
|
|
28
|
+
interface SelectNode {
|
|
29
|
+
type: 'select';
|
|
30
|
+
table: string;
|
|
31
|
+
columns: string[];
|
|
32
|
+
where: ConditionGroup | null;
|
|
33
|
+
orderBy: OrderByItem[];
|
|
34
|
+
groupBy: string[];
|
|
35
|
+
having: ConditionGroup | null;
|
|
36
|
+
limit: {
|
|
37
|
+
offset: number;
|
|
38
|
+
count: number;
|
|
39
|
+
} | null;
|
|
40
|
+
}
|
|
41
|
+
interface InsertNode {
|
|
42
|
+
type: 'insert';
|
|
43
|
+
table: string;
|
|
44
|
+
columns: string[];
|
|
45
|
+
values: any[][];
|
|
46
|
+
}
|
|
47
|
+
interface UpdateNode {
|
|
48
|
+
type: 'update';
|
|
49
|
+
table: string;
|
|
50
|
+
sets: {
|
|
51
|
+
column: string;
|
|
52
|
+
value: any;
|
|
53
|
+
}[];
|
|
54
|
+
where: ConditionGroup | null;
|
|
55
|
+
}
|
|
56
|
+
interface DeleteNode {
|
|
57
|
+
type: 'delete';
|
|
58
|
+
table: string;
|
|
59
|
+
where: ConditionGroup | null;
|
|
60
|
+
}
|
|
61
|
+
type SqlNode = SelectNode | InsertNode | UpdateNode | DeleteNode;
|
|
62
|
+
interface Dialect {
|
|
63
|
+
placeholder(index: number): string;
|
|
64
|
+
quote(identifier: string): string;
|
|
65
|
+
paginate(sql: string, offset: number, limit: number): string;
|
|
66
|
+
insertReturningId(table: string, columns: string[], idColumn: string): string | null;
|
|
67
|
+
}
|
|
68
|
+
interface PluginContext {
|
|
69
|
+
node: SqlNode;
|
|
70
|
+
sql: string;
|
|
71
|
+
params: any[];
|
|
72
|
+
entityMeta: EntityMeta;
|
|
73
|
+
}
|
|
74
|
+
interface Plugin {
|
|
75
|
+
name: string;
|
|
76
|
+
order: number;
|
|
77
|
+
beforeExecute?(ctx: PluginContext): Promise<void> | void;
|
|
78
|
+
afterExecute?(ctx: PluginContext, result: any): Promise<any> | any;
|
|
79
|
+
}
|
|
80
|
+
interface PoolConfig {
|
|
81
|
+
min?: number;
|
|
82
|
+
max?: number;
|
|
83
|
+
idleTimeout?: number;
|
|
84
|
+
acquireTimeout?: number;
|
|
85
|
+
}
|
|
86
|
+
interface DataSourceConfig {
|
|
87
|
+
type: 'mysql' | 'postgres' | 'sqlite';
|
|
88
|
+
host?: string;
|
|
89
|
+
port?: number;
|
|
90
|
+
database: string;
|
|
91
|
+
username?: string;
|
|
92
|
+
password?: string;
|
|
93
|
+
pool?: PoolConfig;
|
|
94
|
+
plugins?: Plugin[];
|
|
95
|
+
namingStrategy?: 'camelToSnake' | ((name: string) => string);
|
|
96
|
+
}
|
|
97
|
+
interface Connection {
|
|
98
|
+
query(sql: string, params: any[]): Promise<any>;
|
|
99
|
+
release(): void;
|
|
100
|
+
}
|
|
101
|
+
interface DataSource {
|
|
102
|
+
config: DataSourceConfig;
|
|
103
|
+
dialect: Dialect;
|
|
104
|
+
plugins: Plugin[];
|
|
105
|
+
getConnection(): Promise<Connection>;
|
|
106
|
+
execute(sql: string, params: any[]): Promise<any>;
|
|
107
|
+
close(): Promise<void>;
|
|
108
|
+
transaction<T>(fn: (tx: TransactionContext) => Promise<T>): Promise<T>;
|
|
109
|
+
}
|
|
110
|
+
interface TransactionContext {
|
|
111
|
+
connection: Connection;
|
|
112
|
+
commit(): Promise<void>;
|
|
113
|
+
rollback(): Promise<void>;
|
|
114
|
+
}
|
|
115
|
+
interface Page<T> {
|
|
116
|
+
records: T[];
|
|
117
|
+
total: number;
|
|
118
|
+
page: number;
|
|
119
|
+
size: number;
|
|
120
|
+
pages: number;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
declare function Table(tableName: string): ClassDecorator;
|
|
124
|
+
interface IdOptions {
|
|
125
|
+
type?: 'auto' | 'uuid' | 'snowflake' | 'input';
|
|
126
|
+
}
|
|
127
|
+
declare function Id(options?: IdOptions): PropertyDecorator;
|
|
128
|
+
interface ColumnOptions {
|
|
129
|
+
name?: string;
|
|
130
|
+
exist?: boolean;
|
|
131
|
+
}
|
|
132
|
+
declare function Column(nameOrOptions?: string | ColumnOptions): PropertyDecorator;
|
|
133
|
+
|
|
134
|
+
declare function createDataSource(config: DataSourceConfig): DataSource;
|
|
135
|
+
|
|
136
|
+
/** 编程式事务(配合 AsyncLocalStorage 自动传播) */
|
|
137
|
+
declare function withTransaction<T>(ds: DataSource, fn: () => Promise<T>): Promise<T>;
|
|
138
|
+
declare function setDefaultDataSource(ds: DataSource): void;
|
|
139
|
+
declare function getDefaultDataSource(): DataSource;
|
|
140
|
+
interface TransactionalOptions {
|
|
141
|
+
datasource?: DataSource;
|
|
142
|
+
}
|
|
143
|
+
declare function Transactional(options?: TransactionalOptions): MethodDecorator;
|
|
144
|
+
|
|
145
|
+
declare class MysqlDialect implements Dialect {
|
|
146
|
+
placeholder(_index: number): string;
|
|
147
|
+
quote(identifier: string): string;
|
|
148
|
+
paginate(sql: string, offset: number, limit: number): string;
|
|
149
|
+
insertReturningId(): null;
|
|
150
|
+
}
|
|
151
|
+
declare class PostgresDialect implements Dialect {
|
|
152
|
+
placeholder(index: number): string;
|
|
153
|
+
quote(identifier: string): string;
|
|
154
|
+
paginate(sql: string, offset: number, limit: number): string;
|
|
155
|
+
insertReturningId(_table: string, _columns: string[], idColumn: string): string;
|
|
156
|
+
}
|
|
157
|
+
declare class SqliteDialect implements Dialect {
|
|
158
|
+
placeholder(_index: number): string;
|
|
159
|
+
quote(identifier: string): string;
|
|
160
|
+
paginate(sql: string, offset: number, limit: number): string;
|
|
161
|
+
insertReturningId(): null;
|
|
162
|
+
}
|
|
163
|
+
declare function createDialect(type: string): Dialect;
|
|
164
|
+
|
|
165
|
+
declare class AbstractWrapper<T, Self extends AbstractWrapper<T, Self>> {
|
|
166
|
+
protected entityMeta: EntityMeta;
|
|
167
|
+
protected conditionGroup: ConditionGroup;
|
|
168
|
+
protected _orderBy: OrderByItem[];
|
|
169
|
+
protected _groupBy: string[];
|
|
170
|
+
protected _having: ConditionGroup | null;
|
|
171
|
+
constructor(entityMeta: EntityMeta);
|
|
172
|
+
eq(column: keyof T & string, value: any): Self;
|
|
173
|
+
eq(condition: boolean, column: keyof T & string, value: any): Self;
|
|
174
|
+
ne(column: keyof T & string, value: any): Self;
|
|
175
|
+
ne(condition: boolean, column: keyof T & string, value: any): Self;
|
|
176
|
+
gt(column: keyof T & string, value: any): Self;
|
|
177
|
+
gt(condition: boolean, column: keyof T & string, value: any): Self;
|
|
178
|
+
ge(column: keyof T & string, value: any): Self;
|
|
179
|
+
ge(condition: boolean, column: keyof T & string, value: any): Self;
|
|
180
|
+
lt(column: keyof T & string, value: any): Self;
|
|
181
|
+
lt(condition: boolean, column: keyof T & string, value: any): Self;
|
|
182
|
+
le(column: keyof T & string, value: any): Self;
|
|
183
|
+
le(condition: boolean, column: keyof T & string, value: any): Self;
|
|
184
|
+
like(column: keyof T & string, value: string): Self;
|
|
185
|
+
like(condition: boolean, column: keyof T & string, value: string): Self;
|
|
186
|
+
likeLeft(column: keyof T & string, value: string): Self;
|
|
187
|
+
likeLeft(condition: boolean, column: keyof T & string, value: string): Self;
|
|
188
|
+
likeRight(column: keyof T & string, value: string): Self;
|
|
189
|
+
likeRight(condition: boolean, column: keyof T & string, value: string): Self;
|
|
190
|
+
between(column: keyof T & string, val1: any, val2: any): Self;
|
|
191
|
+
between(condition: boolean, column: keyof T & string, val1: any, val2: any): Self;
|
|
192
|
+
in(column: keyof T & string, values: any[]): Self;
|
|
193
|
+
in(condition: boolean, column: keyof T & string, values: any[]): Self;
|
|
194
|
+
notIn(column: keyof T & string, values: any[]): Self;
|
|
195
|
+
notIn(condition: boolean, column: keyof T & string, values: any[]): Self;
|
|
196
|
+
isNull(column: keyof T & string): Self;
|
|
197
|
+
isNull(condition: boolean, column: keyof T & string): Self;
|
|
198
|
+
isNotNull(column: keyof T & string): Self;
|
|
199
|
+
isNotNull(condition: boolean, column: keyof T & string): Self;
|
|
200
|
+
or(fn: (w: Self) => void): Self;
|
|
201
|
+
and(fn: (w: Self) => void): Self;
|
|
202
|
+
orderByAsc(...columns: (keyof T & string)[]): Self;
|
|
203
|
+
orderByDesc(...columns: (keyof T & string)[]): Self;
|
|
204
|
+
groupBy(...columns: (keyof T & string)[]): Self;
|
|
205
|
+
protected resolveColumn(propertyName: string): string;
|
|
206
|
+
getConditionGroup(): ConditionGroup;
|
|
207
|
+
getOrderBy(): OrderByItem[];
|
|
208
|
+
getGroupBy(): string[];
|
|
209
|
+
getHaving(): ConditionGroup | null;
|
|
210
|
+
private addCondition;
|
|
211
|
+
private parseArgs;
|
|
212
|
+
private createNested;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
declare class LambdaQueryWrapper<T> extends AbstractWrapper<T, LambdaQueryWrapper<T>> {
|
|
216
|
+
private _columns;
|
|
217
|
+
private _limit;
|
|
218
|
+
private _datasource;
|
|
219
|
+
constructor(entityMeta: EntityMeta);
|
|
220
|
+
/** 绑定数据源(由 BaseMapper 调用) */
|
|
221
|
+
bindDataSource(ds: DataSource): this;
|
|
222
|
+
select(...columns: (keyof T & string)[]): this;
|
|
223
|
+
page(page: number, size: number): this;
|
|
224
|
+
/** 构建 SelectNode AST */
|
|
225
|
+
buildSelectNode(): SelectNode;
|
|
226
|
+
/** 终结操作:执行查询返回列表 */
|
|
227
|
+
list(): Promise<T[]>;
|
|
228
|
+
/** 终结操作:查询单条 */
|
|
229
|
+
one(): Promise<T | null>;
|
|
230
|
+
/** 终结操作:查询数量 */
|
|
231
|
+
count(): Promise<number>;
|
|
232
|
+
/** 终结操作:分页查询 */
|
|
233
|
+
pageResult(page: number, size: number): Promise<Page<T>>;
|
|
234
|
+
private requireDs;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
declare class LambdaUpdateWrapper<T> extends AbstractWrapper<T, LambdaUpdateWrapper<T>> {
|
|
238
|
+
private _sets;
|
|
239
|
+
private _datasource;
|
|
240
|
+
constructor(entityMeta: EntityMeta);
|
|
241
|
+
bindDataSource(ds: DataSource): this;
|
|
242
|
+
set(column: keyof T & string, value: any): this;
|
|
243
|
+
set(condition: boolean, column: keyof T & string, value: any): this;
|
|
244
|
+
buildUpdateNode(): UpdateNode;
|
|
245
|
+
execute(): Promise<number>;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
declare class BaseMapper<T extends object> {
|
|
249
|
+
protected entityMeta: EntityMeta;
|
|
250
|
+
protected ds: DataSource;
|
|
251
|
+
constructor(entityClass: Function, datasource: DataSource);
|
|
252
|
+
lambdaQuery(): LambdaQueryWrapper<T>;
|
|
253
|
+
lambdaUpdate(): LambdaUpdateWrapper<T>;
|
|
254
|
+
insert(entity: Partial<T>): Promise<number>;
|
|
255
|
+
insertBatch(entities: Partial<T>[]): Promise<number>;
|
|
256
|
+
deleteById(id: any): Promise<number>;
|
|
257
|
+
deleteBatchIds(ids: any[]): Promise<number>;
|
|
258
|
+
delete(wrapper: LambdaQueryWrapper<T>): Promise<number>;
|
|
259
|
+
updateById(entity: Partial<T>): Promise<number>;
|
|
260
|
+
update(entity: Partial<T>, wrapper: LambdaQueryWrapper<T>): Promise<number>;
|
|
261
|
+
selectById(id: any): Promise<T | null>;
|
|
262
|
+
selectBatchIds(ids: any[]): Promise<T[]>;
|
|
263
|
+
selectOne(wrapper: LambdaQueryWrapper<T>): Promise<T | null>;
|
|
264
|
+
selectList(wrapper?: LambdaQueryWrapper<T>): Promise<T[]>;
|
|
265
|
+
selectCount(wrapper?: LambdaQueryWrapper<T>): Promise<number>;
|
|
266
|
+
selectPage(page: number, size: number, wrapper?: LambdaQueryWrapper<T>): Promise<Page<T>>;
|
|
267
|
+
rawQuery(sql: string, params?: Record<string, any>): Promise<any>;
|
|
268
|
+
private extractColumns;
|
|
269
|
+
private getInsertableColumns;
|
|
270
|
+
private requireIdColumn;
|
|
271
|
+
private parseNamedParams;
|
|
272
|
+
/** 通过插件链路执行 SQL */
|
|
273
|
+
private executeWithPlugins;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
interface CompiledSql {
|
|
277
|
+
sql: string;
|
|
278
|
+
params: any[];
|
|
279
|
+
}
|
|
280
|
+
declare class SqlBuilder {
|
|
281
|
+
private dialect;
|
|
282
|
+
private params;
|
|
283
|
+
private paramIndex;
|
|
284
|
+
constructor(dialect: Dialect);
|
|
285
|
+
build(node: SqlNode): CompiledSql;
|
|
286
|
+
private buildSelect;
|
|
287
|
+
private buildInsert;
|
|
288
|
+
private buildUpdate;
|
|
289
|
+
private buildDelete;
|
|
290
|
+
private buildConditionGroup;
|
|
291
|
+
private buildCondition;
|
|
292
|
+
private addParam;
|
|
293
|
+
private q;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* 按 order 排序后依次执行插件的 beforeExecute,
|
|
298
|
+
* 执行 SQL,再依次执行 afterExecute,返回最终结果。
|
|
299
|
+
*/
|
|
300
|
+
declare function runPlugins(ds: DataSource, node: SqlNode, sql: string, params: any[], entityMeta: EntityMeta): Promise<any>;
|
|
301
|
+
|
|
302
|
+
export { AbstractWrapper, BaseMapper, Column, type ColumnMeta, type ColumnOptions, type CompiledSql, type Condition, type ConditionGroup, type Connection, type DataSource, type DataSourceConfig, type DeleteNode, type Dialect, type EntityMeta, Id, type IdOptions, type InsertNode, LambdaQueryWrapper, LambdaUpdateWrapper, MysqlDialect, type OrderByItem, type Page, type Plugin, type PluginContext, type PoolConfig, PostgresDialect, type SelectNode, SqlBuilder, type SqlNode, SqliteDialect, Table, type TransactionContext, Transactional, type TransactionalOptions, type UpdateNode, createDataSource, createDialect, getDefaultDataSource, runPlugins, setDefaultDataSource, withTransaction };
|