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