File tree Expand file tree Collapse file tree 3 files changed +20
-35
lines changed Expand file tree Collapse file tree 3 files changed +20
-35
lines changed Original file line number Diff line number Diff line change 1
1
import { dbToTypes , defaultTypes } from "../../data/datatypes" ;
2
- import { parseDefault } from "./shared" ;
2
+ import { getInlineFK , parseDefault } from "./shared" ;
3
3
4
4
export function getJsonType ( f ) {
5
5
if ( ! Object . keys ( defaultTypes ) . includes ( f . type ) ) {
@@ -325,21 +325,6 @@ export function getSQLiteType(field) {
325
325
}
326
326
}
327
327
328
- export function getInlineFK ( table , obj ) {
329
- let fk = "" ;
330
- obj . references . forEach ( ( r ) => {
331
- if ( fk !== "" ) return ;
332
- if ( r . startTableId === table . id ) {
333
- fk = `FOREIGN KEY ("${ table . fields [ r . startFieldId ] . name } ") REFERENCES "${
334
- obj . tables [ r . endTableId ] . name
335
- } "("${
336
- obj . tables [ r . endTableId ] . fields [ r . endFieldId ] . name
337
- } ")\n\tON UPDATE ${ r . updateConstraint . toUpperCase ( ) } ON DELETE ${ r . deleteConstraint . toUpperCase ( ) } `;
338
- }
339
- } ) ;
340
- return fk ;
341
- }
342
-
343
328
export function jsonToSQLite ( obj ) {
344
329
return obj . tables
345
330
. map ( ( table ) => {
@@ -367,7 +352,7 @@ export function jsonToSQLite(obj) {
367
352
. map ( ( f ) => `"${ f . name } "` )
368
353
. join ( ", " ) } )${ inlineFK !== "" ? ",\n" : "" } `
369
354
: ""
370
- } \t ${ inlineFK } \n);\n${ table . indices
355
+ } ${ inlineFK } \n);\n${ table . indices
371
356
. map (
372
357
( i ) =>
373
358
`\nCREATE ${ i . unique ? "UNIQUE " : "" } INDEX IF NOT EXISTS "${
Original file line number Diff line number Diff line change @@ -26,3 +26,19 @@ export function exportFieldComment(comment) {
26
26
. map ( ( commentLine ) => `\t-- ${ commentLine } \n` )
27
27
. join ( "" ) ;
28
28
}
29
+
30
+ export function getInlineFK ( table , obj ) {
31
+ let fks = [ ] ;
32
+ obj . references . forEach ( ( r ) => {
33
+ if ( r . startTableId === table . id ) {
34
+ fks . push (
35
+ `\tFOREIGN KEY ("${ table . fields [ r . startFieldId ] . name } ") REFERENCES "${
36
+ obj . tables [ r . endTableId ] . name
37
+ } "("${
38
+ obj . tables [ r . endTableId ] . fields [ r . endFieldId ] . name
39
+ } ")\n\tON UPDATE ${ r . updateConstraint . toUpperCase ( ) } ON DELETE ${ r . deleteConstraint . toUpperCase ( ) } `,
40
+ ) ;
41
+ }
42
+ } ) ;
43
+ return fks . join ( ",\n" ) ;
44
+ }
Original file line number Diff line number Diff line change 1
- import { exportFieldComment , parseDefault } from "./shared" ;
1
+ import { exportFieldComment , getInlineFK , parseDefault } from "./shared" ;
2
2
3
3
import { dbToTypes } from "../../data/datatypes" ;
4
4
@@ -41,20 +41,4 @@ export function toSqlite(diagram) {
41
41
. join ( "\n" ) } `;
42
42
} )
43
43
. join ( "\n" ) ;
44
- }
45
-
46
- export function getInlineFK ( table , obj ) {
47
- let fks = [ ] ;
48
- obj . references . forEach ( ( r ) => {
49
- if ( r . startTableId === table . id ) {
50
- fks . push (
51
- `\tFOREIGN KEY ("${ table . fields [ r . startFieldId ] . name } ") REFERENCES "${
52
- obj . tables [ r . endTableId ] . name
53
- } "("${
54
- obj . tables [ r . endTableId ] . fields [ r . endFieldId ] . name
55
- } ")\n\tON UPDATE ${ r . updateConstraint . toUpperCase ( ) } ON DELETE ${ r . deleteConstraint . toUpperCase ( ) } `,
56
- ) ;
57
- }
58
- } ) ;
59
- return fks . join ( ",\n" ) ;
60
- }
44
+ }
You can’t perform that action at this time.
0 commit comments