@axiosleo/orm-mysql 0.5.4 → 0.5.6
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 +3 -3
- package/index.d.ts +25 -4
- package/package.json +1 -1
- package/src/operator.js +4 -1
package/README.md
CHANGED
|
@@ -126,7 +126,7 @@ async function deleteExample() {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
async function subqueryExample() {
|
|
129
|
-
const query =
|
|
129
|
+
const query = handler.table("users", "u");
|
|
130
130
|
const subQuery = new Query("select");
|
|
131
131
|
subQuery.table("users").having("COUNT(*)", ">", 1);
|
|
132
132
|
|
|
@@ -156,7 +156,7 @@ Hook.post(async (options, result) => {
|
|
|
156
156
|
```javascript
|
|
157
157
|
const { TransactionHandler, createPromiseClient } = require("@axiosleo/orm-mysql");
|
|
158
158
|
|
|
159
|
-
const conn = createPromiseClient({
|
|
159
|
+
const conn = await createPromiseClient({
|
|
160
160
|
host: process.env.MYSQL_HOST,
|
|
161
161
|
port: process.env.MYSQL_PORT,
|
|
162
162
|
user: process.env.MYSQL_USER,
|
|
@@ -200,4 +200,4 @@ try {
|
|
|
200
200
|
This project is open-sourced software licensed under the [MIT](LICENSE).
|
|
201
201
|
|
|
202
202
|
|
|
203
|
-
[](https://app.fossa.com/projects/git%2Bgithub.com%2FAxiosLeo%2Fnode-orm-mysql?ref=badge_large)
|
|
203
|
+
[](https://app.fossa.com/projects/git%2Bgithub.com%2FAxiosLeo%2Fnode-orm-mysql?ref=badge_large)
|
package/index.d.ts
CHANGED
|
@@ -133,23 +133,44 @@ export declare class QueryHandler {
|
|
|
133
133
|
|
|
134
134
|
constructor(conn: Connection);
|
|
135
135
|
|
|
136
|
+
/**
|
|
137
|
+
* select table
|
|
138
|
+
* @param table
|
|
139
|
+
* @param alias
|
|
140
|
+
*/
|
|
136
141
|
table(table: string, alias?: string | null): QueryOperator;
|
|
137
142
|
|
|
143
|
+
/**
|
|
144
|
+
* execute sql
|
|
145
|
+
* @param options
|
|
146
|
+
*/
|
|
138
147
|
query(options: QueryOptions): Promise<any>;
|
|
139
148
|
|
|
149
|
+
/**
|
|
150
|
+
* insert or update
|
|
151
|
+
* @param tableName
|
|
152
|
+
* @param data
|
|
153
|
+
* @param condition
|
|
154
|
+
*/
|
|
140
155
|
upsert(tableName: string, data: any, condition: Record<string, ConditionValueType>): Promise<OkPacket>;
|
|
141
156
|
}
|
|
142
157
|
|
|
143
158
|
export declare class TransactionOperator extends QueryOperator {
|
|
159
|
+
/**
|
|
160
|
+
* @example LOCK IN SHARE MODE
|
|
161
|
+
* @example FOR UPDATE
|
|
162
|
+
*/
|
|
144
163
|
append(suffix: string): this;
|
|
145
164
|
}
|
|
146
165
|
|
|
166
|
+
export type TransactionLevel = 'READ UNCOMMITTED' | 'RU'
|
|
167
|
+
| 'READ COMMITTED' | 'RC'
|
|
168
|
+
| 'REPEATABLE READ' | 'RR'
|
|
169
|
+
| 'SERIALIZABLE' | 'S';
|
|
170
|
+
|
|
147
171
|
export declare class TransactionHandler {
|
|
148
172
|
constructor(conn: PromiseConnection, options?: {
|
|
149
|
-
level:
|
|
150
|
-
| 'READ COMMITTED' | 'RC'
|
|
151
|
-
| 'REPEATABLE READ' | 'RR'
|
|
152
|
-
| 'SERIALIZABLE' | 'S'
|
|
173
|
+
level: TransactionLevel
|
|
153
174
|
});
|
|
154
175
|
|
|
155
176
|
query(options: QueryOptions): Promise<any>;
|
package/package.json
CHANGED
package/src/operator.js
CHANGED
|
@@ -26,7 +26,7 @@ class QueryOperator extends Query {
|
|
|
26
26
|
/**
|
|
27
27
|
* @param {*} conn
|
|
28
28
|
*/
|
|
29
|
-
constructor(conn) {
|
|
29
|
+
constructor(conn = null) {
|
|
30
30
|
super(null);
|
|
31
31
|
this.conn = conn;
|
|
32
32
|
}
|
|
@@ -40,6 +40,9 @@ class QueryOperator extends Query {
|
|
|
40
40
|
if (!this.options.operator) {
|
|
41
41
|
throw new Error('Invalid operator: ' + this.options.operator);
|
|
42
42
|
}
|
|
43
|
+
if (this.conn === null) {
|
|
44
|
+
throw new Error('Connection is null');
|
|
45
|
+
}
|
|
43
46
|
const builder = this.buildSql(this.options.operator);
|
|
44
47
|
const { sql, values } = builder;
|
|
45
48
|
const options = {
|