imodel 0.15.1 → 0.16.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/index.d.mts +157 -22
- package/index.mjs +147 -33
- package/migrate.d.mts +1 -1
- package/migrate.mjs +1 -1
- package/package.json +1 -1
package/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* imodel v0.
|
|
2
|
+
* imodel v0.16.0
|
|
3
3
|
* (c) 2019-2026 undefined
|
|
4
4
|
* @license undefined
|
|
5
5
|
*/
|
|
@@ -574,6 +574,7 @@ interface VirtualTable<E extends object = object> {
|
|
|
574
574
|
updateManyReturn(environment: Environment<E>, conn: IConnection<E>, fields: Fields<keyof FieldType>, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[], returning: string[]): PromiseLike<any[]>;
|
|
575
575
|
count(environment: Environment<E>, conn: IConnection<E>, columns: Record<string, DBColumn>, where: WhereValue[]): PromiseLike<number>;
|
|
576
576
|
find(environment: Environment<E>, conn: IConnection<E>, columns: Record<string, DBColumn>, argv: FindArg): PromiseLike<any[]>;
|
|
577
|
+
select(environment: Environment<E>, conn: IConnection<E>, select: SelectItem[]): PromiseLike<any[]>;
|
|
577
578
|
delete(environment: Environment<E>, conn: IConnection<E>, columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<number>;
|
|
578
579
|
deleteReturn(environment: Environment<E>, conn: IConnection<E>, returning: string[], columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<any[]>;
|
|
579
580
|
}
|
|
@@ -754,6 +755,7 @@ interface Options {
|
|
|
754
755
|
limit?: number;
|
|
755
756
|
update?: Record<string, SetValue>;
|
|
756
757
|
alias?: string;
|
|
758
|
+
group?: string[];
|
|
757
759
|
}
|
|
758
760
|
interface Queryable<T extends Fields = Fields> extends TableDefine<T> {
|
|
759
761
|
readonly options: Options;
|
|
@@ -787,6 +789,30 @@ interface FindArg {
|
|
|
787
789
|
/** 最大返回数 */
|
|
788
790
|
limit?: number;
|
|
789
791
|
}
|
|
792
|
+
interface JOIN {
|
|
793
|
+
type?: 'INNER' | 'LEFT' | 'RIGHT' | 'FULL' | 'CROSS';
|
|
794
|
+
table: string;
|
|
795
|
+
columns: Record<string, DBColumn>;
|
|
796
|
+
alias?: string;
|
|
797
|
+
condition?: WhereValue[];
|
|
798
|
+
}
|
|
799
|
+
interface SelectItem {
|
|
800
|
+
distinct?: boolean;
|
|
801
|
+
select: [string, Select][];
|
|
802
|
+
table: string;
|
|
803
|
+
columns: Record<string, DBColumn>;
|
|
804
|
+
alias?: string;
|
|
805
|
+
/** 匹配信息 */
|
|
806
|
+
where: WhereValue[];
|
|
807
|
+
group: string[];
|
|
808
|
+
having: WhereValue[];
|
|
809
|
+
/** 排序配置,true 表示逆序 */
|
|
810
|
+
sort: [field: string, desc: boolean][];
|
|
811
|
+
/** 偏移量 */
|
|
812
|
+
offset?: number;
|
|
813
|
+
/** 最大返回数 */
|
|
814
|
+
limit?: number;
|
|
815
|
+
}
|
|
790
816
|
type GetName = (table?: string) => string;
|
|
791
817
|
interface DBColumn {
|
|
792
818
|
type: string;
|
|
@@ -829,6 +855,7 @@ interface IConnection<E extends object = object> {
|
|
|
829
855
|
updateManyReturn(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, update: Record<string, any>, pKeys: string[], setKeys: string[], list: Record<string, any>[], where: WhereValue[], returning: string[]): PromiseLike<any[]>;
|
|
830
856
|
count(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<number>;
|
|
831
857
|
find(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, argv: FindArg): PromiseLike<any[]>;
|
|
858
|
+
select(environment: Environment<E>, select: SelectItem[]): PromiseLike<any[]>;
|
|
832
859
|
delete(environment: Environment<E>, table: string, columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<number>;
|
|
833
860
|
deleteReturn(environment: Environment<E>, returning: string[], table: string, columns: Record<string, DBColumn>, where?: WhereValue[] | null): PromiseLike<any[]>;
|
|
834
861
|
createTable(environment: Environment<E>, table: string, columns: Column<any>[]): PromiseLike<number>;
|
|
@@ -1533,63 +1560,166 @@ declare class Connection<E extends {} = {}> {
|
|
|
1533
1560
|
*/
|
|
1534
1561
|
destroyMany(queryable: Queryable, update?: Record<string, SetValue> | boolean): Promise<number>;
|
|
1535
1562
|
/**
|
|
1536
|
-
* @template {object
|
|
1563
|
+
* @template {object} T
|
|
1537
1564
|
* @overload
|
|
1538
1565
|
* @param {TableDefine} tableDefine
|
|
1539
1566
|
* @param {T} data
|
|
1540
1567
|
* @param {boolean} [ignoreConflict]
|
|
1541
|
-
* @returns {Promise<T
|
|
1568
|
+
* @returns {Promise<T>}
|
|
1569
|
+
*/
|
|
1570
|
+
insert<T extends unknown>(tableDefine: TableDefine, data: T, ignoreConflict?: boolean | undefined): Promise<T>;
|
|
1571
|
+
/**
|
|
1572
|
+
* @template {object} T
|
|
1573
|
+
* @overload
|
|
1574
|
+
* @param {TableDefine} tableDefine
|
|
1575
|
+
* @param {T[]} data
|
|
1576
|
+
* @param {boolean} [ignoreConflict]
|
|
1577
|
+
* @returns {Promise<T[]>}
|
|
1542
1578
|
*/
|
|
1543
|
-
insert<T extends unknown>(tableDefine: TableDefine, data: T, ignoreConflict?: boolean | undefined): Promise<T
|
|
1579
|
+
insert<T extends unknown>(tableDefine: TableDefine, data: T[], ignoreConflict?: boolean | undefined): Promise<T[]>;
|
|
1544
1580
|
/**
|
|
1545
|
-
* @template {object
|
|
1581
|
+
* @template {object} T
|
|
1546
1582
|
* @overload
|
|
1547
1583
|
* @param {TableDefine} tableDefine
|
|
1548
1584
|
* @param {T} data
|
|
1549
1585
|
* @param {string[]} [keys]
|
|
1550
1586
|
* @param {boolean} [ignoreConflict]
|
|
1551
|
-
* @returns {Promise<T
|
|
1587
|
+
* @returns {Promise<T>}
|
|
1588
|
+
*/
|
|
1589
|
+
insert<T extends unknown>(tableDefine: TableDefine, data: T, keys?: string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T>;
|
|
1590
|
+
/**
|
|
1591
|
+
* @template {object} T
|
|
1592
|
+
* @overload
|
|
1593
|
+
* @param {TableDefine} tableDefine
|
|
1594
|
+
* @param {T[]} data
|
|
1595
|
+
* @param {string[]} [keys]
|
|
1596
|
+
* @param {boolean} [ignoreConflict]
|
|
1597
|
+
* @returns {Promise<T[]>}
|
|
1552
1598
|
*/
|
|
1553
|
-
insert<T extends unknown>(tableDefine: TableDefine, data: T, keys?: string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T
|
|
1599
|
+
insert<T extends unknown>(tableDefine: TableDefine, data: T[], keys?: string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T[]>;
|
|
1554
1600
|
/**
|
|
1555
|
-
* @template {object
|
|
1601
|
+
* @template {object} T
|
|
1556
1602
|
* @overload
|
|
1557
1603
|
* @param {TableDefine} tableDefine
|
|
1558
1604
|
* @param {T} data
|
|
1559
1605
|
* @param {string[] | boolean} [keys]
|
|
1560
1606
|
* @param {boolean} [ignoreConflict]
|
|
1561
|
-
* @returns {Promise<T
|
|
1607
|
+
* @returns {Promise<T>}
|
|
1608
|
+
*/
|
|
1609
|
+
insert<T extends unknown>(tableDefine: TableDefine, data: T, keys?: boolean | string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T>;
|
|
1610
|
+
/**
|
|
1611
|
+
* @template {object} T
|
|
1612
|
+
* @overload
|
|
1613
|
+
* @param {TableDefine} tableDefine
|
|
1614
|
+
* @param {T[]} data
|
|
1615
|
+
* @param {string[] | boolean} [keys]
|
|
1616
|
+
* @param {boolean} [ignoreConflict]
|
|
1617
|
+
* @returns {Promise<T[]>}
|
|
1618
|
+
*/
|
|
1619
|
+
insert<T extends unknown>(tableDefine: TableDefine, data: T[], keys?: boolean | string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T[]>;
|
|
1620
|
+
/**
|
|
1621
|
+
* @template {object} T
|
|
1622
|
+
* @overload
|
|
1623
|
+
* @param {TableDefine} tableDefine
|
|
1624
|
+
* @param {T | T[]} data
|
|
1625
|
+
* @param {string[] | boolean} [keys]
|
|
1626
|
+
* @param {boolean} [ignoreConflict]
|
|
1627
|
+
* @returns {Promise<T | T[]>}
|
|
1562
1628
|
*/
|
|
1563
|
-
insert<T extends unknown>(tableDefine: TableDefine, data: T, keys?: boolean | string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T
|
|
1629
|
+
insert<T extends unknown>(tableDefine: TableDefine, data: T | T[], keys?: boolean | string[] | undefined, ignoreConflict?: boolean | undefined): Promise<T | T[]>;
|
|
1564
1630
|
/**
|
|
1565
|
-
* @template {object
|
|
1631
|
+
* @template {object} T
|
|
1566
1632
|
* @overload
|
|
1567
1633
|
* @param {TableDefine} tableDefine
|
|
1568
1634
|
* @param {T} data
|
|
1569
1635
|
* @param {Record<string, SetValue>} [conflictSet]
|
|
1570
|
-
* @returns {Promise<T
|
|
1636
|
+
* @returns {Promise<T>}
|
|
1637
|
+
*/
|
|
1638
|
+
upsert<T extends unknown>(tableDefine: TableDefine, data: T, conflictSet?: Record<string, SetValue> | undefined): Promise<T>;
|
|
1639
|
+
/**
|
|
1640
|
+
* @template {object} T
|
|
1641
|
+
* @overload
|
|
1642
|
+
* @param {TableDefine} tableDefine
|
|
1643
|
+
* @param {T[]} data
|
|
1644
|
+
* @param {Record<string, SetValue>} [conflictSet]
|
|
1645
|
+
* @returns {Promise<T[]>}
|
|
1571
1646
|
*/
|
|
1572
|
-
upsert<T extends unknown>(tableDefine: TableDefine, data: T, conflictSet?: Record<string, SetValue> | undefined): Promise<T
|
|
1647
|
+
upsert<T extends unknown>(tableDefine: TableDefine, data: T[], conflictSet?: Record<string, SetValue> | undefined): Promise<T[]>;
|
|
1573
1648
|
/**
|
|
1574
|
-
* @template {object
|
|
1649
|
+
* @template {object} T
|
|
1575
1650
|
* @overload
|
|
1576
1651
|
* @param {TableDefine} tableDefine
|
|
1577
1652
|
* @param {T} data
|
|
1578
|
-
* @param {string[]} [keys]
|
|
1653
|
+
* @param {null | string[]} [keys]
|
|
1654
|
+
* @param {Record<string, SetValue>} [conflictSet]
|
|
1655
|
+
* @returns {Promise<T>}
|
|
1656
|
+
*/
|
|
1657
|
+
upsert<T extends unknown>(tableDefine: TableDefine, data: T, keys?: string[] | null | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T>;
|
|
1658
|
+
/**
|
|
1659
|
+
* @template {object} T
|
|
1660
|
+
* @overload
|
|
1661
|
+
* @param {TableDefine} tableDefine
|
|
1662
|
+
* @param {T[]} data
|
|
1663
|
+
* @param {null | string[]} [keys]
|
|
1579
1664
|
* @param {Record<string, SetValue>} [conflictSet]
|
|
1580
|
-
* @returns {Promise<T
|
|
1665
|
+
* @returns {Promise<T[]>}
|
|
1581
1666
|
*/
|
|
1582
|
-
upsert<T extends unknown>(tableDefine: TableDefine, data: T, keys?: string[] | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T
|
|
1667
|
+
upsert<T extends unknown>(tableDefine: TableDefine, data: T[], keys?: string[] | null | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T[]>;
|
|
1583
1668
|
/**
|
|
1584
|
-
* @template {object
|
|
1669
|
+
* @template {object} T
|
|
1585
1670
|
* @overload
|
|
1586
1671
|
* @param {TableDefine} tableDefine
|
|
1587
1672
|
* @param {T} data
|
|
1588
|
-
* @param {
|
|
1673
|
+
* @param {null | string[]} [keys]
|
|
1674
|
+
* @param {string[] | boolean} [conflictKeys]
|
|
1589
1675
|
* @param {Record<string, SetValue>} [conflictSet]
|
|
1590
|
-
* @returns {Promise<T
|
|
1676
|
+
* @returns {Promise<T>}
|
|
1591
1677
|
*/
|
|
1592
|
-
upsert<T extends unknown>(tableDefine: TableDefine, data: T, keys?: string[] |
|
|
1678
|
+
upsert<T extends unknown>(tableDefine: TableDefine, data: T, keys?: string[] | null | undefined, conflictKeys?: boolean | string[] | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T>;
|
|
1679
|
+
/**
|
|
1680
|
+
* @template {object} T
|
|
1681
|
+
* @overload
|
|
1682
|
+
* @param {TableDefine} tableDefine
|
|
1683
|
+
* @param {T[]} data
|
|
1684
|
+
* @param {null | string[]} [keys]
|
|
1685
|
+
* @param {string[] | boolean} [conflictKeys]
|
|
1686
|
+
* @param {Record<string, SetValue>} [conflictSet]
|
|
1687
|
+
* @returns {Promise<T[]>}
|
|
1688
|
+
*/
|
|
1689
|
+
upsert<T extends unknown>(tableDefine: TableDefine, data: T[], keys?: string[] | null | undefined, conflictKeys?: boolean | string[] | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T[]>;
|
|
1690
|
+
/**
|
|
1691
|
+
* @template {object} T
|
|
1692
|
+
* @overload
|
|
1693
|
+
* @param {TableDefine} tableDefine
|
|
1694
|
+
* @param {T} data
|
|
1695
|
+
* @param {null | string[] | boolean | Record<string, SetValue>} [keys]
|
|
1696
|
+
* @param {string[] | boolean | Record<string, SetValue>} [conflictKeys]
|
|
1697
|
+
* @param {Record<string, SetValue>} [conflictSet]
|
|
1698
|
+
* @returns {Promise<T>}
|
|
1699
|
+
*/
|
|
1700
|
+
upsert<T extends unknown>(tableDefine: TableDefine, data: T, keys?: boolean | string[] | Record<string, SetValue> | null | undefined, conflictKeys?: boolean | string[] | Record<string, SetValue> | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T>;
|
|
1701
|
+
/**
|
|
1702
|
+
* @template {object} T
|
|
1703
|
+
* @overload
|
|
1704
|
+
* @param {TableDefine} tableDefine
|
|
1705
|
+
* @param {T[]} data
|
|
1706
|
+
* @param {null | string[] | boolean | Record<string, SetValue>} [keys]
|
|
1707
|
+
* @param {string[] | boolean | Record<string, SetValue>} [conflictKeys]
|
|
1708
|
+
* @param {Record<string, SetValue>} [conflictSet]
|
|
1709
|
+
* @returns {Promise<T[]>}
|
|
1710
|
+
*/
|
|
1711
|
+
upsert<T extends unknown>(tableDefine: TableDefine, data: T[], keys?: boolean | string[] | Record<string, SetValue> | null | undefined, conflictKeys?: boolean | string[] | Record<string, SetValue> | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T[]>;
|
|
1712
|
+
/**
|
|
1713
|
+
* @template {object} T
|
|
1714
|
+
* @overload
|
|
1715
|
+
* @param {TableDefine} tableDefine
|
|
1716
|
+
* @param {T | T[]} data
|
|
1717
|
+
* @param {null | string[] | boolean | Record<string, SetValue>} [keys]
|
|
1718
|
+
* @param {string[] | boolean | Record<string, SetValue>} [conflictKeys]
|
|
1719
|
+
* @param {Record<string, SetValue>} [conflictSet]
|
|
1720
|
+
* @returns {Promise<T | T[]>}
|
|
1721
|
+
*/
|
|
1722
|
+
upsert<T extends unknown>(tableDefine: TableDefine, data: T | T[], keys?: boolean | string[] | Record<string, SetValue> | null | undefined, conflictKeys?: boolean | string[] | Record<string, SetValue> | undefined, conflictSet?: Record<string, SetValue> | undefined): Promise<T | T[]>;
|
|
1593
1723
|
/**
|
|
1594
1724
|
* @param {TableDefine} tableDefine
|
|
1595
1725
|
* @param {Record<string, any>} update
|
|
@@ -1958,6 +2088,11 @@ declare class Query<T extends Fields, TB extends unknown = any> implements Query
|
|
|
1958
2088
|
* @returns {this}
|
|
1959
2089
|
*/
|
|
1960
2090
|
primary(primary?: any, ...args: any[]): this;
|
|
2091
|
+
/**
|
|
2092
|
+
*
|
|
2093
|
+
* @param {...string | string[]} groups
|
|
2094
|
+
*/
|
|
2095
|
+
groupBy(...groups: (string | string[])[]): this;
|
|
1961
2096
|
/**
|
|
1962
2097
|
*
|
|
1963
2098
|
* @param {object} a
|
|
@@ -2383,4 +2518,4 @@ declare function field<T extends MainFieldType>(type: T, options: {
|
|
|
2383
2518
|
declare function setDevelopment(d?: boolean): void;
|
|
2384
2519
|
declare let isDevelopment: boolean;
|
|
2385
2520
|
|
|
2386
|
-
export { Build, type ClassDecorator, type Column, type ColumnOptions, Connection, type Constraint, Create, type DBColumn, type DBIndex, type DBTable, Destroy, type Environment, type FieldDecorator, type FieldDefine, type FieldDefineOption, type FieldDefineType, type FieldSpecific, type FieldSpecificValue, type FieldType, type FieldTypeDefine, type FieldValue, type Fields, type FindArg, type FindRange, type GetName, type Hook, type Hooks, type IConnection, type Index, type IndexInfo, type IndexOptions, type Join, type JoinType, type MainFieldType, type MaybePromise, type MethodDecorator, Model, type Options, PseudoDestroy, Query, type QueryOptions, type Queryable, Save, Scene, Select, SetValue, type Skip, Submodel, type Support, type TableDefine, type TableType, type ToFieldType, type ToType, type TransactionFn, type VirtualTable, Where, type WhereItem, type WhereLike, type WhereOr, type WhereRaw, type WhereValue, type Wheres, afterCreate, afterCreateMany, afterDelete, afterUpdate, beforeCreate, beforeCreateMany, beforeDelete, beforeUpdate, coefficient, column, creating, decrement, defaultValue, field as define, deleted, deleting, divide, field$1 as field, getPrimaryFields, getPrimaryKeys, immutable, increment, index, isDevelopment, isPseudo, model, multiply, now, primary, prop, pseudo, setDevelopment, sort, model as submodel, toNot, toPrimaries, toPrimary, uncreatable, undeleted, updating, uuid, values, where, withDeleted };
|
|
2521
|
+
export { Build, type ClassDecorator, type Column, type ColumnOptions, Connection, type Constraint, Create, type DBColumn, type DBIndex, type DBTable, Destroy, type Environment, type FieldDecorator, type FieldDefine, type FieldDefineOption, type FieldDefineType, type FieldSpecific, type FieldSpecificValue, type FieldType, type FieldTypeDefine, type FieldValue, type Fields, type FindArg, type FindRange, type GetName, type Hook, type Hooks, type IConnection, type Index, type IndexInfo, type IndexOptions, type JOIN, type Join, type JoinType, type MainFieldType, type MaybePromise, type MethodDecorator, Model, type Options, PseudoDestroy, Query, type QueryOptions, type Queryable, Save, Scene, Select, type SelectItem, SetValue, type Skip, Submodel, type Support, type TableDefine, type TableType, type ToFieldType, type ToType, type TransactionFn, type VirtualTable, Where, type WhereItem, type WhereLike, type WhereOr, type WhereRaw, type WhereValue, type Wheres, afterCreate, afterCreateMany, afterDelete, afterUpdate, beforeCreate, beforeCreateMany, beforeDelete, beforeUpdate, coefficient, column, creating, decrement, defaultValue, field as define, deleted, deleting, divide, field$1 as field, getPrimaryFields, getPrimaryKeys, immutable, increment, index, isDevelopment, isPseudo, model, multiply, now, primary, prop, pseudo, setDevelopment, sort, model as submodel, toNot, toPrimaries, toPrimary, uncreatable, undeleted, updating, uuid, values, where, withDeleted };
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* imodel v0.
|
|
2
|
+
* imodel v0.16.0
|
|
3
3
|
* (c) 2019-2026 undefined
|
|
4
4
|
* @license undefined
|
|
5
5
|
*/
|
|
@@ -2934,38 +2934,73 @@ class Connection {
|
|
|
2934
2934
|
return pseudoDeleteMany(conn, queryable, update, this.#env);
|
|
2935
2935
|
}
|
|
2936
2936
|
/**
|
|
2937
|
-
* @template {object
|
|
2937
|
+
* @template {object} T
|
|
2938
2938
|
* @overload
|
|
2939
2939
|
* @param {TableDefine} tableDefine
|
|
2940
2940
|
* @param {T} data
|
|
2941
2941
|
* @param {boolean} [ignoreConflict]
|
|
2942
|
-
* @returns {Promise<T
|
|
2942
|
+
* @returns {Promise<T>}
|
|
2943
|
+
*/
|
|
2944
|
+
/**
|
|
2945
|
+
* @template {object} T
|
|
2946
|
+
* @overload
|
|
2947
|
+
* @param {TableDefine} tableDefine
|
|
2948
|
+
* @param {T[]} data
|
|
2949
|
+
* @param {boolean} [ignoreConflict]
|
|
2950
|
+
* @returns {Promise<T[]>}
|
|
2943
2951
|
*/
|
|
2944
2952
|
/**
|
|
2945
|
-
* @template {object
|
|
2953
|
+
* @template {object} T
|
|
2946
2954
|
* @overload
|
|
2947
2955
|
* @param {TableDefine} tableDefine
|
|
2948
2956
|
* @param {T} data
|
|
2949
2957
|
* @param {string[]} [keys]
|
|
2950
2958
|
* @param {boolean} [ignoreConflict]
|
|
2951
|
-
* @returns {Promise<T
|
|
2959
|
+
* @returns {Promise<T>}
|
|
2952
2960
|
*/
|
|
2953
2961
|
/**
|
|
2954
|
-
* @template {object
|
|
2962
|
+
* @template {object} T
|
|
2963
|
+
* @overload
|
|
2964
|
+
* @param {TableDefine} tableDefine
|
|
2965
|
+
* @param {T[]} data
|
|
2966
|
+
* @param {string[]} [keys]
|
|
2967
|
+
* @param {boolean} [ignoreConflict]
|
|
2968
|
+
* @returns {Promise<T[]>}
|
|
2969
|
+
*/
|
|
2970
|
+
/**
|
|
2971
|
+
* @template {object} T
|
|
2955
2972
|
* @overload
|
|
2956
2973
|
* @param {TableDefine} tableDefine
|
|
2957
2974
|
* @param {T} data
|
|
2958
2975
|
* @param {string[] | boolean} [keys]
|
|
2959
2976
|
* @param {boolean} [ignoreConflict]
|
|
2960
|
-
* @returns {Promise<T
|
|
2977
|
+
* @returns {Promise<T>}
|
|
2961
2978
|
*/
|
|
2962
2979
|
/**
|
|
2963
|
-
* @template {object
|
|
2980
|
+
* @template {object} T
|
|
2981
|
+
* @overload
|
|
2964
2982
|
* @param {TableDefine} tableDefine
|
|
2965
|
-
* @param {T} data
|
|
2983
|
+
* @param {T[]} data
|
|
2966
2984
|
* @param {string[] | boolean} [keys]
|
|
2967
2985
|
* @param {boolean} [ignoreConflict]
|
|
2968
|
-
* @returns {Promise<T
|
|
2986
|
+
* @returns {Promise<T[]>}
|
|
2987
|
+
*/
|
|
2988
|
+
/**
|
|
2989
|
+
* @template {object} T
|
|
2990
|
+
* @overload
|
|
2991
|
+
* @param {TableDefine} tableDefine
|
|
2992
|
+
* @param {T | T[]} data
|
|
2993
|
+
* @param {string[] | boolean} [keys]
|
|
2994
|
+
* @param {boolean} [ignoreConflict]
|
|
2995
|
+
* @returns {Promise<T | T[]>}
|
|
2996
|
+
*/
|
|
2997
|
+
/**
|
|
2998
|
+
* @template {object} T
|
|
2999
|
+
* @param {TableDefine} tableDefine
|
|
3000
|
+
* @param {T | T[]} data
|
|
3001
|
+
* @param {string[] | boolean} [keys]
|
|
3002
|
+
* @param {boolean} [ignoreConflict]
|
|
3003
|
+
* @returns {Promise<T | T[]>}
|
|
2969
3004
|
*/
|
|
2970
3005
|
async insert({
|
|
2971
3006
|
table,
|
|
@@ -2973,7 +3008,9 @@ class Connection {
|
|
|
2973
3008
|
}, data, keys, ignoreConflict) {
|
|
2974
3009
|
const [columns, fieldColumns] = toColumns(fields);
|
|
2975
3010
|
const isArray = Array.isArray(data);
|
|
2976
|
-
const insertValues = (isArray ? data : [data]
|
|
3011
|
+
const insertValues = (isArray ? data : [data]
|
|
3012
|
+
// @ts-ignore
|
|
3013
|
+
).map(d => getInsertValue(d, columns, fieldColumns, {
|
|
2977
3014
|
uncreatable: true
|
|
2978
3015
|
}));
|
|
2979
3016
|
if (!insertValues.length) {
|
|
@@ -2995,52 +3032,113 @@ class Connection {
|
|
|
2995
3032
|
return isArray ? list : list[0];
|
|
2996
3033
|
}
|
|
2997
3034
|
/**
|
|
2998
|
-
* @template {object
|
|
3035
|
+
* @template {object} T
|
|
2999
3036
|
* @overload
|
|
3000
3037
|
* @param {TableDefine} tableDefine
|
|
3001
3038
|
* @param {T} data
|
|
3002
3039
|
* @param {Record<string, SetValue>} [conflictSet]
|
|
3003
|
-
* @returns {Promise<T
|
|
3040
|
+
* @returns {Promise<T>}
|
|
3004
3041
|
*/
|
|
3005
3042
|
/**
|
|
3006
|
-
* @template {object
|
|
3043
|
+
* @template {object} T
|
|
3044
|
+
* @overload
|
|
3045
|
+
* @param {TableDefine} tableDefine
|
|
3046
|
+
* @param {T[]} data
|
|
3047
|
+
* @param {Record<string, SetValue>} [conflictSet]
|
|
3048
|
+
* @returns {Promise<T[]>}
|
|
3049
|
+
*/
|
|
3050
|
+
/**
|
|
3051
|
+
* @template {object} T
|
|
3007
3052
|
* @overload
|
|
3008
3053
|
* @param {TableDefine} tableDefine
|
|
3009
3054
|
* @param {T} data
|
|
3010
|
-
* @param {string[]} [keys]
|
|
3055
|
+
* @param {null | string[]} [keys]
|
|
3011
3056
|
* @param {Record<string, SetValue>} [conflictSet]
|
|
3012
|
-
* @returns {Promise<T
|
|
3057
|
+
* @returns {Promise<T>}
|
|
3013
3058
|
*/
|
|
3014
3059
|
/**
|
|
3015
|
-
* @template {object
|
|
3060
|
+
* @template {object} T
|
|
3061
|
+
* @overload
|
|
3062
|
+
* @param {TableDefine} tableDefine
|
|
3063
|
+
* @param {T[]} data
|
|
3064
|
+
* @param {null | string[]} [keys]
|
|
3065
|
+
* @param {Record<string, SetValue>} [conflictSet]
|
|
3066
|
+
* @returns {Promise<T[]>}
|
|
3067
|
+
*/
|
|
3068
|
+
/**
|
|
3069
|
+
* @template {object} T
|
|
3016
3070
|
* @overload
|
|
3017
3071
|
* @param {TableDefine} tableDefine
|
|
3018
3072
|
* @param {T} data
|
|
3019
|
-
* @param {
|
|
3073
|
+
* @param {null | string[]} [keys]
|
|
3074
|
+
* @param {string[] | boolean} [conflictKeys]
|
|
3075
|
+
* @param {Record<string, SetValue>} [conflictSet]
|
|
3076
|
+
* @returns {Promise<T>}
|
|
3077
|
+
*/
|
|
3078
|
+
/**
|
|
3079
|
+
* @template {object} T
|
|
3080
|
+
* @overload
|
|
3081
|
+
* @param {TableDefine} tableDefine
|
|
3082
|
+
* @param {T[]} data
|
|
3083
|
+
* @param {null | string[]} [keys]
|
|
3084
|
+
* @param {string[] | boolean} [conflictKeys]
|
|
3020
3085
|
* @param {Record<string, SetValue>} [conflictSet]
|
|
3021
|
-
* @returns {Promise<T
|
|
3086
|
+
* @returns {Promise<T[]>}
|
|
3022
3087
|
*/
|
|
3023
3088
|
/**
|
|
3024
|
-
* @template {object
|
|
3089
|
+
* @template {object} T
|
|
3090
|
+
* @overload
|
|
3025
3091
|
* @param {TableDefine} tableDefine
|
|
3026
3092
|
* @param {T} data
|
|
3027
|
-
* @param {string[] | Record<string, SetValue>} [keys]
|
|
3093
|
+
* @param {null | string[] | boolean | Record<string, SetValue>} [keys]
|
|
3094
|
+
* @param {string[] | boolean | Record<string, SetValue>} [conflictKeys]
|
|
3095
|
+
* @param {Record<string, SetValue>} [conflictSet]
|
|
3096
|
+
* @returns {Promise<T>}
|
|
3097
|
+
*/
|
|
3098
|
+
/**
|
|
3099
|
+
* @template {object} T
|
|
3100
|
+
* @overload
|
|
3101
|
+
* @param {TableDefine} tableDefine
|
|
3102
|
+
* @param {T[]} data
|
|
3103
|
+
* @param {null | string[] | boolean | Record<string, SetValue>} [keys]
|
|
3104
|
+
* @param {string[] | boolean | Record<string, SetValue>} [conflictKeys]
|
|
3105
|
+
* @param {Record<string, SetValue>} [conflictSet]
|
|
3106
|
+
* @returns {Promise<T[]>}
|
|
3107
|
+
*/
|
|
3108
|
+
/**
|
|
3109
|
+
* @template {object} T
|
|
3110
|
+
* @overload
|
|
3111
|
+
* @param {TableDefine} tableDefine
|
|
3112
|
+
* @param {T | T[]} data
|
|
3113
|
+
* @param {null | string[] | boolean | Record<string, SetValue>} [keys]
|
|
3114
|
+
* @param {string[] | boolean | Record<string, SetValue>} [conflictKeys]
|
|
3115
|
+
* @param {Record<string, SetValue>} [conflictSet]
|
|
3116
|
+
* @returns {Promise<T | T[]>}
|
|
3117
|
+
*/
|
|
3118
|
+
/**
|
|
3119
|
+
* @template {object} T
|
|
3120
|
+
* @param {TableDefine} tableDefine
|
|
3121
|
+
* @param {T | T[]} data
|
|
3122
|
+
* @param {null | string[] | boolean | Record<string, SetValue>} [keys]
|
|
3123
|
+
* @param {string[] | boolean | Record<string, SetValue>} [conflictKeys]
|
|
3028
3124
|
* @param {Record<string, SetValue>} [conflictSet]
|
|
3029
|
-
* @returns {Promise<T
|
|
3125
|
+
* @returns {Promise<T | T[]>}
|
|
3030
3126
|
*/
|
|
3031
3127
|
async upsert({
|
|
3032
3128
|
table,
|
|
3033
3129
|
fields
|
|
3034
|
-
}, data, keys, conflictSet) {
|
|
3130
|
+
}, data, keys, conflictKeys, conflictSet) {
|
|
3035
3131
|
const [columns, fieldColumns, baseFields] = toColumns(fields);
|
|
3036
3132
|
const isArray = Array.isArray(data);
|
|
3037
|
-
const insertValues = (isArray ? data : [data]
|
|
3133
|
+
const insertValues = (isArray ? data : [data]
|
|
3134
|
+
// @ts-ignore
|
|
3135
|
+
).map(d => getInsertValue(d, columns, fieldColumns, {
|
|
3038
3136
|
uncreatable: true
|
|
3039
3137
|
}));
|
|
3040
3138
|
if (!insertValues.length) {
|
|
3041
3139
|
throw new Error();
|
|
3042
3140
|
}
|
|
3043
|
-
const set = Array.isArray(
|
|
3141
|
+
const set = [keys, conflictKeys, conflictSet].find(/** @type {(v: any) => v is Record<string, SetValue>} */v => v && !Array.isArray(v) && typeof v === 'object');
|
|
3044
3142
|
const saveKeys = Array.isArray(keys) ? [...new Set(keys)] : [];
|
|
3045
3143
|
let insertKeys = fieldColumns ? saveKeys.map(k => fieldColumns[k]).filter(Boolean) : saveKeys.filter(k => k in columns);
|
|
3046
3144
|
if (!insertKeys.length && !isArray) {
|
|
@@ -3049,9 +3147,9 @@ class Connection {
|
|
|
3049
3147
|
if (!insertKeys.length) {
|
|
3050
3148
|
insertKeys = Object.entries(columns).map(v => v[0]);
|
|
3051
3149
|
}
|
|
3052
|
-
const
|
|
3150
|
+
const conflict = Array.isArray(conflictKeys) || conflictKeys === true ? conflictKeys : baseFields.filter(([, v]) => v.primary).sort(([, a], [, b]) => Number(a.primary) - Number(b.primary)).map(([v]) => v);
|
|
3053
3151
|
const conn = await this.#getConnection();
|
|
3054
|
-
const result = table && typeof table === 'object' ? await table.upsert(this.#env, conn, columns, insertValues, insertKeys,
|
|
3152
|
+
const result = table && typeof table === 'object' ? await table.upsert(this.#env, conn, columns, insertValues, insertKeys, conflict, set) : await conn.upsert(this.#env, table || '', columns, insertValues, insertKeys, conflict, set);
|
|
3055
3153
|
const list = toFieldList(result, fieldColumns);
|
|
3056
3154
|
// @ts-ignore
|
|
3057
3155
|
return isArray ? list : list[0];
|
|
@@ -3202,19 +3300,27 @@ class Connection {
|
|
|
3202
3300
|
const {
|
|
3203
3301
|
sort
|
|
3204
3302
|
} = options;
|
|
3205
|
-
const result = table && typeof table === 'object' ? await table.
|
|
3303
|
+
const result = table && typeof table === 'object' ? await table.select(this.#env, conn, [{
|
|
3304
|
+
table: '',
|
|
3305
|
+
columns,
|
|
3206
3306
|
offset,
|
|
3207
3307
|
limit,
|
|
3208
3308
|
where,
|
|
3209
3309
|
select,
|
|
3210
|
-
sort: sort?.length ? sort2column(sort, fieldColumns) : getDefaultSort(columns)
|
|
3211
|
-
|
|
3310
|
+
sort: sort?.length ? sort2column(sort, fieldColumns) : getDefaultSort(columns),
|
|
3311
|
+
group: options.group || [],
|
|
3312
|
+
having: []
|
|
3313
|
+
}]) : await conn.select(this.#env, [{
|
|
3314
|
+
table: table || '',
|
|
3315
|
+
columns,
|
|
3212
3316
|
offset,
|
|
3213
3317
|
limit,
|
|
3214
3318
|
where,
|
|
3215
3319
|
select,
|
|
3216
|
-
sort: sort?.length ? sort2column(sort, fieldColumns) : getDefaultSort(columns)
|
|
3217
|
-
|
|
3320
|
+
sort: sort?.length ? sort2column(sort, fieldColumns) : getDefaultSort(columns),
|
|
3321
|
+
group: options.group || [],
|
|
3322
|
+
having: []
|
|
3323
|
+
}]);
|
|
3218
3324
|
return result;
|
|
3219
3325
|
}
|
|
3220
3326
|
/**
|
|
@@ -4667,7 +4773,7 @@ function selectFn(fn, select, newSelect) {
|
|
|
4667
4773
|
if (typeof s === 'string') {
|
|
4668
4774
|
select[s] = {
|
|
4669
4775
|
field: s,
|
|
4670
|
-
fn
|
|
4776
|
+
fn
|
|
4671
4777
|
};
|
|
4672
4778
|
continue;
|
|
4673
4779
|
}
|
|
@@ -5142,6 +5248,14 @@ class Query {
|
|
|
5142
5248
|
m.#primary = primary;
|
|
5143
5249
|
return m;
|
|
5144
5250
|
}
|
|
5251
|
+
/**
|
|
5252
|
+
*
|
|
5253
|
+
* @param {...string | string[]} groups
|
|
5254
|
+
*/
|
|
5255
|
+
groupBy(...groups) {
|
|
5256
|
+
this.#options.group = [this.#options.group || [], groups].flat(2);
|
|
5257
|
+
return this;
|
|
5258
|
+
}
|
|
5145
5259
|
}
|
|
5146
5260
|
|
|
5147
5261
|
/** @import { Fields, IndexInfo, FieldDefine } from './types' */
|
package/migrate.d.mts
CHANGED
package/migrate.mjs
CHANGED