@@ -13,9 +13,9 @@ with functionality like [Knex][knex-url] (from the Node.js world). Squirrel itse
13
13
doesn't provide other types of queries for creating a table, upsert,
14
14
and some other things. Bob is meant to fill those gaps.
15
15
16
- The different between Bob and Squirrel is that Bob is solely a query builder.
17
- The users have to execute and manage the SQL connection themself .
18
- Meaning there are no ExecWith() function implemented on Bob, as you can
16
+ The difference between Bob and Squirrel is that Bob is solely a query builder.
17
+ The users have to execute and manage the SQL connection themselves .
18
+ Meaning there is no ExecWith() function implemented in Bob, as you can
19
19
find it on Squirrel.
20
20
21
21
The purpose of an SQL query builder is to prevent any typo or mistypes
@@ -41,7 +41,7 @@ you are good to go.
41
41
42
42
Either way, I'm not 100% confident enough to say that this thing is
43
43
production ready. But, the way I see it, it's good enough to be used
44
- on a production-level applications . In fact, I'm using it on one of my
44
+ on a production-level application . In fact, I'm using it on one of my
45
45
current projects that's getting around 100-200 hits per day.
46
46
47
47
If you have any feature request or improvement ideas for the project,
@@ -57,7 +57,7 @@ func main() {
57
57
sql , _ , err := bob.
58
58
CreateTable (" tableName" ).
59
59
// The first parameter is the column's name.
60
- // The second parameters and so on forth are extras.
60
+ // The second parameter and so on forth are extras.
61
61
StringColumn (" id" , " NOT NULL" , " PRIMARY KEY" , " AUTOINCREMENT" ).
62
62
StringColumn (" email" , " NOT NULL" , " UNIQUE" ).
63
63
// See the list of available column definition types through pkg.go.dev or scroll down below.
@@ -72,21 +72,22 @@ func main() {
72
72
```
73
73
74
74
Available column definition types (please be aware that some only works on certain database):
75
- * ` StringColumn() ` - Default to ` VARCHAR(255) `
76
- * ` TextColumn() ` - Default to ` TEXT `
77
- * ` UUIDColumn() ` - Defaults to ` UUID `
78
- * ` BooleanColumn() ` - Defaults to ` BOOLEAN `
79
- * ` IntegerColumn() ` - Defaults to ` INTEGER ` . Postgres and SQLite only.
80
- * ` IntColumn() ` - Defaults to ` INT ` . MySQL and MSSQL only.
81
- * ` RealColumn() ` - Defaults to ` REAL ` . Postgres, MSSQL, and SQLite only.
82
- * ` FloatColumn() ` - Defaults to ` FLOAT ` . Postgres and SQLite only.
83
- * ` DateTimeColumn() ` - Defaults to ` DATETIME ` .
84
- * ` TimeStampColumn() ` - Defaults to ` TIMESTAMP ` .
85
- * ` TimeColumn() ` - Defaults to ` TIME ` .
86
- * ` DateColumn() ` - Defaults to ` DATE ` .
87
- * ` JSONColumn() ` - Dafults to ` JSON ` . MySQL and Postgres only.
88
- * ` JSONBColumn() ` - Defaults to ` JSONB ` . Postgres only.
89
- * ` BlobColumn() ` - Defaults to ` BLOB ` . MySQL and SQLite only.
75
+
76
+ - ` StringColumn() ` - Default to ` VARCHAR(255) `
77
+ - ` TextColumn() ` - Default to ` TEXT `
78
+ - ` UUIDColumn() ` - Defaults to ` UUID `
79
+ - ` BooleanColumn() ` - Defaults to ` BOOLEAN `
80
+ - ` IntegerColumn() ` - Defaults to ` INTEGER ` . Postgres and SQLite only.
81
+ - ` IntColumn() ` - Defaults to ` INT ` . MySQL and MSSQL only.
82
+ - ` RealColumn() ` - Defaults to ` REAL ` . Postgres, MSSQL, and SQLite only.
83
+ - ` FloatColumn() ` - Defaults to ` FLOAT ` . Postgres and SQLite only.
84
+ - ` DateTimeColumn() ` - Defaults to ` DATETIME ` .
85
+ - ` TimeStampColumn() ` - Defaults to ` TIMESTAMP ` .
86
+ - ` TimeColumn() ` - Defaults to ` TIME ` .
87
+ - ` DateColumn() ` - Defaults to ` DATE ` .
88
+ - ` JSONColumn() ` - Defaults to ` JSON ` . MySQL and Postgres only.
89
+ - ` JSONBColumn() ` - Defaults to ` JSONB ` . Postgres only.
90
+ - ` BlobColumn() ` - Defaults to ` BLOB ` . MySQL and SQLite only.
90
91
91
92
For any other types, please use ` AddColumn() ` .
92
93
@@ -244,10 +245,11 @@ func main() {
244
245
```
245
246
246
247
Available placeholder formats:
247
- * ` bob.Question ` - ` INSERT INTO "users" (name) VALUES (?) `
248
- * ` bob.Dollar ` - ` INSERT INTO "users" (name) VALUES ($1) `
249
- * ` bob.Colon ` - ` INSERT INTO "users" (name) VALUES (:1) `
250
- * ` bob.AtP ` - ` INSERT INTO "users" (name) VALUES (@p1) `
248
+
249
+ - ` bob.Question ` - ` INSERT INTO "users" (name) VALUES (?) `
250
+ - ` bob.Dollar ` - ` INSERT INTO "users" (name) VALUES ($1) `
251
+ - ` bob.Colon ` - ` INSERT INTO "users" (name) VALUES (:1) `
252
+ - ` bob.AtP ` - ` INSERT INTO "users" (name) VALUES (@p1) `
251
253
252
254
### With pgx (PostgreSQL)
253
255
@@ -264,7 +266,7 @@ import (
264
266
func main () {
265
267
db := pgx.Connect ()
266
268
267
- // Check if a table is exists
269
+ // Check if a table exists
268
270
sql, args, err = bob.HasTable (" users" ).PlaceholderFormat (bob.Dollar ).ToSql ()
269
271
if err != nil {
270
272
log.Fatal (err)
@@ -320,17 +322,17 @@ func main() {
320
322
321
323
## Features
322
324
323
- * ` bob.CreateTable(tableName) ` - Basic SQL create table
324
- * ` bob.CreateTableIfNotExists(tableName) ` - Create table if not exists
325
- * ` bob.CreateIndex(indexName) ` - Basic SQL create index
326
- * ` bob.CreateIndexIfNotExists(tableName) ` - Create index if not exists
327
- * ` bob.HasTable(tableName) ` - Checks if column exists (return error if false, check example above for error handling)
328
- * ` bob.HasColumn(columnName) ` - Check if a column exists on current table
329
- * ` bob.DropTable(tableName) ` - Drop a table (` drop table "users" ` )
330
- * ` bob.DropTableIfExists(tableName) ` - Drop a table if exists (` drop table if exists "users" ` )
331
- * ` bob.RenameTable(currentTable, desiredName) ` - Rename a table (` rename table "users" to "people" ` )
332
- * ` bob.Truncate(tableName) ` - Truncate a table (` truncate "users" ` )
333
- * ` bob.Upsert(tableName, dialect) ` - UPSERT function (` insert into "users" ("name", "email") values (?, ?) on duplicate key update email = ? ` )
325
+ - ` bob.CreateTable(tableName) ` - Basic SQL create table
326
+ - ` bob.CreateTableIfNotExists(tableName) ` - Create table if not exists
327
+ - ` bob.CreateIndex(indexName) ` - Basic SQL create index
328
+ - ` bob.CreateIndexIfNotExists(tableName) ` - Create index if not exists
329
+ - ` bob.HasTable(tableName) ` - Checks if column exists (return error if false, check example above for error handling)
330
+ - ` bob.HasColumn(columnName) ` - Check if a column exists on current table
331
+ - ` bob.DropTable(tableName) ` - Drop a table (` drop table "users" ` )
332
+ - ` bob.DropTableIfExists(tableName) ` - Drop a table if exists (` drop table if exists "users" ` )
333
+ - ` bob.RenameTable(currentTable, desiredName) ` - Rename a table (` rename table "users" to "people" ` )
334
+ - ` bob.Truncate(tableName) ` - Truncate a table (` truncate "users" ` )
335
+ - ` bob.Upsert(tableName, dialect) ` - UPSERT function (` insert into "users" ("name", "email") values (?, ?) on duplicate key update email = ? ` )
334
336
335
337
## Contributing
336
338
@@ -353,6 +355,6 @@ Bob is licensed under [MIT license](./LICENSE)
353
355
[ codecov-badge ] : https://codecov.io/gh/aldy505/bob/branch/master/graph/badge.svg?token=Noeexg5xEJ
354
356
[ codecov-link ] : https://codecov.io/gh/aldy505/bob
355
357
[ codacy-badge ] : https://app.codacy.com/project/badge/Grade/9b78970127c74c1a923533e05f65848d
356
- [ codacy-link ] : https://www.codacy.com/gh/aldy505/bob/dashboard?utm_source=github.com& ; utm_medium=referral& ; utm_content=aldy505/bob& ; utm_campaign=Badge_Grade
358
+ [ codacy-link ] : https://www.codacy.com/gh/aldy505/bob/dashboard?utm_source=github.com&utm_medium=referral&utm_content=aldy505/bob&utm_campaign=Badge_Grade
357
359
[ actions-badge ] : https://github.com/aldy505/bob/actions/workflows/coverage.yml/badge.svg
358
360
[ actions-link ] : https://github.com/aldy505/bob/actions/workflows/coverage.yml
0 commit comments