mirror of https://github.com/aldy505/bob.git
docs: column types
This commit is contained in:
parent
b6fad37b7a
commit
4940a22a5a
22
README.md
22
README.md
|
@ -29,6 +29,8 @@ func main() {
|
||||||
StringColumn("email", "NOT NULL", "UNIQUE").
|
StringColumn("email", "NOT NULL", "UNIQUE").
|
||||||
// See the list of available column definition type through pkg.go.dev or scroll down below.
|
// See the list of available column definition type through pkg.go.dev or scroll down below.
|
||||||
TextColumn("password").
|
TextColumn("password").
|
||||||
|
// Or add your custom types
|
||||||
|
AddColumn(bob.ColumnDef{Name: "tableName", Type: "customType", Extras: []string{"NOT NULL"}}).
|
||||||
ToSql()
|
ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// handle your error
|
// 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.
|
Another builder of `bob.CreateTableIfNotExists()` is also available.
|
||||||
|
|
||||||
### Check if a table exists
|
### Check if a table exists
|
||||||
|
@ -87,7 +108,6 @@ Available placeholder formats:
|
||||||
* `bob.Colon` - `INSERT INTO "users" (name) VALUES (:1)`
|
* `bob.Colon` - `INSERT INTO "users" (name) VALUES (:1)`
|
||||||
* `bob.AtP` - `INSERT INTO "users" (name) VALUES (@p1)`
|
* `bob.AtP` - `INSERT INTO "users" (name) VALUES (@p1)`
|
||||||
|
|
||||||
|
|
||||||
### With pgx (PostgreSQL)
|
### With pgx (PostgreSQL)
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
|
Loading…
Reference in New Issue