imodel-pg 0.15.0 → 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 +1 -1
- package/index.mjs +45 -9
- package/package.json +1 -1
package/index.d.mts
CHANGED
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
|
*/
|
|
@@ -687,12 +687,12 @@ function getWhere2(env, wheres) {
|
|
|
687
687
|
* @param {WhereValue[]?} [where]
|
|
688
688
|
* @returns {Sql | undefined}
|
|
689
689
|
*/
|
|
690
|
-
function getWhere(env, where) {
|
|
690
|
+
function getWhere(env, where, key = 'WHERE') {
|
|
691
691
|
const andList = getWhere2(env, where);
|
|
692
692
|
if (!andList) {
|
|
693
693
|
return;
|
|
694
694
|
}
|
|
695
|
-
return Sql
|
|
695
|
+
return Sql`${Sql(key)} ${andList}`;
|
|
696
696
|
}
|
|
697
697
|
|
|
698
698
|
/** @import { DBColumn, Environment, FindArg } from 'imodel' */
|
|
@@ -874,11 +874,13 @@ function insertSql(env, table, columns, list, keys, conflict, conflictSet) {
|
|
|
874
874
|
const setList = conflictSet && typeof conflictSet === 'object' ? getSet(conflictSet, columns, env) : [];
|
|
875
875
|
if (fields?.length) {
|
|
876
876
|
conflictSql = Sql(['ON CONFLICT (', ...Array(fields.length - 1).fill(','), ')'], ...fields.map(f => Sql.Field(f)));
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
877
|
+
if (!setList.length) {
|
|
878
|
+
for (const f of key) {
|
|
879
|
+
if (fields.includes(f)) {
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
setList.push(Sql`${Sql.Field(f)} = EXCLUDED.${Sql.Field(f)}`);
|
|
880
883
|
}
|
|
881
|
-
setList.push(Sql`${Sql.Field(f)} = EXCLUDED.${Sql.Field(f)}`);
|
|
882
884
|
}
|
|
883
885
|
} else {
|
|
884
886
|
conflictSql = Sql`ON CONFLICT`;
|
|
@@ -1650,6 +1652,37 @@ async function syncTables(env, query, tables, schema) {
|
|
|
1650
1652
|
}
|
|
1651
1653
|
}
|
|
1652
1654
|
|
|
1655
|
+
/** @import { DBColumn, Environment, FindArg, SelectItem } from 'imodel' */
|
|
1656
|
+
/**
|
|
1657
|
+
*
|
|
1658
|
+
* @param {Environment} env
|
|
1659
|
+
* @param {SelectItem[]} selectList
|
|
1660
|
+
* @returns {Sql}
|
|
1661
|
+
*/
|
|
1662
|
+
function buildSelect(env, selectList) {
|
|
1663
|
+
/** @type {Sql[]} */
|
|
1664
|
+
const list = [];
|
|
1665
|
+
for (const {
|
|
1666
|
+
table,
|
|
1667
|
+
columns,
|
|
1668
|
+
select,
|
|
1669
|
+
where,
|
|
1670
|
+
sort,
|
|
1671
|
+
offset,
|
|
1672
|
+
limit,
|
|
1673
|
+
group,
|
|
1674
|
+
having
|
|
1675
|
+
} of selectList) {
|
|
1676
|
+
const Table = Sql.Table(table);
|
|
1677
|
+
const selectSql = getSelect(Table, select);
|
|
1678
|
+
const orderSql = getOrder(sort);
|
|
1679
|
+
const limitSql = limit && limit > 0 ? Sql('LIMIT', limit) : undefined;
|
|
1680
|
+
const offsetSql = offset && offset > 0 ? Sql('OFFSET', offset) : undefined;
|
|
1681
|
+
list.push(Sql(Sql`SELECT ${selectSql} FROM ${Table}`, getWhere(env, where), orderSql, limitSql, offsetSql, group?.length ? Sql`GROUP BY ${Sql`,`.glue(group.map(v => Sql.Field(v)))}` : undefined, getWhere(env, having, 'HAVING')));
|
|
1682
|
+
}
|
|
1683
|
+
return list.length === 1 && list[0] || Sql`UNION`.glue(list);
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1653
1686
|
/** @import { Environment, IConnection } from 'imodel' */
|
|
1654
1687
|
const {
|
|
1655
1688
|
types
|
|
@@ -1819,8 +1852,8 @@ function index (pool, version) {
|
|
|
1819
1852
|
return '';
|
|
1820
1853
|
}
|
|
1821
1854
|
},
|
|
1822
|
-
insert(env, table, columns, data, keys) {
|
|
1823
|
-
return query(env, insertSql(env, table, columns, data, keys));
|
|
1855
|
+
insert(env, table, columns, data, keys, ignore) {
|
|
1856
|
+
return query(env, insertSql(env, table, columns, data, keys, ignore));
|
|
1824
1857
|
},
|
|
1825
1858
|
upsert(env, table, columns, data, keys, conflict, conflictSet) {
|
|
1826
1859
|
return query(env, insertSql(env, table, columns, data, keys, conflict, conflictSet));
|
|
@@ -1828,6 +1861,9 @@ function index (pool, version) {
|
|
|
1828
1861
|
find(env, table, columns, argv) {
|
|
1829
1862
|
return query(env, selectSql(env, table, columns, argv));
|
|
1830
1863
|
},
|
|
1864
|
+
select(env, select) {
|
|
1865
|
+
return query(env, buildSelect(env, select));
|
|
1866
|
+
},
|
|
1831
1867
|
count(env, table, columns, where) {
|
|
1832
1868
|
return query(env, countSql(env, table, columns, where)).then(r => r[0]?.count || 0);
|
|
1833
1869
|
},
|