(col: DatabaseTableColumn)
| 12 | } |
| 13 | |
| 14 | function generateCreateColumn(col: DatabaseTableColumn): string { |
| 15 | const tokens: string[] = [escapeIdentity(col.name), col.type]; |
| 16 | |
| 17 | if (col.constraint?.primaryKey) { |
| 18 | tokens.push( |
| 19 | [ |
| 20 | "PRIMARY KEY", |
| 21 | col.constraint.primaryKeyOrder, |
| 22 | col.constraint.primaryKeyConflict |
| 23 | ? `ON CONFLICT ${col.constraint.primaryKeyConflict}` |
| 24 | : undefined, |
| 25 | col.constraint.autoIncrement ? "AUTOINCREMENT" : undefined, |
| 26 | ] |
| 27 | .filter(Boolean) |
| 28 | .join(" ") |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | if (col.constraint?.unique) { |
| 33 | tokens.push( |
| 34 | [ |
| 35 | "UNIQUE", |
| 36 | col.constraint.uniqueConflict |
| 37 | ? `ON CONFLICT ${col.constraint.uniqueConflict}` |
| 38 | : undefined, |
| 39 | ] |
| 40 | .filter(Boolean) |
| 41 | .join(" ") |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | if (col.constraint?.notNull) { |
| 46 | tokens.push( |
| 47 | [ |
| 48 | "NOT NULL", |
| 49 | col.constraint.notNullConflict |
| 50 | ? `ON CONFLICT ${col.constraint.notNullConflict}` |
| 51 | : undefined, |
| 52 | ] |
| 53 | .filter(Boolean) |
| 54 | .join(" ") |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | if (col.constraint?.defaultValue) { |
| 59 | tokens.push( |
| 60 | ["DEFAULT", escapeSqlValue(col.constraint.defaultValue)].join(" ") |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | if (col.constraint?.defaultExpression) { |
| 65 | tokens.push( |
| 66 | ["DEFAULT", wrapParen(col.constraint.defaultExpression)].join(" ") |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | if (col.constraint?.generatedExpression) { |
| 71 | tokens.push( |
no test coverage detected