Skip to content

Commit

Permalink
feat: document timestamps method
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed May 19, 2021
1 parent 09a36bf commit 8a4763e
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions content/reference/database/table-builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,50 @@ this.schema.createTable('users', (table) => {

---

### timestamps
Adds `created_at` and `updated_at` columns to the database table.

:::warning

Since AdonisJS uses knex.js under the hood, your editor autocomplete feature will list the `timestamps` method in list of available methods.

However, we recommend not using this method and instead use the `timestamp` method for following reasons.

- The `timestamps` method is not chainable. Meaning you cannot add additional constraints like `index` or `nullable` to the column.
- You can create columns of type `timestampz` or `Datetime2`.

:::

```ts
this.schema.createTable('users', (table) => {
table.timestamps()
})
```

By default, the `timestamps` method creates a **DATETIME** column. However, you can change it to a **TIMESTAMP** column by passing `true` as the first argument.

```ts
this.schema.createTable('users', (table) => {
/**
* Creates timestamp column
*/
table.timestamps(true)
})
```

```ts
this.schema.createTable('users', (table) => {
/**
* Creates timestamp column
* +
* Set the default value to "CURRENT_TIMESTAMP"
*/
table.timestamps(true, true)
})
```

---

### binary
Adds a binary column. The method accepts the column name as the first argument, with an optional length as the second argument (applicable for MySQL only).

Expand Down

0 comments on commit 8a4763e

Please sign in to comment.