@asla/yoursql 0.4.0 → 0.5.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/mod.js +154 -91
- package/dist/select/TableQuery.d.ts +21 -6
- package/dist/select/select.d.ts +31 -32
- package/dist/util.d.ts +44 -13
- package/package.json +1 -1
package/dist/mod.js
CHANGED
|
@@ -34,6 +34,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
+
* 获取对象数组中的 key 的集合
|
|
37
38
|
* @public
|
|
38
39
|
* @param keepUndefinedKey - 是否保留值为 undefined 的 key
|
|
39
40
|
*/
|
|
@@ -52,24 +53,59 @@ function getObjectListKeys(objectList, keepUndefinedKey) {
|
|
|
52
53
|
keys.add(k);
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
|
-
return
|
|
56
|
+
return keys;
|
|
56
57
|
}
|
|
57
|
-
/**
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
/**
|
|
59
|
+
* 生成 WHERE 语句
|
|
60
|
+
* @public
|
|
61
|
+
* ```ts
|
|
62
|
+
*
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
function where(conditions, type) {
|
|
66
|
+
const sql = condition(conditions, type);
|
|
67
|
+
if (sql)
|
|
68
|
+
return "\nWHERE " + sql;
|
|
69
|
+
return "";
|
|
60
70
|
}
|
|
61
|
-
/**
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
/**
|
|
72
|
+
*
|
|
73
|
+
* 生成 HAVING 语句
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
function having(conditions, type) {
|
|
77
|
+
const sql = condition(conditions, type);
|
|
78
|
+
if (sql)
|
|
79
|
+
return "\nHAVING " + sql;
|
|
80
|
+
return "";
|
|
81
|
+
}
|
|
82
|
+
function condition(conditions, type = "AND") {
|
|
83
|
+
if (typeof conditions === "function")
|
|
84
|
+
conditions = conditions();
|
|
85
|
+
if (!conditions)
|
|
86
|
+
return;
|
|
87
|
+
if (typeof conditions === "string")
|
|
88
|
+
return conditions;
|
|
89
|
+
else {
|
|
90
|
+
if (conditions.length) {
|
|
91
|
+
let sql = "";
|
|
92
|
+
type = " " + type + " ";
|
|
93
|
+
sql += conditions[0];
|
|
94
|
+
for (let i = 1; i < conditions.length; i++)
|
|
95
|
+
sql += type + conditions[i];
|
|
96
|
+
return sql;
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
64
100
|
}
|
|
65
101
|
/**
|
|
66
102
|
* @public
|
|
67
103
|
* ```ts
|
|
68
|
-
*
|
|
69
|
-
*
|
|
104
|
+
* selectColumns({c1: true, c2: "count(*)", c3: "column"}) // "c1,count(*) AS c2,column as c3"
|
|
105
|
+
* selectColumns(["c1", "count(*) AS c2", "column as c3"]) // "c1,count(*) AS c2,column as c3"
|
|
70
106
|
* ```
|
|
71
107
|
*/
|
|
72
|
-
function
|
|
108
|
+
function selectColumns(columns) {
|
|
73
109
|
let sql = "";
|
|
74
110
|
if (columns instanceof Array) {
|
|
75
111
|
if (columns.length)
|
|
@@ -101,41 +137,65 @@ function genSelect(columns) {
|
|
|
101
137
|
}
|
|
102
138
|
return sql;
|
|
103
139
|
}
|
|
104
|
-
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
140
|
+
/**
|
|
141
|
+
* 生成 ORDER BY 语句, d
|
|
142
|
+
* @public
|
|
143
|
+
* ```ts
|
|
144
|
+
* // 以下生成 "\nORDER BY age DESC NULLS FIRST,num ASC"
|
|
145
|
+
* orderBy("age DESC NULLS FIRST,num ASC");
|
|
146
|
+
* orderBy(["age DESC NULLS FIRST", "num ASC"]);
|
|
147
|
+
* orderBy([
|
|
148
|
+
* { key: "age", asc: false, nullLast: false },
|
|
149
|
+
* { key: "num", asc: true },
|
|
150
|
+
* ]);
|
|
151
|
+
* orderBy({ age: "DESC NULLS FIRST", num: true });
|
|
152
|
+
*
|
|
153
|
+
* orderBy([]) // ""
|
|
154
|
+
* orderBy({}) // ""
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
function orderBy(by) {
|
|
158
|
+
if (typeof by === "function")
|
|
159
|
+
by = by();
|
|
108
160
|
let sql = "";
|
|
109
|
-
if (
|
|
110
|
-
sql
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
161
|
+
if (!by)
|
|
162
|
+
return sql;
|
|
163
|
+
if (typeof by === "string") {
|
|
164
|
+
sql += "\nORDER BY " + by;
|
|
165
|
+
}
|
|
166
|
+
else if (by instanceof Array) {
|
|
167
|
+
if (by.length) {
|
|
168
|
+
sql += "\nORDER BY " + handlerOrderValue(by[0]);
|
|
169
|
+
for (let i = 1; i < by.length; i++)
|
|
170
|
+
sql += "," + handlerOrderValue(by[i]);
|
|
171
|
+
}
|
|
114
172
|
}
|
|
115
173
|
else {
|
|
116
|
-
let keys = Object.keys(
|
|
117
|
-
if (keys.length)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
174
|
+
let keys = Object.keys(by);
|
|
175
|
+
if (keys.length) {
|
|
176
|
+
let key = keys[0];
|
|
177
|
+
sql += "\nORDER BY " + key + " " + by[key];
|
|
178
|
+
for (let i = 1; i < keys.length; i++) {
|
|
179
|
+
key = keys[i];
|
|
180
|
+
sql += "," + key + " ";
|
|
181
|
+
if (typeof by[key] === "string")
|
|
182
|
+
sql += by[key];
|
|
183
|
+
else
|
|
184
|
+
sql += by[key] ? "ASC" : "DESC";
|
|
185
|
+
}
|
|
121
186
|
}
|
|
122
187
|
}
|
|
123
188
|
return sql;
|
|
124
189
|
}
|
|
125
|
-
function
|
|
126
|
-
if (typeof
|
|
127
|
-
|
|
128
|
-
type = " " + type + " ";
|
|
129
|
-
let sql = "";
|
|
130
|
-
if (typeof where === "string")
|
|
131
|
-
sql += "\n" + statement + " " + where;
|
|
190
|
+
function handlerOrderValue(value) {
|
|
191
|
+
if (typeof value === "string")
|
|
192
|
+
return value;
|
|
132
193
|
else {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
194
|
+
let str = value.key + " " + (value.asc ? "ASC" : "DESC");
|
|
195
|
+
if (value.nullLast !== undefined)
|
|
196
|
+
str += value.nullLast ? " NULLS LAST" : " NULLS FIRST";
|
|
197
|
+
return str;
|
|
137
198
|
}
|
|
138
|
-
return sql;
|
|
139
199
|
}
|
|
140
200
|
|
|
141
201
|
var _SqlQueryStatement_sql;
|
|
@@ -319,7 +379,7 @@ class SqlValuesCreator {
|
|
|
319
379
|
throw new Error("objectList 不能是空数组");
|
|
320
380
|
let keys;
|
|
321
381
|
if (!keys_types) {
|
|
322
|
-
keys = getObjectListKeys(objectList, keepUndefinedKey);
|
|
382
|
+
keys = Array.from(getObjectListKeys(objectList, keepUndefinedKey));
|
|
323
383
|
}
|
|
324
384
|
else if (keys_types instanceof Array) {
|
|
325
385
|
keys = keys_types;
|
|
@@ -484,61 +544,76 @@ const pgSqlTransformer = new Map([
|
|
|
484
544
|
[Date, (value) => SqlValuesCreator.string(value.toISOString())],
|
|
485
545
|
]);
|
|
486
546
|
|
|
487
|
-
var
|
|
488
|
-
class
|
|
489
|
-
constructor(
|
|
490
|
-
super(
|
|
547
|
+
var _Selection_instances, _a, _Selection_sql, _Selection_join;
|
|
548
|
+
class AfterSelectImpl extends SqlQueryStatement {
|
|
549
|
+
constructor(sql, columns) {
|
|
550
|
+
super(sql, columns);
|
|
551
|
+
}
|
|
552
|
+
where(param) {
|
|
553
|
+
return new AfterSelectImpl(this.toString() + where(param), this.columns);
|
|
554
|
+
}
|
|
555
|
+
groupBy(columns) {
|
|
556
|
+
let sql = this.toString();
|
|
557
|
+
if (typeof columns === "string")
|
|
558
|
+
sql += " GROUP BY " + columns;
|
|
559
|
+
else
|
|
560
|
+
sql += " GROUP BY " + columns.join(",");
|
|
561
|
+
return new AfterSelectImpl(sql, this.columns);
|
|
491
562
|
}
|
|
492
|
-
|
|
493
|
-
|
|
563
|
+
having(param) {
|
|
564
|
+
return new AfterSelectImpl(this.toString() + having(param), this.columns);
|
|
565
|
+
}
|
|
566
|
+
orderBy(param) {
|
|
567
|
+
return new AfterSelectImpl(this.toString() + orderBy(param), this.columns);
|
|
568
|
+
}
|
|
569
|
+
limit(limit, offset) {
|
|
494
570
|
let sql = this.toString();
|
|
495
|
-
if (
|
|
496
|
-
sql +=
|
|
497
|
-
if (
|
|
498
|
-
sql += "\
|
|
499
|
-
if (option.offset)
|
|
500
|
-
sql += "\nOFFSET " + option.offset;
|
|
571
|
+
if (limit)
|
|
572
|
+
sql += "\nLIMIT " + limit;
|
|
573
|
+
if (offset)
|
|
574
|
+
sql += "\nOFFSET " + offset;
|
|
501
575
|
return new SqlQueryStatement(sql, Array.from(this.columns));
|
|
502
576
|
}
|
|
503
577
|
}
|
|
504
|
-
/** @public */
|
|
505
|
-
function createSelect(selectable, as) {
|
|
506
|
-
return new SelectImpl("FROM " + fromAs(selectable, as));
|
|
507
|
-
}
|
|
508
578
|
function fromAs(selectable, as) {
|
|
509
579
|
let sql = typeof selectable === "string" ? selectable : selectable.toSelect();
|
|
510
580
|
if (as)
|
|
511
581
|
sql += " AS " + as;
|
|
512
582
|
return sql;
|
|
513
583
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
this
|
|
584
|
+
/** @public */
|
|
585
|
+
class Selection {
|
|
586
|
+
static from(selectable, as) {
|
|
587
|
+
return new this(selectable, as);
|
|
588
|
+
}
|
|
589
|
+
constructor(selectable, as) {
|
|
590
|
+
_Selection_instances.add(this);
|
|
591
|
+
_Selection_sql.set(this, void 0);
|
|
592
|
+
__classPrivateFieldSet(this, _Selection_sql, fromAs(selectable, as), "f");
|
|
518
593
|
}
|
|
519
594
|
toString() {
|
|
520
|
-
return this
|
|
595
|
+
return "FROM " + __classPrivateFieldGet(this, _Selection_sql, "f");
|
|
521
596
|
}
|
|
522
597
|
fullJoin(selectable, as, on) {
|
|
523
|
-
return __classPrivateFieldGet(this,
|
|
598
|
+
return __classPrivateFieldGet(this, _Selection_instances, "m", _Selection_join).call(this, "FULL JOIN", selectable, as, on);
|
|
524
599
|
}
|
|
525
600
|
innerJoin(selectable, as, on) {
|
|
526
|
-
return __classPrivateFieldGet(this,
|
|
601
|
+
return __classPrivateFieldGet(this, _Selection_instances, "m", _Selection_join).call(this, "INNER JOIN", selectable, as, on);
|
|
527
602
|
}
|
|
528
603
|
leftJoin(selectable, as, on) {
|
|
529
|
-
return __classPrivateFieldGet(this,
|
|
604
|
+
return __classPrivateFieldGet(this, _Selection_instances, "m", _Selection_join).call(this, "LEFT JOIN", selectable, as, on);
|
|
530
605
|
}
|
|
531
606
|
rightJoin(selectable, as, on) {
|
|
532
|
-
return __classPrivateFieldGet(this,
|
|
607
|
+
return __classPrivateFieldGet(this, _Selection_instances, "m", _Selection_join).call(this, "RIGHT JOIN", selectable, as, on);
|
|
533
608
|
}
|
|
534
609
|
naturalJoin(selectable, as) {
|
|
535
|
-
return __classPrivateFieldGet(this,
|
|
610
|
+
return __classPrivateFieldGet(this, _Selection_instances, "m", _Selection_join).call(this, "NATURAL JOIN", selectable, as);
|
|
536
611
|
}
|
|
537
612
|
crossJoin(selectable, as) {
|
|
538
|
-
return __classPrivateFieldGet(this,
|
|
613
|
+
return __classPrivateFieldGet(this, _Selection_instances, "m", _Selection_join).call(this, "CROSS JOIN", selectable, as);
|
|
539
614
|
}
|
|
540
615
|
from(selectable, as) {
|
|
541
|
-
return new _a(this
|
|
616
|
+
return new _a(__classPrivateFieldGet(this, _Selection_sql, "f") + "," + fromAs(selectable, as));
|
|
542
617
|
}
|
|
543
618
|
select(columnsIn) {
|
|
544
619
|
let sql = "SELECT ";
|
|
@@ -546,31 +621,17 @@ class SelectImpl {
|
|
|
546
621
|
if (typeof columnsIn === "string")
|
|
547
622
|
sql += columnsIn;
|
|
548
623
|
else {
|
|
549
|
-
sql +=
|
|
624
|
+
sql += selectColumns(columnsIn);
|
|
550
625
|
if (columnsIn instanceof Array) ;
|
|
551
626
|
else
|
|
552
627
|
columns = Object.keys(columnsIn);
|
|
553
628
|
}
|
|
554
|
-
sql += "\n" + this.
|
|
555
|
-
return new
|
|
556
|
-
}
|
|
557
|
-
groupBy(columns) {
|
|
558
|
-
let sql = this.str;
|
|
559
|
-
if (typeof columns === "string")
|
|
560
|
-
sql += " GROUP BY " + columns;
|
|
561
|
-
else
|
|
562
|
-
sql += " GROUP BY " + columns.join(",");
|
|
563
|
-
return new _a(sql);
|
|
564
|
-
}
|
|
565
|
-
having(param) {
|
|
566
|
-
return new _a(this.str + genWhere(param));
|
|
567
|
-
}
|
|
568
|
-
where(param) {
|
|
569
|
-
return new _a(this.str + genWhere(param));
|
|
629
|
+
sql += "\n" + this.toString();
|
|
630
|
+
return new AfterSelectImpl(sql, columns);
|
|
570
631
|
}
|
|
571
632
|
}
|
|
572
|
-
_a =
|
|
573
|
-
let sql = this
|
|
633
|
+
_a = Selection, _Selection_sql = new WeakMap(), _Selection_instances = new WeakSet(), _Selection_join = function _Selection_join(type, selectable, as, on) {
|
|
634
|
+
let sql = __classPrivateFieldGet(this, _Selection_sql, "f") + "\n" + type + " " + fromAs(selectable, as);
|
|
574
635
|
if (on)
|
|
575
636
|
sql += " ON " + on;
|
|
576
637
|
return new _a(sql);
|
|
@@ -611,7 +672,10 @@ class DbTableQuery extends DbTable {
|
|
|
611
672
|
this.statement = statement;
|
|
612
673
|
}
|
|
613
674
|
fromAs(as) {
|
|
614
|
-
return
|
|
675
|
+
return new Selection(this, as);
|
|
676
|
+
}
|
|
677
|
+
select(columns, as) {
|
|
678
|
+
return this.fromAs(as).select(columns);
|
|
615
679
|
}
|
|
616
680
|
insert(values, option) {
|
|
617
681
|
let insertCol;
|
|
@@ -619,7 +683,7 @@ class DbTableQuery extends DbTable {
|
|
|
619
683
|
if (values instanceof Array) {
|
|
620
684
|
if (values.length === 0)
|
|
621
685
|
throw new Error("值不能为空");
|
|
622
|
-
insertCol = getObjectListKeys(values);
|
|
686
|
+
insertCol = Array.from(getObjectListKeys(values));
|
|
623
687
|
valuesStr = `VALUES\n${this.statement.objectListToValuesList(values, insertCol)}`;
|
|
624
688
|
}
|
|
625
689
|
else if (values instanceof SqlQueryStatement) {
|
|
@@ -653,7 +717,6 @@ class DbTableQuery extends DbTable {
|
|
|
653
717
|
return genRetuningSql(sql, returns, values instanceof SqlQueryStatement ? values.columns : this.columns);
|
|
654
718
|
}
|
|
655
719
|
update(values, option = {}) {
|
|
656
|
-
const { where } = option;
|
|
657
720
|
const updateKey = Object.entries(values);
|
|
658
721
|
if (updateKey.length === 0)
|
|
659
722
|
throw new Error("值不能为空");
|
|
@@ -664,8 +727,8 @@ class DbTableQuery extends DbTable {
|
|
|
664
727
|
setList.push(k + " = " + this.statement.toSqlStr(v));
|
|
665
728
|
}
|
|
666
729
|
let sql = `UPDATE ${this.name}\nSET ${setList.join(",\n")}`;
|
|
667
|
-
if (where)
|
|
668
|
-
sql +=
|
|
730
|
+
if (option.where)
|
|
731
|
+
sql += where(option.where);
|
|
669
732
|
return sql;
|
|
670
733
|
}
|
|
671
734
|
updateWithResult(values, returns, option) {
|
|
@@ -675,7 +738,7 @@ class DbTableQuery extends DbTable {
|
|
|
675
738
|
delete(option = {}) {
|
|
676
739
|
let sql = "DELETE FROM " + this.name;
|
|
677
740
|
if (option.where)
|
|
678
|
-
sql +=
|
|
741
|
+
sql += where(option.where);
|
|
679
742
|
return sql;
|
|
680
743
|
}
|
|
681
744
|
deleteWithResult(returns = "*", option) {
|
|
@@ -870,4 +933,4 @@ class YourTable extends DbTableQuery {
|
|
|
870
933
|
}
|
|
871
934
|
}
|
|
872
935
|
|
|
873
|
-
export { ColumnMeta, CustomDbType, DbTable, DbTableQuery, SqlQueryStatement, SqlRaw, SqlSelectable, SqlValuesCreator, TypeChecker, YourTable, YourTypeMap,
|
|
936
|
+
export { ColumnMeta, CustomDbType, DbTable, DbTableQuery, Selection, SqlQueryStatement, SqlRaw, SqlSelectable, SqlValuesCreator, TypeChecker, YourTable, YourTypeMap, getObjectListKeys, having, orderBy, pgSqlTransformer, selectColumns, where };
|
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import { SqlValuesCreator, SqlRaw } from "../sql_value/sql_value.ts";
|
|
2
2
|
import { ColumnsSelected, SelectColumns, UpdateRowValue, TableType } from "./type.ts";
|
|
3
|
-
import {
|
|
3
|
+
import { CurrentWhere, Selection } from "./select.ts";
|
|
4
4
|
import { DbTable, SqlQueryStatement } from "./selectable.ts";
|
|
5
|
-
import {
|
|
5
|
+
import { ConditionParam } from "../util.ts";
|
|
6
6
|
/** @public */
|
|
7
7
|
export declare class DbTableQuery<T extends TableType = Record<string, any>, C extends TableType = Partial<T>> extends DbTable<T> {
|
|
8
8
|
private statement;
|
|
9
9
|
constructor(name: string, columns: readonly string[], statement: SqlValuesCreator);
|
|
10
|
-
fromAs(as?: string):
|
|
10
|
+
fromAs(as?: string): Selection;
|
|
11
|
+
/** 选择单表全部列 */
|
|
12
|
+
select(columns: "*", as?: string): CurrentWhere<T>;
|
|
13
|
+
/**
|
|
14
|
+
* 选择单表
|
|
15
|
+
* @param columns - 对象选择
|
|
16
|
+
*/
|
|
17
|
+
select<R extends {
|
|
18
|
+
[key in keyof T]?: string | boolean;
|
|
19
|
+
} | Record<string, string>>(columns: R, as?: string): CurrentWhere<{
|
|
20
|
+
[key in keyof R]: R[key] extends boolean ? key extends keyof T ? T[key] : unknown : R[key] extends keyof T ? T[R[key]] : unknown;
|
|
21
|
+
}>;
|
|
22
|
+
/** 选择单表- 所有类型 */
|
|
23
|
+
select<R extends {}>(columns: "*" | string[] | {
|
|
24
|
+
[key in keyof R]?: key extends keyof T ? string | boolean : string;
|
|
25
|
+
}, as?: string): CurrentWhere<R>;
|
|
11
26
|
insert(values: C[] | SqlQueryStatement<C>, option?: InsertOption<T>): string;
|
|
12
27
|
insertWithResult<R extends ColumnsSelected<T>>(values: C[] | SqlQueryStatement<C>, returns: R, option?: InsertOption<T>): SqlQueryStatement<SelectColumns<T, R>>;
|
|
13
28
|
update(values: UpdateRowValue<T>, option?: UpdateOption): string;
|
|
@@ -21,14 +36,14 @@ export interface InsertOption<T extends object> {
|
|
|
21
36
|
updateValues?: {
|
|
22
37
|
[key in keyof T]?: undefined | SqlRaw | T[key];
|
|
23
38
|
};
|
|
24
|
-
where?:
|
|
39
|
+
where?: ConditionParam;
|
|
25
40
|
}
|
|
26
41
|
/** @public */
|
|
27
42
|
export interface UpdateOption {
|
|
28
|
-
where?:
|
|
43
|
+
where?: ConditionParam;
|
|
29
44
|
}
|
|
30
45
|
/** @public */
|
|
31
46
|
export interface DeleteOption {
|
|
32
|
-
where?:
|
|
47
|
+
where?: ConditionParam;
|
|
33
48
|
}
|
|
34
49
|
//# sourceMappingURL=TableQuery.d.ts.map
|
package/dist/select/select.d.ts
CHANGED
|
@@ -1,44 +1,43 @@
|
|
|
1
1
|
import { SqlSelectable, SqlQueryStatement } from "./selectable.ts";
|
|
2
|
-
import { OrderByParam,
|
|
2
|
+
import { OrderByParam, ConditionParam } from "../util.ts";
|
|
3
3
|
import type { TableType } from "./type.ts";
|
|
4
4
|
/** @public */
|
|
5
|
-
export interface
|
|
6
|
-
|
|
7
|
-
offset?: number;
|
|
8
|
-
limit?: number;
|
|
5
|
+
export interface CurrentLimit<T extends TableType> extends SqlQueryStatement<T> {
|
|
6
|
+
limit(limit?: number, offset?: number): SqlQueryStatement<T>;
|
|
9
7
|
}
|
|
10
8
|
/** @public */
|
|
11
|
-
export interface
|
|
12
|
-
|
|
9
|
+
export interface CurrentOrderBy<T extends TableType> extends CurrentLimit<T> {
|
|
10
|
+
orderBy(param: OrderByParam | (() => OrderByParam | void)): CurrentLimit<T>;
|
|
13
11
|
}
|
|
14
12
|
/** @public */
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}): FinalSelect<T>;
|
|
19
|
-
};
|
|
20
|
-
/** @public */
|
|
21
|
-
export type AfterGroup = LastSelect & {
|
|
22
|
-
having(param: WhereParam | (() => WhereParam)): LastSelect;
|
|
23
|
-
};
|
|
24
|
-
/** @public */
|
|
25
|
-
export type AfterWhere = AfterGroup & {
|
|
26
|
-
groupBy(columns: string | string[]): AfterGroup;
|
|
27
|
-
};
|
|
13
|
+
export interface CurrentHaving<T extends TableType> extends CurrentOrderBy<T> {
|
|
14
|
+
having(param: ConditionParam | (() => ConditionParam | void)): CurrentLimit<T>;
|
|
15
|
+
}
|
|
28
16
|
/** @public */
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
}
|
|
17
|
+
export interface CurrentGroupBy<T extends TableType> extends CurrentOrderBy<T> {
|
|
18
|
+
groupBy(columns: string | string[]): CurrentHaving<T>;
|
|
19
|
+
}
|
|
32
20
|
/** @public */
|
|
33
|
-
export interface
|
|
34
|
-
|
|
35
|
-
crossJoin(selectable: SqlSelectable<any> | string, as?: string): JoinSelect;
|
|
36
|
-
naturalJoin(selectable: SqlSelectable<any> | string, as?: string): JoinSelect;
|
|
37
|
-
innerJoin(selectable: SqlSelectable<any> | string, as: string | undefined, on: string): JoinSelect;
|
|
38
|
-
leftJoin(selectable: SqlSelectable<any> | string, as: string | undefined, on: string): JoinSelect;
|
|
39
|
-
rightJoin(selectable: SqlSelectable<any> | string, as: string | undefined, on: string): JoinSelect;
|
|
40
|
-
fullJoin(selectable: SqlSelectable<any> | string, as: string | undefined, on: string): JoinSelect;
|
|
21
|
+
export interface CurrentWhere<T extends TableType> extends CurrentGroupBy<T> {
|
|
22
|
+
where(param: ConditionParam | (() => ConditionParam | void)): CurrentGroupBy<T>;
|
|
41
23
|
}
|
|
42
24
|
/** @public */
|
|
43
|
-
export declare
|
|
25
|
+
export declare class Selection {
|
|
26
|
+
#private;
|
|
27
|
+
static from(selectable: SqlSelectable<any> | string, as?: string): Selection;
|
|
28
|
+
constructor(selectable: SqlSelectable<any> | string, as?: string);
|
|
29
|
+
toString(): string;
|
|
30
|
+
fullJoin(selectable: SqlSelectable<any>, as: string | undefined, on: string): Selection;
|
|
31
|
+
innerJoin(selectable: SqlSelectable<any>, as: string | undefined, on: string): Selection;
|
|
32
|
+
leftJoin(selectable: SqlSelectable<any>, as: string | undefined, on: string): Selection;
|
|
33
|
+
rightJoin(selectable: SqlSelectable<any>, as: string | undefined, on: string): Selection;
|
|
34
|
+
naturalJoin(selectable: SqlSelectable<any>, as?: string | undefined): Selection;
|
|
35
|
+
crossJoin(selectable: SqlSelectable<any>, as?: string | undefined): Selection;
|
|
36
|
+
from(selectable: SqlSelectable<any> | string, as?: string): Selection;
|
|
37
|
+
select<T extends TableType = TableType>(columns: "*" | string[]): CurrentWhere<T>;
|
|
38
|
+
select<T extends TableType>(columns: {
|
|
39
|
+
[key in keyof T]: string | boolean;
|
|
40
|
+
}): CurrentWhere<T>;
|
|
41
|
+
select(columns: "*" | string[] | Record<string, string | boolean>): CurrentWhere<TableType>;
|
|
42
|
+
}
|
|
44
43
|
//# sourceMappingURL=select.d.ts.map
|
package/dist/util.d.ts
CHANGED
|
@@ -1,27 +1,58 @@
|
|
|
1
1
|
import { OrderValue } from "./select/type.ts";
|
|
2
2
|
/**
|
|
3
|
+
* 获取对象数组中的 key 的集合
|
|
3
4
|
* @public
|
|
4
5
|
* @param keepUndefinedKey - 是否保留值为 undefined 的 key
|
|
5
6
|
*/
|
|
6
|
-
export declare function getObjectListKeys(objectList: any[], keepUndefinedKey?: boolean): string
|
|
7
|
+
export declare function getObjectListKeys(objectList: any[], keepUndefinedKey?: boolean): Set<string>;
|
|
7
8
|
/** @public */
|
|
8
|
-
export type
|
|
9
|
-
/** @public */
|
|
10
|
-
export declare function genWhere(where: WhereParam | (() => WhereParam), type?: "AND" | "OR"): string;
|
|
11
|
-
/** @public */
|
|
12
|
-
export declare function genHaving(having: WhereParam | (() => WhereParam), type?: "AND" | "OR"): string;
|
|
9
|
+
export type ConditionParam = string | string[];
|
|
13
10
|
/**
|
|
11
|
+
* 生成 WHERE 语句
|
|
14
12
|
* @public
|
|
15
13
|
* ```ts
|
|
16
|
-
*
|
|
17
|
-
* genSelect(["c1", "count(*) AS c2", "column as c3"]) // "c1,count(*) AS c2,column as c3"
|
|
14
|
+
*
|
|
18
15
|
* ```
|
|
19
16
|
*/
|
|
20
|
-
export declare function
|
|
17
|
+
export declare function where(conditions?: ConditionParam | (() => ConditionParam | void), type?: "AND" | "OR"): string;
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* 生成 HAVING 语句
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export declare function having(conditions?: ConditionParam | (() => ConditionParam | void), type?: "AND" | "OR"): string;
|
|
24
|
+
/**
|
|
25
|
+
* @public
|
|
26
|
+
* ```ts
|
|
27
|
+
* selectColumns({c1: true, c2: "count(*)", c3: "column"}) // "c1,count(*) AS c2,column as c3"
|
|
28
|
+
* selectColumns(["c1", "count(*) AS c2", "column as c3"]) // "c1,count(*) AS c2,column as c3"
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function selectColumns(columns: string[] | Record<string, string | boolean>): string;
|
|
21
32
|
/** @public */
|
|
22
|
-
export type
|
|
23
|
-
|
|
24
|
-
|
|
33
|
+
export type OrderBehavior = {
|
|
34
|
+
key: string;
|
|
35
|
+
asc: boolean;
|
|
36
|
+
nullLast?: boolean;
|
|
37
|
+
};
|
|
25
38
|
/** @public */
|
|
26
|
-
export
|
|
39
|
+
export type OrderByParam = string | (string | OrderBehavior)[] | Record<string, boolean | `${OrderValue} ${"NULLS FIRST" | "NULLS LAST"}`>;
|
|
40
|
+
/**
|
|
41
|
+
* 生成 ORDER BY 语句, d
|
|
42
|
+
* @public
|
|
43
|
+
* ```ts
|
|
44
|
+
* // 以下生成 "\nORDER BY age DESC NULLS FIRST,num ASC"
|
|
45
|
+
* orderBy("age DESC NULLS FIRST,num ASC");
|
|
46
|
+
* orderBy(["age DESC NULLS FIRST", "num ASC"]);
|
|
47
|
+
* orderBy([
|
|
48
|
+
* { key: "age", asc: false, nullLast: false },
|
|
49
|
+
* { key: "num", asc: true },
|
|
50
|
+
* ]);
|
|
51
|
+
* orderBy({ age: "DESC NULLS FIRST", num: true });
|
|
52
|
+
*
|
|
53
|
+
* orderBy([]) // ""
|
|
54
|
+
* orderBy({}) // ""
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function orderBy(by?: OrderByParam | void | (() => OrderByParam | void)): string;
|
|
27
58
|
//# sourceMappingURL=util.d.ts.map
|