@asla/yoursql 0.9.0 → 0.9.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/DbQuery.js
CHANGED
|
@@ -5,27 +5,27 @@
|
|
|
5
5
|
class DbQuery {
|
|
6
6
|
/** 单语句查询受影响的行 */
|
|
7
7
|
queryCount(sql) {
|
|
8
|
-
return this.query(sql
|
|
8
|
+
return this.query(sql).then((res) => {
|
|
9
9
|
if (res.rowCount === null)
|
|
10
10
|
return 0;
|
|
11
11
|
return res.rowCount;
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
queryRows(sql) {
|
|
15
|
-
return this.query(sql
|
|
15
|
+
return this.query(sql).then((res) => res.rows);
|
|
16
16
|
}
|
|
17
17
|
queryFirstRow(sql) {
|
|
18
|
-
return this.query(sql
|
|
18
|
+
return this.query(sql).then(({ rows, rowCount }) => {
|
|
19
19
|
if (rows.length === 0)
|
|
20
20
|
throw new Error("Query did not return any rows");
|
|
21
21
|
return rows[0];
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
multipleQueryRows(sql) {
|
|
25
|
-
return this.multipleQuery(sql
|
|
25
|
+
return this.multipleQuery(sql).then((res) => res.map((item) => item.rows ?? []));
|
|
26
26
|
}
|
|
27
27
|
async queryMap(sql, key) {
|
|
28
|
-
const { rows } = await this.query(sql
|
|
28
|
+
const { rows } = await this.query(sql);
|
|
29
29
|
let map = new Map();
|
|
30
30
|
for (let i = 0; i < rows.length; i++) {
|
|
31
31
|
map.set(rows[i][key], rows[i]);
|
|
@@ -18,7 +18,7 @@ class SqlChainModify extends SqlStatement {
|
|
|
18
18
|
else {
|
|
19
19
|
columnsStr = selectColumns(returns);
|
|
20
20
|
}
|
|
21
|
-
let sql = this.
|
|
21
|
+
let sql = this.genSql() + "\nRETURNING " + columnsStr;
|
|
22
22
|
return new SqlTextStatementDataset(sql);
|
|
23
23
|
}
|
|
24
24
|
onConflict(onConflict) {
|
|
@@ -26,12 +26,12 @@ class SqlChainModify extends SqlStatement {
|
|
|
26
26
|
onConflict = onConflict();
|
|
27
27
|
if (typeof onConflict !== "string")
|
|
28
28
|
onConflict = onConflict.join(",");
|
|
29
|
-
let sql = this.
|
|
29
|
+
let sql = this.genSql() + `\nON CONFLICT (${onConflict})`;
|
|
30
30
|
return new SqlInsertConflictBranch(sql);
|
|
31
31
|
}
|
|
32
32
|
where(where$1) {
|
|
33
33
|
const sql = where(where$1);
|
|
34
|
-
return new SqlChainModify(this.
|
|
34
|
+
return new SqlChainModify(this.genSql() + sql);
|
|
35
35
|
}
|
|
36
36
|
genSql() {
|
|
37
37
|
return this.sql;
|
|
@@ -8,10 +8,10 @@ var _a;
|
|
|
8
8
|
*/
|
|
9
9
|
class SqlSelectChain extends SqlTextStatementDataset {
|
|
10
10
|
where(param) {
|
|
11
|
-
return new SqlSelectChain(this.
|
|
11
|
+
return new SqlSelectChain(this.genSql() + where(param));
|
|
12
12
|
}
|
|
13
13
|
groupBy(columns) {
|
|
14
|
-
let sql = this.
|
|
14
|
+
let sql = this.genSql();
|
|
15
15
|
if (typeof columns === "string")
|
|
16
16
|
sql += " GROUP BY " + columns;
|
|
17
17
|
else
|
|
@@ -19,13 +19,13 @@ class SqlSelectChain extends SqlTextStatementDataset {
|
|
|
19
19
|
return new SqlSelectChain(sql);
|
|
20
20
|
}
|
|
21
21
|
having(param) {
|
|
22
|
-
return new SqlSelectChain(this.
|
|
22
|
+
return new SqlSelectChain(this.genSql() + having(param));
|
|
23
23
|
}
|
|
24
24
|
orderBy(param) {
|
|
25
|
-
return new SqlSelectChain(this.
|
|
25
|
+
return new SqlSelectChain(this.genSql() + orderBy(param));
|
|
26
26
|
}
|
|
27
27
|
limit(limit, offset) {
|
|
28
|
-
let sql = this.
|
|
28
|
+
let sql = this.genSql();
|
|
29
29
|
let type;
|
|
30
30
|
if (limit) {
|
|
31
31
|
type = typeof limit;
|