@balena/abstract-sql-compiler
Advanced tools
Comparing version 7.0.7 to 7.1.0-add-check-constraint-support-2ac556f3bdc6143a9a4be37c47079659ee20a866
@@ -7,2 +7,6 @@ # Change Log | ||
## 7.1.0 - 2020-12-09 | ||
* Add check constraint support at the table level [Pagan Gazzard] | ||
## 7.0.7 - 2020-12-09 | ||
@@ -9,0 +13,0 @@ |
@@ -138,2 +138,7 @@ export declare const enum Engines { | ||
} | ||
export interface Check { | ||
description?: string; | ||
name?: string; | ||
abstractSql: BooleanTypeNodes; | ||
} | ||
export interface AbstractSqlTable { | ||
@@ -150,2 +155,3 @@ name: string; | ||
triggers?: Trigger[]; | ||
checks?: Check[]; | ||
} | ||
@@ -152,0 +158,0 @@ export interface ReferencedFields { |
@@ -271,2 +271,13 @@ "use strict"; | ||
} | ||
if (table.checks) { | ||
for (const check of table.checks) { | ||
const comment = check.description | ||
? `-- ${check.description.split(/\r?\n/).join('\n-- ')}\n` | ||
: ''; | ||
const constraintName = check.name ? `CONSTRAINT "${check.name}" ` : ''; | ||
const sql = compileRule(check.abstractSql, engine, true); | ||
createSqlElements.push(`\ | ||
${comment}${constraintName}CHECK (${sql})`); | ||
} | ||
} | ||
const createTriggers = []; | ||
@@ -273,0 +284,0 @@ const dropTriggers = []; |
{ | ||
"name": "@balena/abstract-sql-compiler", | ||
"version": "7.0.7", | ||
"version": "7.1.0-add-check-constraint-support-2ac556f3bdc6143a9a4be37c47079659ee20a866", | ||
"description": "A translator for abstract sql into sql.", | ||
@@ -5,0 +5,0 @@ "main": "out/AbstractSQLCompiler.js", |
@@ -226,2 +226,7 @@ export const enum Engines { | ||
} | ||
export interface Check { | ||
description?: string; | ||
name?: string; | ||
abstractSql: BooleanTypeNodes; | ||
} | ||
export interface AbstractSqlTable { | ||
@@ -238,2 +243,3 @@ name: string; | ||
triggers?: Trigger[]; | ||
checks?: Check[]; | ||
} | ||
@@ -652,2 +658,18 @@ export interface ReferencedFields { | ||
if (table.checks) { | ||
for (const check of table.checks) { | ||
const comment = check.description | ||
? `-- ${check.description.split(/\r?\n/).join('\n-- ')}\n` | ||
: ''; | ||
const constraintName = check.name ? `CONSTRAINT "${check.name}" ` : ''; | ||
const sql = compileRule( | ||
check.abstractSql as AbstractSqlQuery, | ||
engine, | ||
true, | ||
); | ||
createSqlElements.push(`\ | ||
${comment}${constraintName}CHECK (${sql})`); | ||
} | ||
} | ||
const createTriggers: string[] = []; | ||
@@ -654,0 +676,0 @@ const dropTriggers: string[] = []; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
532726
44
11621
2