|
2 | 2 |
|
3 | 3 | [](https://pkg.go.dev/github.com/aldy505/bob) [](https://goreportcard.com/report/github.com/aldy505/bob)  [](https://www.codefactor.io/repository/github/aldy505/bob) [](https://codecov.io/gh/aldy505/bob) [](https://www.codacy.com/gh/aldy505/bob/dashboard?utm_source=github.com&utm_medium=referral&utm_content=aldy505/bob&utm_campaign=Badge_Grade) [](https://github.com/aldy505/bob/actions/workflows/build.yml) [](https://github.com/aldy505/bob/actions/workflows/coverage.yml)
|
4 | 4 |
|
5 |
| -I really need a create table SQL builder, and I can't find one. So, like everything else, I made one. Heavily inspired by [Squirrel](https://github.com/Masterminds/squirrel) and [Knex](https://knexjs.org/). |
| 5 | +I really need a create table SQL builder, and I can't find one. So, like everything else, I made one. Heavily inspired by [Squirrel](https://github.com/Masterminds/squirrel) and [Knex](https://knexjs.org/). And of course, I still use Squirrel for other types of queries (insert, select, and all), think this package as an extension for Squirrel. |
6 | 6 |
|
7 | 7 | Oh, and of course, heavily inspired by Bob the Builder.
|
8 | 8 |
|
| 9 | +```go |
| 10 | +import "github.com/aldy505/bob" |
| 11 | +``` |
| 12 | + |
9 | 13 | ## Usage
|
10 | 14 |
|
11 | 15 | It's not ready for production yet. But, the API is probably close to how you'd do things on Squirrel. This is an example for using with pgx.
|
@@ -61,6 +65,32 @@ func main() {
|
61 | 65 | log.Fatal(err)
|
62 | 66 | }
|
63 | 67 | }
|
| 68 | + |
| 69 | + // Create another table, this time with CREATE TABLE IF NOT EXISTS |
| 70 | + sql, _, err := bob.CreateTableIfNotExists("inventory"). |
| 71 | + Columns("id", "userID", "items", "quantity"). |
| 72 | + Types("varchar(36)", "varchar(36)", "json", "int"). |
| 73 | + Primary("id"). |
| 74 | + ToSql() |
| 75 | + if err != nil { |
| 76 | + log.Fatal(err) |
| 77 | + } |
| 78 | + |
| 79 | + inventoryQuery := strings.Split(sql, ";") |
| 80 | + for i := range inventoryQuery { |
| 81 | + _, err = db.Query(context.Background(), inventoryQuery[i]) |
| 82 | + if err != nil { |
| 83 | + log.Fatal(err) |
| 84 | + } |
| 85 | + } |
64 | 86 | }
|
65 | 87 | }
|
66 |
| -``` |
| 88 | +``` |
| 89 | + |
| 90 | +## Contributing |
| 91 | + |
| 92 | +Contributions are always welcome! As long as you add a test for your changes. |
| 93 | + |
| 94 | +## License |
| 95 | + |
| 96 | +Bob is licensed under [MIT license](./LICENSE) |
0 commit comments