docs: column types

This commit is contained in:
Reinaldy Rafli 2021-07-21 17:24:05 +07:00
parent b6fad37b7a
commit 4940a22a5a
1 changed files with 21 additions and 1 deletions

View File

@ -29,6 +29,8 @@ func main() {
StringColumn("email", "NOT NULL", "UNIQUE").
// See the list of available column definition type through pkg.go.dev or scroll down below.
TextColumn("password").
// Or add your custom types
AddColumn(bob.ColumnDef{Name: "tableName", Type: "customType", Extras: []string{"NOT NULL"}}).
ToSql()
if err != nil {
// handle your error
@ -36,6 +38,25 @@ func main() {
}
```
Available column definition types:
* `StringColumn()` - Default to `VARCHAR(255)`
* `TextColumn()` - Default to `TEXT`
* `UUIDColumn()` - Defaults to `UUID`
* `BooleanColumn()` - Defaults to `BOOLEAN`
* `IntegerColumn()` - Defaults to `INTEGER`. Postgres and SQLite only.
* `IntColumn()` - Defaults to `INT`. MySQL and MSSQL only.
* `RealColumn()` - Defaults to `REAL`. Postgres, MSSQL, and SQLite only.
* `FloatColumn()` - Defaults to `FLOAT`. Postgres and SQLite only.
* `DateTimeColumn()` - Defaults to `DATETIME`.
* `TimeStampColumn()` - Defaults to `TIMESTAMP`.
* `TimeColumn()` - Defaults to `TIME`.
* `DateColumn()` - Defaults to `DATE`.
* `JSONColumn()` - Dafults to `JSON`. MySQL and Postgres only.
* `JSONBColumn()` - Defaults to `JSONB`. Postgres only.
* `BlobColumn()` - Defaults to `BLOB`. MySQL and SQLite only.
For any other types, please use `AddColumn()`.
Another builder of `bob.CreateTableIfNotExists()` is also available.
### Check if a table exists
@ -87,7 +108,6 @@ Available placeholder formats:
* `bob.Colon` - `INSERT INTO "users" (name) VALUES (:1)`
* `bob.AtP` - `INSERT INTO "users" (name) VALUES (@p1)`
### With pgx (PostgreSQL)
```go