@ronin/compiler
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -162,4 +162,3 @@ // src/utils/index.ts | ||
name: "RONIN - Created By", | ||
type: "reference", | ||
target: "account", | ||
type: "string", | ||
slug: "ronin.createdBy" | ||
@@ -174,4 +173,3 @@ }, | ||
name: "RONIN - Updated By", | ||
type: "reference", | ||
target: "account", | ||
type: "string", | ||
slug: "ronin.updatedBy" | ||
@@ -208,8 +206,13 @@ } | ||
{ slug: "type", type: "string", required: true }, | ||
{ slug: "schema", type: "reference", target: "schema" }, | ||
{ slug: "target", type: "reference", target: "schema" }, | ||
{ slug: "schema", type: "reference", target: { pluralSlug: "schemas" } }, | ||
{ slug: "required", type: "boolean" }, | ||
{ slug: "defaultValue", type: "string" }, | ||
{ slug: "unique", type: "boolean" }, | ||
{ slug: "autoIncrement", type: "boolean" } | ||
{ slug: "autoIncrement", type: "boolean" }, | ||
// Only allowed for fields of type "reference". | ||
{ slug: "target", type: "reference", target: { pluralSlug: "schemas" } }, | ||
{ slug: "kind", type: "string" }, | ||
{ slug: "actions", type: "group" }, | ||
{ slug: "actions.onDelete", type: "string" }, | ||
{ slug: "actions.onUpdate", type: "string" } | ||
] | ||
@@ -224,3 +227,3 @@ } | ||
if (field.type === "reference" && !field.slug.startsWith("ronin.")) { | ||
const relatedSchema = getSchemaBySlug(list, field.target); | ||
const relatedSchema = getSchemaBySlug(list, field.target.pluralSlug); | ||
let fieldSlug = relatedSchema.slug; | ||
@@ -236,3 +239,3 @@ if (field.kind === "many") { | ||
type: "reference", | ||
target: schema.slug | ||
target: schema | ||
}, | ||
@@ -242,3 +245,3 @@ { | ||
type: "reference", | ||
target: relatedSchema.slug | ||
target: relatedSchema | ||
} | ||
@@ -259,3 +262,3 @@ ] | ||
}; | ||
const relatedSchemaToModify = list.find((schema2) => schema2.slug === field.target); | ||
const relatedSchemaToModify = getSchemaBySlug(list, field.target.pluralSlug); | ||
if (!relatedSchemaToModify) throw new Error("Missing related schema"); | ||
@@ -303,2 +306,12 @@ relatedSchemaToModify.including = { | ||
statement += ` DEFAULT ${field.defaultValue}`; | ||
if (field.type === "reference") { | ||
const actions = field.actions || {}; | ||
const targetTable = convertToSnakeCase(field.target.pluralSlug); | ||
statement += ` REFERENCES ${targetTable}("id")`; | ||
for (const trigger in actions) { | ||
const triggerName = trigger.toUpperCase().slice(2); | ||
const action = actions[trigger]; | ||
statement += ` ON ${triggerName} ${action}`; | ||
} | ||
} | ||
return statement; | ||
@@ -507,3 +520,3 @@ }; | ||
} else { | ||
const relatedSchema = getSchemaBySlug(schemas, schemaField.target); | ||
const relatedSchema = getSchemaBySlug(schemas, schemaField.target.pluralSlug); | ||
const subQuery = { | ||
@@ -510,0 +523,0 @@ get: { |
{ | ||
"name": "@ronin/compiler", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "description": "Compiles RONIN queries to SQL statements.", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
346939
5791