postgresdk 0.9.8 → 0.9.9
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/cli.js +39 -9
- package/dist/core/operations.d.ts +1 -0
- package/dist/index.js +39 -9
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -2423,6 +2423,7 @@ import * as coreOps from "../core/operations${ext}";
|
|
|
2423
2423
|
${authImport}
|
|
2424
2424
|
|
|
2425
2425
|
const listSchema = z.object({
|
|
2426
|
+
where: z.any().optional(),
|
|
2426
2427
|
include: z.any().optional(),
|
|
2427
2428
|
limit: z.number().int().positive().max(100).optional(),
|
|
2428
2429
|
offset: z.number().int().min(0).optional(),
|
|
@@ -3652,19 +3653,48 @@ export async function getByPk(
|
|
|
3652
3653
|
*/
|
|
3653
3654
|
export async function listRecords(
|
|
3654
3655
|
ctx: OperationContext,
|
|
3655
|
-
params: { limit?: number; offset?: number; include?: any }
|
|
3656
|
-
): Promise<{ data?: any; error?: string; issues?: any;
|
|
3656
|
+
params: { where?: any; limit?: number; offset?: number; include?: any }
|
|
3657
|
+
): Promise<{ data?: any; error?: string; issues?: any; needsIncludes?: boolean; includeSpec?: any; status: number }> {
|
|
3657
3658
|
try {
|
|
3658
|
-
const { limit = 50, offset = 0, include } = params;
|
|
3659
|
+
const { where: whereClause, limit = 50, offset = 0, include } = params;
|
|
3660
|
+
|
|
3661
|
+
// Build WHERE clause
|
|
3662
|
+
const whereParts: string[] = [];
|
|
3663
|
+
const whereParams: any[] = [];
|
|
3664
|
+
let paramIndex = 1;
|
|
3665
|
+
|
|
3666
|
+
// Add soft delete filter if applicable
|
|
3667
|
+
if (ctx.softDeleteColumn) {
|
|
3668
|
+
whereParts.push(\`"\${ctx.softDeleteColumn}" IS NULL\`);
|
|
3669
|
+
}
|
|
3670
|
+
|
|
3671
|
+
// Add user-provided where conditions
|
|
3672
|
+
if (whereClause && typeof whereClause === 'object') {
|
|
3673
|
+
for (const [key, value] of Object.entries(whereClause)) {
|
|
3674
|
+
if (value === null) {
|
|
3675
|
+
whereParts.push(\`"\${key}" IS NULL\`);
|
|
3676
|
+
} else if (value === undefined) {
|
|
3677
|
+
// Skip undefined values
|
|
3678
|
+
continue;
|
|
3679
|
+
} else {
|
|
3680
|
+
whereParts.push(\`"\${key}" = $\${paramIndex}\`);
|
|
3681
|
+
whereParams.push(value);
|
|
3682
|
+
paramIndex++;
|
|
3683
|
+
}
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3686
|
+
|
|
3687
|
+
const whereSQL = whereParts.length > 0 ? \`WHERE \${whereParts.join(" AND ")}\` : "";
|
|
3659
3688
|
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3689
|
+
// Add limit and offset params
|
|
3690
|
+
const limitParam = \`$\${paramIndex}\`;
|
|
3691
|
+
const offsetParam = \`$\${paramIndex + 1}\`;
|
|
3692
|
+
const allParams = [...whereParams, limit, offset];
|
|
3663
3693
|
|
|
3664
|
-
const text = \`SELECT * FROM "\${ctx.table}" \${
|
|
3665
|
-
log.debug(\`LIST \${ctx.table} SQL:\`, text, "params:",
|
|
3694
|
+
const text = \`SELECT * FROM "\${ctx.table}" \${whereSQL} LIMIT \${limitParam} OFFSET \${offsetParam}\`;
|
|
3695
|
+
log.debug(\`LIST \${ctx.table} SQL:\`, text, "params:", allParams);
|
|
3666
3696
|
|
|
3667
|
-
const { rows } = await ctx.pg.query(text,
|
|
3697
|
+
const { rows } = await ctx.pg.query(text, allParams);
|
|
3668
3698
|
|
|
3669
3699
|
if (!include) {
|
|
3670
3700
|
log.debug(\`LIST \${ctx.table} rows:\`, rows.length);
|
|
@@ -35,6 +35,7 @@ export declare function getByPk(ctx: OperationContext, pkValues: any[]): Promise
|
|
|
35
35
|
* LIST operation - Get multiple records with optional filters
|
|
36
36
|
*/
|
|
37
37
|
export declare function listRecords(ctx: OperationContext, params: {
|
|
38
|
+
where?: any;
|
|
38
39
|
limit?: number;
|
|
39
40
|
offset?: number;
|
|
40
41
|
include?: any;
|
package/dist/index.js
CHANGED
|
@@ -1679,6 +1679,7 @@ import * as coreOps from "../core/operations${ext}";
|
|
|
1679
1679
|
${authImport}
|
|
1680
1680
|
|
|
1681
1681
|
const listSchema = z.object({
|
|
1682
|
+
where: z.any().optional(),
|
|
1682
1683
|
include: z.any().optional(),
|
|
1683
1684
|
limit: z.number().int().positive().max(100).optional(),
|
|
1684
1685
|
offset: z.number().int().min(0).optional(),
|
|
@@ -2908,19 +2909,48 @@ export async function getByPk(
|
|
|
2908
2909
|
*/
|
|
2909
2910
|
export async function listRecords(
|
|
2910
2911
|
ctx: OperationContext,
|
|
2911
|
-
params: { limit?: number; offset?: number; include?: any }
|
|
2912
|
-
): Promise<{ data?: any; error?: string; issues?: any;
|
|
2912
|
+
params: { where?: any; limit?: number; offset?: number; include?: any }
|
|
2913
|
+
): Promise<{ data?: any; error?: string; issues?: any; needsIncludes?: boolean; includeSpec?: any; status: number }> {
|
|
2913
2914
|
try {
|
|
2914
|
-
const { limit = 50, offset = 0, include } = params;
|
|
2915
|
+
const { where: whereClause, limit = 50, offset = 0, include } = params;
|
|
2916
|
+
|
|
2917
|
+
// Build WHERE clause
|
|
2918
|
+
const whereParts: string[] = [];
|
|
2919
|
+
const whereParams: any[] = [];
|
|
2920
|
+
let paramIndex = 1;
|
|
2921
|
+
|
|
2922
|
+
// Add soft delete filter if applicable
|
|
2923
|
+
if (ctx.softDeleteColumn) {
|
|
2924
|
+
whereParts.push(\`"\${ctx.softDeleteColumn}" IS NULL\`);
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2927
|
+
// Add user-provided where conditions
|
|
2928
|
+
if (whereClause && typeof whereClause === 'object') {
|
|
2929
|
+
for (const [key, value] of Object.entries(whereClause)) {
|
|
2930
|
+
if (value === null) {
|
|
2931
|
+
whereParts.push(\`"\${key}" IS NULL\`);
|
|
2932
|
+
} else if (value === undefined) {
|
|
2933
|
+
// Skip undefined values
|
|
2934
|
+
continue;
|
|
2935
|
+
} else {
|
|
2936
|
+
whereParts.push(\`"\${key}" = $\${paramIndex}\`);
|
|
2937
|
+
whereParams.push(value);
|
|
2938
|
+
paramIndex++;
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
}
|
|
2942
|
+
|
|
2943
|
+
const whereSQL = whereParts.length > 0 ? \`WHERE \${whereParts.join(" AND ")}\` : "";
|
|
2915
2944
|
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2945
|
+
// Add limit and offset params
|
|
2946
|
+
const limitParam = \`$\${paramIndex}\`;
|
|
2947
|
+
const offsetParam = \`$\${paramIndex + 1}\`;
|
|
2948
|
+
const allParams = [...whereParams, limit, offset];
|
|
2919
2949
|
|
|
2920
|
-
const text = \`SELECT * FROM "\${ctx.table}" \${
|
|
2921
|
-
log.debug(\`LIST \${ctx.table} SQL:\`, text, "params:",
|
|
2950
|
+
const text = \`SELECT * FROM "\${ctx.table}" \${whereSQL} LIMIT \${limitParam} OFFSET \${offsetParam}\`;
|
|
2951
|
+
log.debug(\`LIST \${ctx.table} SQL:\`, text, "params:", allParams);
|
|
2922
2952
|
|
|
2923
|
-
const { rows } = await ctx.pg.query(text,
|
|
2953
|
+
const { rows } = await ctx.pg.query(text, allParams);
|
|
2924
2954
|
|
|
2925
2955
|
if (!include) {
|
|
2926
2956
|
log.debug(\`LIST \${ctx.table} rows:\`, rows.length);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postgresdk",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.9",
|
|
4
4
|
"description": "Generate a typed server/client SDK from a Postgres schema (includes, Zod, Hono).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
24
|
"build": "bun build src/cli.ts src/index.ts --outdir dist --target node --format esm --external=pg --external=zod --external=hono --external=prompts --external=node:* && tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
25
|
-
"test": "bun test:init && bun test:gen && bun test:gen-with-tests && bun test:pull && bun test:typecheck && bun test:drizzle-e2e",
|
|
25
|
+
"test": "bun test:init && bun test:gen && bun test test/test-where-clause.test.ts && bun test:gen-with-tests && bun test:pull && bun test:typecheck && bun test:drizzle-e2e",
|
|
26
26
|
"test:init": "bun test/test-init.ts",
|
|
27
27
|
"test:gen": "bun test/test-gen.ts",
|
|
28
28
|
"test:gen-with-tests": "bun test/test-gen-with-tests.ts",
|