@asla/yoursql 0.11.4 → 0.12.1
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/client/DbCursor.d.ts +1 -1
- package/dist/client/DbPoolConnection.d.ts +4 -27
- package/dist/client/DbPoolConnection.js +9 -11
- package/dist/client/DbPoolTransaction.d.ts +3 -25
- package/dist/client/DbPoolTransaction.js +6 -6
- package/dist/client/DbQuery.d.ts +4 -1
- package/dist/client/DbQueryPool.d.ts +1 -2
- package/dist/client/interfaces.d.ts +20 -1
- package/dist/client/mod.js +2 -2
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ export interface DbCursorOption {
|
|
|
3
3
|
defaultSize?: number;
|
|
4
4
|
}
|
|
5
5
|
/** @public */
|
|
6
|
-
export declare abstract class DbCursor<T> {
|
|
6
|
+
export declare abstract class DbCursor<T> implements AsyncDisposable, AsyncIterable<T> {
|
|
7
7
|
/** 读取游标,如果读取结束,返回空数组 */
|
|
8
8
|
abstract read(maxSize?: number): Promise<T[]>;
|
|
9
9
|
/** 提前关闭游标,如果多次调用,会被忽略 */
|
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 池连接
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
|
-
export declare class DbPoolConnection extends DbQuery {
|
|
11
|
-
#private;
|
|
12
|
-
constructor(conn: DbQueryBase, onRelease: (conn: DbQueryBase) => void, onDispose?: (conn: DbQueryBase) => void);
|
|
13
|
-
begin(mode?: TransactionMode): Promise<void>;
|
|
14
|
-
query<T extends MultipleQueryResult = MultipleQueryResult>(sql: MultipleQueryInput): Promise<T>;
|
|
15
|
-
query<T = any>(sql: QueryDataInput<T>): Promise<QueryRowsResult<T>>;
|
|
16
|
-
query<T = any>(sql: QueryInput): Promise<QueryRowsResult<T>>;
|
|
17
|
-
execute(sql: QueryInput | MultipleQueryInput): Promise<void>;
|
|
18
|
-
/** @deprecated 不建议使用 */
|
|
19
|
-
multipleQuery<T extends MultipleQueryResult = MultipleQueryResult>(sql: SqlLike | SqlLike[]): Promise<T>;
|
|
20
|
-
rollback(): Promise<void>;
|
|
21
|
-
commit(): Promise<void>;
|
|
22
|
-
get released(): boolean;
|
|
23
|
-
/** 调用 release() 时,如果事务未提交,则抛出异常 */
|
|
24
|
-
release(): void;
|
|
25
|
-
dispose(): void;
|
|
26
|
-
[Symbol.dispose](): void;
|
|
27
|
-
}
|
|
1
|
+
import { type DbQueryBase } from "./DbQueryBase.ts";
|
|
2
|
+
import type { DbPoolConnection } from "./interfaces.ts";
|
|
3
|
+
/** @public */
|
|
4
|
+
export declare function createDbPoolConnection(conn: DbQueryBase, onRelease: (conn: DbQueryBase) => void, onDispose?: (conn: DbQueryBase) => void): DbPoolConnection;
|
|
28
5
|
//# sourceMappingURL=DbPoolConnection.d.ts.map
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { DbQuery } from './DbQuery.js';
|
|
2
2
|
import { ConnectionNotAvailableError } from './errors.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 池连接
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
|
-
class DbPoolConnection extends DbQuery {
|
|
4
|
+
class DbPoolConnectionImpl extends DbQuery {
|
|
11
5
|
constructor(conn, onRelease, onDispose = onRelease) {
|
|
12
6
|
super();
|
|
13
7
|
this.#conn = conn;
|
|
@@ -18,7 +12,7 @@ class DbPoolConnection extends DbQuery {
|
|
|
18
12
|
#onDispose;
|
|
19
13
|
//implement
|
|
20
14
|
async begin(mode) {
|
|
21
|
-
await this.
|
|
15
|
+
await this.execute("BEGIN" + (mode ? " TRANSACTION ISOLATION LEVEL " + mode : ""));
|
|
22
16
|
}
|
|
23
17
|
#conn;
|
|
24
18
|
query(sql) {
|
|
@@ -43,11 +37,11 @@ class DbPoolConnection extends DbQuery {
|
|
|
43
37
|
}
|
|
44
38
|
//implement
|
|
45
39
|
async rollback() {
|
|
46
|
-
await this.
|
|
40
|
+
await this.execute("ROLLBACK");
|
|
47
41
|
}
|
|
48
42
|
//implement
|
|
49
43
|
async commit() {
|
|
50
|
-
await this.
|
|
44
|
+
await this.execute("COMMIT");
|
|
51
45
|
}
|
|
52
46
|
get released() {
|
|
53
47
|
return !this.#conn;
|
|
@@ -72,5 +66,9 @@ class DbPoolConnection extends DbQuery {
|
|
|
72
66
|
return this.release();
|
|
73
67
|
}
|
|
74
68
|
}
|
|
69
|
+
/** @public */
|
|
70
|
+
function createDbPoolConnection(conn, onRelease, onDispose = onRelease) {
|
|
71
|
+
return new DbPoolConnectionImpl(conn, onRelease, onDispose);
|
|
72
|
+
}
|
|
75
73
|
|
|
76
|
-
export {
|
|
74
|
+
export { createDbPoolConnection };
|
|
@@ -1,31 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { MultipleQueryResult, QueryRowsResult } from "./DbQueryBase.ts";
|
|
3
|
-
import type { DbPoolConnection } from "./DbPoolConnection.ts";
|
|
4
|
-
import type { DbTransaction, SqlLike, TransactionMode } from "./interfaces.ts";
|
|
1
|
+
import type { DbPoolConnection, DbPoolTransaction, TransactionMode } from "./interfaces.ts";
|
|
5
2
|
/** @public */
|
|
6
3
|
export type DbPoolTransactionOption = {
|
|
7
4
|
errorRollback?: boolean;
|
|
8
5
|
mode?: TransactionMode;
|
|
9
6
|
};
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
* 池连接事务
|
|
13
|
-
*/
|
|
14
|
-
export declare class DbPoolTransaction extends DbQuery implements DbTransaction {
|
|
15
|
-
#private;
|
|
16
|
-
readonly mode?: TransactionMode;
|
|
17
|
-
constructor(connect: () => Promise<DbPoolConnection>, option?: TransactionMode | DbPoolTransactionOption);
|
|
18
|
-
commit(): Promise<void>;
|
|
19
|
-
rollback(): Promise<void>;
|
|
20
|
-
savePoint(savePoint: string): Promise<void>;
|
|
21
|
-
rollbackTo(savePoint: string): Promise<void>;
|
|
22
|
-
query<T extends MultipleQueryResult = MultipleQueryResult>(sql: MultipleQueryInput): Promise<T>;
|
|
23
|
-
query<T extends object = any>(sql: QueryDataInput<T>): Promise<QueryRowsResult<T>>;
|
|
24
|
-
query<T extends object = any>(sql: QueryInput): Promise<QueryRowsResult<T>>;
|
|
25
|
-
execute(sql: QueryInput | MultipleQueryInput): Promise<void>;
|
|
26
|
-
/** @deprecated 不建议使用 */
|
|
27
|
-
multipleQuery<T extends MultipleQueryResult = MultipleQueryResult>(sql: SqlLike | SqlLike[]): Promise<T>;
|
|
28
|
-
get released(): boolean;
|
|
29
|
-
[Symbol.asyncDispose](): Promise<void>;
|
|
30
|
-
}
|
|
7
|
+
/** @public */
|
|
8
|
+
export declare function createDbPoolTransaction(connect: () => Promise<DbPoolConnection>, option?: TransactionMode | DbPoolTransactionOption): DbPoolTransaction;
|
|
31
9
|
//# sourceMappingURL=DbPoolTransaction.d.ts.map
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { DbQuery } from './DbQuery.js';
|
|
2
2
|
import { ParallelQueryError, ConnectionNotAvailableError } from './errors.js';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
* @public
|
|
6
|
-
* 池连接事务
|
|
7
|
-
*/
|
|
8
|
-
class DbPoolTransaction extends DbQuery {
|
|
4
|
+
class DbPoolTransactionImpl extends DbQuery {
|
|
9
5
|
#errorRollback;
|
|
10
6
|
mode;
|
|
11
7
|
#begin;
|
|
@@ -142,5 +138,9 @@ class DbPoolTransaction extends DbQuery {
|
|
|
142
138
|
return this.rollback();
|
|
143
139
|
}
|
|
144
140
|
}
|
|
141
|
+
/** @public */
|
|
142
|
+
function createDbPoolTransaction(connect, option) {
|
|
143
|
+
return new DbPoolTransactionImpl(connect, option);
|
|
144
|
+
}
|
|
145
145
|
|
|
146
|
-
export {
|
|
146
|
+
export { createDbPoolTransaction };
|
package/dist/client/DbQuery.d.ts
CHANGED
|
@@ -16,7 +16,10 @@ export declare abstract class DbQuery {
|
|
|
16
16
|
abstract query<T extends MultipleQueryResult = MultipleQueryResult>(sql: MultipleQueryInput): Promise<T>;
|
|
17
17
|
abstract query<T = any>(sql: QueryDataInput<T>): Promise<QueryRowsResult<T>>;
|
|
18
18
|
abstract query<T = any>(sql: QueryInput): Promise<QueryRowsResult<T>>;
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* 执行多语句的方法
|
|
21
|
+
* @deprecated 不建议使用。改用 query()
|
|
22
|
+
*/
|
|
20
23
|
abstract multipleQuery<T extends MultipleQueryResult = MultipleQueryResult>(sql: SqlLike | SqlLike[]): Promise<T>;
|
|
21
24
|
/** 单语句查询受影响的行 */
|
|
22
25
|
queryCount(sql: QueryInput): Promise<number>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DbCursor, DbCursorOption } from "./DbCursor.ts";
|
|
2
|
-
import { DbPoolConnection } from "./DbPoolConnection.ts";
|
|
3
2
|
import { DbQuery } from "./DbQuery.ts";
|
|
4
|
-
import { DbPool, DbTransaction, SqlLike, TransactionMode } from "./interfaces.ts";
|
|
3
|
+
import { DbPool, DbPoolConnection, DbTransaction, SqlLike, TransactionMode } from "./interfaces.ts";
|
|
5
4
|
import { QueryRowsResult } from "./DbQueryBase.ts";
|
|
6
5
|
import { SqlStatementDataset, InferQueryResult } from "./_type.ts";
|
|
7
6
|
/** @public */
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { DbQuery } from "./DbQuery.ts";
|
|
2
|
-
import { DbPoolConnection } from "./DbPoolConnection.ts";
|
|
3
2
|
import { DbCursor, DbCursorOption } from "./DbCursor.ts";
|
|
4
3
|
import { SqlStatementDataset, SqlTemplate } from "./_type.ts";
|
|
5
4
|
/**
|
|
@@ -9,6 +8,18 @@ import { SqlStatementDataset, SqlTemplate } from "./_type.ts";
|
|
|
9
8
|
export interface DbConnection extends DbQuery, AsyncDisposable {
|
|
10
9
|
close(): Promise<void>;
|
|
11
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* 数据库池连接
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export interface DbPoolConnection extends DbQuery, Disposable {
|
|
16
|
+
release(): void;
|
|
17
|
+
dispose(): void;
|
|
18
|
+
begin(mode?: TransactionMode): Promise<void>;
|
|
19
|
+
commit(): Promise<void>;
|
|
20
|
+
rollback(): Promise<void>;
|
|
21
|
+
get released(): boolean;
|
|
22
|
+
}
|
|
12
23
|
/** @public */
|
|
13
24
|
export type TransactionMode = "SERIALIZABLE" | "REPEATABLE READ" | "READ COMMITTED" | "READ UNCOMMITTED";
|
|
14
25
|
/**
|
|
@@ -49,6 +60,14 @@ export interface DbTransaction extends DbQuery, AsyncDisposable {
|
|
|
49
60
|
/** 提交,并释放连接 */
|
|
50
61
|
commit(): Promise<void>;
|
|
51
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* @public
|
|
65
|
+
* 池连接事务
|
|
66
|
+
*/
|
|
67
|
+
export interface DbPoolTransaction extends DbTransaction {
|
|
68
|
+
readonly mode?: TransactionMode;
|
|
69
|
+
get released(): boolean;
|
|
70
|
+
}
|
|
52
71
|
/**
|
|
53
72
|
* 数据库连接池
|
|
54
73
|
* @public
|
package/dist/client/mod.js
CHANGED
|
@@ -2,6 +2,6 @@ export { ConnectionNotAvailableError, ParallelQueryError } from './errors.js';
|
|
|
2
2
|
export { isSqlTemplate, sqlLikeToString } from './DbQueryBase.js';
|
|
3
3
|
export { DbQuery } from './DbQuery.js';
|
|
4
4
|
export { DbCursor } from './DbCursor.js';
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
5
|
+
export { createDbPoolConnection } from './DbPoolConnection.js';
|
|
6
|
+
export { createDbPoolTransaction } from './DbPoolTransaction.js';
|
|
7
7
|
export { DbQueryPool } from './DbQueryPool.js';
|