@graffy/pg 0.16.3-alpha.4 → 0.16.3-alpha.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/index.cjs +5 -25
- package/index.mjs +5 -25
- package/package.json +2 -2
- package/types/sql/getArgSql.d.ts +1 -2
package/index.cjs
CHANGED
|
@@ -442,12 +442,7 @@ function getArgSql({ $first, $last, $after, $before, $since, $until, $all, $curs
|
|
|
442
442
|
if (!common.isEmpty(filter))
|
|
443
443
|
where.push(getSql(filter, options));
|
|
444
444
|
if (!hasRangeArg)
|
|
445
|
-
return {
|
|
446
|
-
meta: meta(baseKey),
|
|
447
|
-
where,
|
|
448
|
-
limit: 1,
|
|
449
|
-
ensureSingleRow: $group === true
|
|
450
|
-
};
|
|
445
|
+
return { meta: meta(baseKey), where, limit: 1 };
|
|
451
446
|
const groupCols = Array.isArray($group) && $group.length && $group.map((prop) => lookup(prop, options));
|
|
452
447
|
const group = groupCols ? join(groupCols, ", ") : void 0;
|
|
453
448
|
const orderCols = ($order || [idCol]).map(
|
|
@@ -474,8 +469,7 @@ function getArgSql({ $first, $last, $after, $before, $since, $until, $all, $curs
|
|
|
474
469
|
where,
|
|
475
470
|
order,
|
|
476
471
|
group,
|
|
477
|
-
limit: $first || $last
|
|
478
|
-
ensureSingleRow: true
|
|
472
|
+
limit: $first || $last
|
|
479
473
|
};
|
|
480
474
|
}
|
|
481
475
|
function getBoundCond(orderCols, bound, kind) {
|
|
@@ -509,23 +503,9 @@ function getBoundCond(orderCols, bound, kind) {
|
|
|
509
503
|
}
|
|
510
504
|
const MAX_LIMIT = 4096;
|
|
511
505
|
function selectByArgs(args, projection, options) {
|
|
512
|
-
const { table
|
|
513
|
-
const { where, order, group, limit, meta
|
|
514
|
-
args,
|
|
515
|
-
options
|
|
516
|
-
);
|
|
506
|
+
const { table } = options;
|
|
507
|
+
const { where, order, group, limit, meta } = getArgSql(args, options);
|
|
517
508
|
const clampedLimit = Math.min(MAX_LIMIT, limit || MAX_LIMIT);
|
|
518
|
-
if (!ensureSingleRow) {
|
|
519
|
-
return sql`
|
|
520
|
-
SELECT
|
|
521
|
-
${getSelectCols(options, projection)}, ${meta}
|
|
522
|
-
FROM "${raw(table)}" WHERE "${raw(idCol)}" = (
|
|
523
|
-
SELECT "${raw(idCol)}" FROM "${raw(table)}"
|
|
524
|
-
${where.length ? sql`WHERE ${join(where, " AND ")}` : empty}
|
|
525
|
-
LIMIT 2
|
|
526
|
-
)
|
|
527
|
-
`;
|
|
528
|
-
}
|
|
529
509
|
return sql`
|
|
530
510
|
SELECT
|
|
531
511
|
${getSelectCols(options, projection)}, ${meta}
|
|
@@ -561,7 +541,7 @@ function getSingleSql(arg, options) {
|
|
|
561
541
|
SELECT "${raw(idCol)}"
|
|
562
542
|
FROM "${raw(table)}"
|
|
563
543
|
WHERE ${join(where, " AND ")}
|
|
564
|
-
LIMIT
|
|
544
|
+
LIMIT 1
|
|
565
545
|
)`,
|
|
566
546
|
meta
|
|
567
547
|
};
|
package/index.mjs
CHANGED
|
@@ -440,12 +440,7 @@ function getArgSql({ $first, $last, $after, $before, $since, $until, $all, $curs
|
|
|
440
440
|
if (!isEmpty(filter))
|
|
441
441
|
where.push(getSql(filter, options));
|
|
442
442
|
if (!hasRangeArg)
|
|
443
|
-
return {
|
|
444
|
-
meta: meta(baseKey),
|
|
445
|
-
where,
|
|
446
|
-
limit: 1,
|
|
447
|
-
ensureSingleRow: $group === true
|
|
448
|
-
};
|
|
443
|
+
return { meta: meta(baseKey), where, limit: 1 };
|
|
449
444
|
const groupCols = Array.isArray($group) && $group.length && $group.map((prop) => lookup(prop, options));
|
|
450
445
|
const group = groupCols ? join(groupCols, ", ") : void 0;
|
|
451
446
|
const orderCols = ($order || [idCol]).map(
|
|
@@ -472,8 +467,7 @@ function getArgSql({ $first, $last, $after, $before, $since, $until, $all, $curs
|
|
|
472
467
|
where,
|
|
473
468
|
order,
|
|
474
469
|
group,
|
|
475
|
-
limit: $first || $last
|
|
476
|
-
ensureSingleRow: true
|
|
470
|
+
limit: $first || $last
|
|
477
471
|
};
|
|
478
472
|
}
|
|
479
473
|
function getBoundCond(orderCols, bound, kind) {
|
|
@@ -507,23 +501,9 @@ function getBoundCond(orderCols, bound, kind) {
|
|
|
507
501
|
}
|
|
508
502
|
const MAX_LIMIT = 4096;
|
|
509
503
|
function selectByArgs(args, projection, options) {
|
|
510
|
-
const { table
|
|
511
|
-
const { where, order, group, limit, meta
|
|
512
|
-
args,
|
|
513
|
-
options
|
|
514
|
-
);
|
|
504
|
+
const { table } = options;
|
|
505
|
+
const { where, order, group, limit, meta } = getArgSql(args, options);
|
|
515
506
|
const clampedLimit = Math.min(MAX_LIMIT, limit || MAX_LIMIT);
|
|
516
|
-
if (!ensureSingleRow) {
|
|
517
|
-
return sql`
|
|
518
|
-
SELECT
|
|
519
|
-
${getSelectCols(options, projection)}, ${meta}
|
|
520
|
-
FROM "${raw(table)}" WHERE "${raw(idCol)}" = (
|
|
521
|
-
SELECT "${raw(idCol)}" FROM "${raw(table)}"
|
|
522
|
-
${where.length ? sql`WHERE ${join(where, " AND ")}` : empty}
|
|
523
|
-
LIMIT 2
|
|
524
|
-
)
|
|
525
|
-
`;
|
|
526
|
-
}
|
|
527
507
|
return sql`
|
|
528
508
|
SELECT
|
|
529
509
|
${getSelectCols(options, projection)}, ${meta}
|
|
@@ -559,7 +539,7 @@ function getSingleSql(arg, options) {
|
|
|
559
539
|
SELECT "${raw(idCol)}"
|
|
560
540
|
FROM "${raw(table)}"
|
|
561
541
|
WHERE ${join(where, " AND ")}
|
|
562
|
-
LIMIT
|
|
542
|
+
LIMIT 1
|
|
563
543
|
)`,
|
|
564
544
|
meta
|
|
565
545
|
};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graffy/pg",
|
|
3
3
|
"description": "The standard Postgres module for Graffy. Each instance this module mounts a Postgres table as a Graffy subtree.",
|
|
4
4
|
"author": "aravind (https://github.com/aravindet)",
|
|
5
|
-
"version": "0.16.3-alpha.
|
|
5
|
+
"version": "0.16.3-alpha.6",
|
|
6
6
|
"main": "./index.cjs",
|
|
7
7
|
"exports": {
|
|
8
8
|
"import": "./index.mjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"license": "Apache-2.0",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@graffy/common": "0.16.3-alpha.
|
|
19
|
+
"@graffy/common": "0.16.3-alpha.6",
|
|
20
20
|
"debug": "^4.3.3"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
package/types/sql/getArgSql.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
@param {{prefix: string, idCol: string, verDefault: string}} options
|
|
6
6
|
|
|
7
7
|
@typedef { import('sql-template-tag').Sql } Sql
|
|
8
|
-
@return {{ meta: Sql, where: Sql[], order?: Sql, group?: Sql, limit: number
|
|
8
|
+
@return {{ meta: Sql, where: Sql[], order?: Sql, group?: Sql, limit: number }}
|
|
9
9
|
*/
|
|
10
10
|
export default function getArgSql({ $first, $last, $after, $before, $since, $until, $all, $cursor: _, ...rest }: object, options: {
|
|
11
11
|
prefix: string;
|
|
@@ -17,7 +17,6 @@ export default function getArgSql({ $first, $last, $after, $before, $since, $unt
|
|
|
17
17
|
order?: Sql;
|
|
18
18
|
group?: Sql;
|
|
19
19
|
limit: number;
|
|
20
|
-
ensureSingleRow: boolean;
|
|
21
20
|
};
|
|
22
21
|
/**
|
|
23
22
|
* Uses the args object (typically passed in the $key attribute)
|