docs: grammar

This commit is contained in:
Reinaldy Rafli 2021-07-22 01:47:19 +07:00 committed by GitHub
parent 0a8dbefad7
commit 0d704c88df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 8 deletions

View File

@ -12,7 +12,7 @@ import "github.com/aldy505/bob"
## Usage ## Usage
It's not ready for large-scale production yet (I've already using it on one of my projects). But, the API is probably close to how you'd do things on Squirrel. It's not ready for large-scale production yet (although I've already using it on one of my projects). But, the API is probably close to how you'd do things on Squirrel.
### Create a table ### Create a table
@ -20,16 +20,16 @@ It's not ready for large-scale production yet (I've already using it on one of m
import "github.com/aldy505/bob" import "github.com/aldy505/bob"
func main() { func main() {
// Note that CREATE TABLE don't return args params. // Note that CREATE TABLE doesn't returns args params.
sql, _, err := bob. sql, _, err := bob.
CreateTable("tableName"). CreateTable("tableName").
// The first parameter is the column's name. // The first parameter is the column's name.
// The second parameters and so on forth are extras. // The second parameters and so on forth are extras.
StringColumn("id", "NOT NULL", "PRIMARY KEY", "AUTOINCREMENT"). StringColumn("id", "NOT NULL", "PRIMARY KEY", "AUTOINCREMENT").
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 types through pkg.go.dev or scroll down below.
TextColumn("password"). TextColumn("password").
// Or add your custom types // Or add your custom type.
AddColumn(bob.ColumnDef{Name: "tableName", Type: "customType", Extras: []string{"NOT NULL"}}). AddColumn(bob.ColumnDef{Name: "tableName", Type: "customType", Extras: []string{"NOT NULL"}}).
ToSql() ToSql()
if err != nil { if err != nil {
@ -38,7 +38,7 @@ func main() {
} }
``` ```
Available column definition types: Available column definition types (please be aware that some only works on certain database):
* `StringColumn()` - Default to `VARCHAR(255)` * `StringColumn()` - Default to `VARCHAR(255)`
* `TextColumn()` - Default to `TEXT` * `TextColumn()` - Default to `TEXT`
* `UUIDColumn()` - Defaults to `UUID` * `UUIDColumn()` - Defaults to `UUID`
@ -81,7 +81,7 @@ func main() {
} }
``` ```
### Placeholder format ### Placeholder format / Dialect
Default placeholder is a question mark (MySQL-like). If you want to change it, simply use something like this: Default placeholder is a question mark (MySQL-like). If you want to change it, simply use something like this:
@ -141,7 +141,6 @@ func main() {
if !hasTableUsers { if !hasTableUsers {
// Create "users" table // Create "users" table
// Note that this will return multiple query in a single string.
sql, _, err := bob. sql, _, err := bob.
CreateTable("users"). CreateTable("users").
IntegerColumn("id", "PRIMARY KEY", "SERIAL"). IntegerColumn("id", "PRIMARY KEY", "SERIAL").
@ -203,4 +202,4 @@ Contributions are always welcome! As long as you add a test for your changes.
## License ## License
Bob is licensed under [MIT license](./LICENSE) Bob is licensed under [MIT license](./LICENSE)