@compas/code-gen
Advanced tools
Comparing version
{ | ||
"name": "@compas/code-gen", | ||
"version": "0.0.156", | ||
"version": "0.0.157", | ||
"description": "Generate various boring parts of your server", | ||
@@ -18,4 +18,4 @@ "main": "./index.js", | ||
"dependencies": { | ||
"@compas/cli": "0.0.156", | ||
"@compas/stdlib": "0.0.156" | ||
"@compas/cli": "0.0.157", | ||
"@compas/stdlib": "0.0.157" | ||
}, | ||
@@ -22,0 +22,0 @@ "maintainers": [ |
@@ -74,7 +74,9 @@ import { merge } from "@compas/stdlib"; | ||
/** | ||
* @param {object} [options={}] | ||
* @param {boolean} [options.withSoftDeletes] | ||
* @param {boolean} [options.withDates] | ||
* @param {boolean} [options.withPrimaryKey=true] | ||
* @param {boolean} [options.isView] | ||
* @param {{ | ||
* withSoftDeletes?: boolean, | ||
* withDates?: boolean, | ||
* withPrimaryKey?: boolean, | ||
* isView?: boolean, | ||
* schema?: string | ||
* }} [options = {}] | ||
* @returns {ObjectType} | ||
@@ -81,0 +83,0 @@ */ |
@@ -43,3 +43,3 @@ // Generated by @compas/code-gen | ||
/** | ||
* @typedef {{"type": "object", "docString": string, "isOptional": boolean, "defaultValue"?: undefined|string|boolean|number, "uniqueName"?: undefined|string, "group"?: undefined|string, "name"?: undefined|string, "sql"?: undefined|{"primary": boolean, "searchable": boolean, }, "validator": {"allowNull": boolean, "strict": boolean, }, "internalSettings": {}, "shortName"?: undefined|string, "keys": Object<string, CodeGenType>, "enableQueries": boolean, "queryOptions"?: undefined|{"withSoftDeletes": boolean, "withDates": boolean, "withPrimaryKey": boolean, "isView": boolean, }, "relations": (CodeGenRelationType)[], "where"?: undefined|{"type": string, "fields": ({"key": string, "name": string, "isRelation": boolean, "variant": "equal"|"notEqual"|"in"|"notIn"|"greaterThan"|"lowerThan"|"isNull"|"isNotNull"|"includeNotNull"|"like"|"iLike"|"notLike"|"exists"|"notExists", })[], }, "orderBy"?: undefined|{"type": string, "specType": string, "fields": ({"key": string, "optional": boolean, })[], }, "partial"?: undefined|{"insertType": string, "updateType": string, "fields": ({"key": string, "defaultValue"?: undefined|string, "isJsonb": boolean, })[], }, }} CodeGenObjectType | ||
* @typedef {{"type": "object", "docString": string, "isOptional": boolean, "defaultValue"?: undefined|string|boolean|number, "uniqueName"?: undefined|string, "group"?: undefined|string, "name"?: undefined|string, "sql"?: undefined|{"primary": boolean, "searchable": boolean, }, "validator": {"allowNull": boolean, "strict": boolean, }, "internalSettings": {}, "shortName"?: undefined|string, "keys": Object<string, CodeGenType>, "enableQueries": boolean, "queryOptions"?: undefined|{"withSoftDeletes": boolean, "withDates": boolean, "withPrimaryKey": boolean, "isView": boolean, "schema": string, }, "relations": (CodeGenRelationType)[], "where"?: undefined|{"type": string, "fields": ({"key": string, "name": string, "isRelation": boolean, "variant": "equal"|"notEqual"|"in"|"notIn"|"greaterThan"|"lowerThan"|"isNull"|"isNotNull"|"includeNotNull"|"like"|"iLike"|"notLike"|"exists"|"notExists", })[], }, "orderBy"?: undefined|{"type": string, "specType": string, "fields": ({"key": string, "optional": boolean, })[], }, "partial"?: undefined|{"insertType": string, "updateType": string, "fields": ({"key": string, "defaultValue"?: undefined|string, "isJsonb": boolean, })[], }, }} CodeGenObjectType | ||
*/ | ||
@@ -46,0 +46,0 @@ /** |
@@ -63,3 +63,3 @@ import { upperCaseFirst } from "../../utils.js"; | ||
SELECT COUNT(${type.shortName}."${primaryKey}") as "countResult" | ||
FROM "${type.name}" ${type.shortName} | ||
FROM ${type.queryOptions.schema}"${type.name}" ${type.shortName} | ||
WHERE $\{${type.name}Where(where)} | ||
@@ -96,3 +96,3 @@ \`.exec(sql); | ||
return await query\` | ||
DELETE FROM "${type.name}" ${type.shortName} | ||
DELETE FROM ${type.queryOptions.schema}"${type.name}" ${type.shortName} | ||
WHERE $\{${type.name}Where(where)} | ||
@@ -137,3 +137,3 @@ \`.exec(sql); | ||
await query\` | ||
UPDATE "${type.name}" ${type.shortName} | ||
UPDATE ${type.queryOptions.schema}"${type.name}" ${type.shortName} | ||
SET "deletedAt" = now() | ||
@@ -197,3 +197,5 @@ WHERE $\{${type.name}Where(where)} | ||
const result = await query\` | ||
INSERT INTO "${type.name}" ($\{${type.name}Fields( | ||
INSERT INTO ${type.queryOptions.schema}"${type.name}" ($\{${ | ||
type.name | ||
}Fields( | ||
"", { excludePrimaryKey: !options.withPrimaryKey })}) | ||
@@ -241,3 +243,5 @@ VALUES $\{${type.name}InsertValues( | ||
const result = await query\` | ||
INSERT INTO "${type.name}" ($\{${type.name}Fields( | ||
INSERT INTO ${type.queryOptions.schema}"${type.name}" ($\{${ | ||
type.name | ||
}Fields( | ||
"", { excludePrimaryKey: false })}) | ||
@@ -272,3 +276,3 @@ VALUES $\{${type.name}InsertValues( | ||
const result = await query\` | ||
UPDATE "${type.name}" ${type.shortName} | ||
UPDATE ${type.queryOptions.schema}"${type.name}" ${type.shortName} | ||
SET $\{${type.name}UpdateSet(update)} | ||
@@ -275,0 +279,0 @@ WHERE $\{${type.name}Where(where)} |
@@ -492,3 +492,3 @@ import { isNil } from "@compas/stdlib"; | ||
return query\` | ||
FROM "${type.name}" ${shortName} | ||
FROM ${type.queryOptions.schema}"${type.name}" ${shortName} | ||
$\{joinQb} | ||
@@ -495,0 +495,0 @@ WHERE $\{${type.name}Where( |
@@ -30,2 +30,10 @@ import { isNil } from "@compas/stdlib"; | ||
} | ||
// Also format schema if specified | ||
type.queryOptions.schema = type.queryOptions.schema ?? ""; | ||
if (type.queryOptions.schema.length > 0) { | ||
if (!type.queryOptions.schema.startsWith(`"`)) { | ||
type.queryOptions.schema = `"${type.queryOptions.schema}".`; | ||
} | ||
} | ||
} | ||
@@ -32,0 +40,0 @@ } |
Sorry, the diff of this file is too big to display
426580
0.32%13783
0.39%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
Updated
Updated