Truncate table [PostgreSQL MySQL]

API

For the full list of supported methods, see TruncateTableQueryTRUNCATE TABLE - 图1open in new window.

  1. db.NewTruncateTable().
  2. Model(&strct).
  3. Table("table1"). // quotes table names
  4. TableExpr("table1"). // arbitrary unsafe expression
  5. ModelTableExpr("table1"). // overrides model table name
  6. ContinueIdentity().
  7. Cascade().
  8. Restrict().
  9. Exec(ctx)

Example

To drop a table:

  1. _, err := db.NewTruncateTable().Model((*Book)(nil)).Exec(ctx)
  2. if err != nil {
  3. panic(err)
  4. }