@@ -6,33 +6,49 @@ The `createTable` and `addColumns` methods both take a `columns` argument that s
66It is an object (key/value) where each key is the name of the column,
77and the value is another object that defines the options for the column.
88
9- | Option | Type | Description |
10- | ----------------------------- | ------------------------------------- | -------------------------------------------------------------------------------------------- |
11- | ` type ` | ` string ` | Data type (use normal postgres types) |
12- | ` collation ` | ` string ` | Collation of data type |
13- | ` unique ` | ` boolean ` | Set to true to add a unique constraint on this column |
14- | ` primaryKey ` | ` boolean ` | Set to true to make this column the primary key |
15- | ` notNull ` | ` boolean ` | Set to true to make this column not null |
16- | ` default ` | ` string ` | Adds DEFAULT clause for column. Accepts null, a literal value, or a ` pgm.func() ` expression. |
17- | ` check ` | ` string ` | SQL for a check constraint for this column |
18- | ` references ` | [ Name] ( /migrations/#type ) or ` string ` | A table name that this column is a foreign key to |
19- | ` referencesConstraintName ` | ` string ` | Name of the created constraint |
20- | ` referencesConstraintComment ` | ` string ` | Comment on the created constraint |
21- | ` onDelete ` | ` string ` | Adds ON DELETE constraint for a reference column |
22- | ` onUpdate ` | ` string ` | Adds ON UPDATE constraint for a reference column |
23- | ` match ` | ` string ` | ` FULL ` or ` SIMPLE ` |
24- | ` deferrable ` | ` boolean ` | Flag for deferrable column constraint |
25- | ` deferred ` | ` boolean ` | Flag for initially deferred deferrable column constraint |
26- | ` comment ` | ` string ` | Adds comment on column |
27- | ` expressionGenerated ` | ` string ` | Expression to compute column value |
28- | ` sequenceGenerated ` | ` object ` | Creates identity column see [ sequence options section] ( sequences.md#sequence-options ) |
29- | ` precedence ` | ` string ` | ` ALWAYS ` or ` BY DEFAULT ` |
9+ | Option | Type | Description |
10+ | ----------------------------- | ------------------------------------- | ------------------------------------------------------------------------------------------------- |
11+ | ` type ` | ` string ` | Data type (use normal postgres types) |
12+ | ` array ` | ` boolean ` or ` number ` | Defines the column as a PostgreSQL array type. Use ` true ` for ` ARRAY ` or a number for ` ARRAY[n] ` . |
13+ | ` collation ` | ` string ` | Collation of data type |
14+ | ` unique ` | ` boolean ` | Set to true to add a unique constraint on this column |
15+ | ` primaryKey ` | ` boolean ` | Set to true to make this column the primary key |
16+ | ` notNull ` | ` boolean ` | Set to true to make this column not null |
17+ | ` default ` | ` string ` | Adds DEFAULT clause for column. Accepts null, a literal value, or a ` pgm.func() ` expression. |
18+ | ` check ` | ` string ` | SQL for a check constraint for this column |
19+ | ` references ` | [ Name] ( /migrations/#type ) or ` string ` | A table name that this column is a foreign key to |
20+ | ` referencesConstraintName ` | ` string ` | Name of the created constraint |
21+ | ` referencesConstraintComment ` | ` string ` | Comment on the created constraint |
22+ | ` onDelete ` | ` string ` | Adds ON DELETE constraint for a reference column |
23+ | ` onUpdate ` | ` string ` | Adds ON UPDATE constraint for a reference column |
24+ | ` match ` | ` string ` | ` FULL ` or ` SIMPLE ` |
25+ | ` deferrable ` | ` boolean ` | Flag for deferrable column constraint |
26+ | ` deferred ` | ` boolean ` | Flag for initially deferred deferrable column constraint |
27+ | ` comment ` | ` string ` | Adds comment on column |
28+ | ` expressionGenerated ` | ` string ` | Expression to compute column value |
29+ | ` sequenceGenerated ` | ` object ` | Creates identity column see [ sequence options section] ( sequences.md#sequence-options ) |
30+ | ` precedence ` | ` string ` | ` ALWAYS ` or ` BY DEFAULT ` |
3031
3132## Data types & Convenience Shorthand
3233
3334Data type strings will be passed through directly to postgres, so write types as you would if you were writing the
3435queries by hand.
3536
37+ ** PostgreSQL array columns can be defined with the ` array ` option:**
38+
39+ ``` ts
40+ pgm .addColumns (' myTable' , {
41+ tags: { type: PgType .TEXT , array: true },
42+ payByQuarter: { type: PgType .INTEGER , array: 4 },
43+ });
44+ ```
45+
46+ String-based PostgreSQL array type declarations continue to work as before:
47+
48+ ``` ts
49+ pgm .addColumns (' myTable' , { tags: { type: ' text[]' } });
50+ ```
51+
3652** There are some aliases on types to make things more foolproof:** _ (int, string, float, double, datetime, bool)_
3753
3854** There is a shorthand to pass only the type instead of an option object:**
0 commit comments