Create defines a new table schema.
import Create from '@stackpress/inquire/Create';Most code uses it through engine.create(table).
await engine.create('users')
.addField('id', { type: 'integer', autoIncrement: true })
.addField('email', { type: 'string', length: 255, nullable: false })
.addPrimaryKey('id')
.addUniqueKey('users_email_unique', 'email');Add a field definition.
| Parameter | Type | Description |
|---|---|---|
name |
string |
Column name. |
field |
Field |
Field definition. |
Add a foreign key definition.
Add a non-unique index. field can be a string or string array.
Add one primary key column name. Call it multiple times for composite keys.
Add a unique key. field can be a string or string array.
Return the collected schema state.
Return an array of QueryObject values for the target dialect.
Returns
An array because a table definition may need more than one statement.
Execute the generated statements through the attached engine.
Returns
A promise that resolves with the result of the last query in the transaction.
The shared Field type supports:
typelengthattributedefaultnullableunsignedautoIncrementcomment
Actual SQL support varies by dialect.