SQL query builder and ORM/Factory generator for Go with support for PostgreSQL, MySQL and SQLite
MIT License
Published by stephenafamo over 1 year ago
Full Changelog: https://github.com/stephenafamo/bob/compare/v0.19.1...v0.20.0
PreloadWhere
preload mod to filter what relation should be preloaded.ViewQuery
now embeds bob.BaseQuery
giving it additional methods like Apply
and Build
PlugState
, PlugDBInfo
and PlugTemplateData
.View.Name()
return a dialect-specific expressionDebug
helpers.
Debug
writes query output to stdoutDebugToWriter
writes the query output to any io.Writer
with a fallback to stdout.DebugToPrinter
prints the query with a given bob.DebugPrinter
. Also falls back to stdout.OnlyColumns
to PreloadOnly
and ExceptColumns
to PreloadExcept
to be more consistent with the newly added PreloadWhere
.JoinChain.On
now takes Expressions instead of any
.JoinChain.Using
now takes strings instead of any
.gen.TemplateData
ILIKE
operator from MySQL since it is not supported.Destination()
method in driver interface.PackageName()
method in driver interface.Preload
mods work the same way as other query modsPublished by stephenafamo over 1 year ago
On
method for JoinChain in mysql
and sqlite
Full Changelog: https://github.com/stephenafamo/bob/compare/v0.19.0...v0.19.1
Published by stephenafamo over 1 year ago
LIKE
and ILIKE
operatorsno_reverse
option for user-configured relationshipsFull Changelog: https://github.com/stephenafamo/bob/compare/v0.18.2...v0.19.0
Published by stephenafamo over 1 year ago
Full Changelog: https://github.com/stephenafamo/bob/compare/v0.18.1...v0.18.2
Published by stephenafamo over 1 year ago
Full Changelog: https://github.com/stephenafamo/bob/compare/v0.18.0...v0.18.1
Published by stephenafamo over 1 year ago
bob.Expression
)The primary breaking change is that several builder methods now require a bob.Expression
instead of any
.
While this makes building some simple queries more verbose, it makes it harder to make some errors.
As an example, consider the following query
// SELECT * FROM users WHERE id = 1
psql.Select(
sm.From("users"),
sm.Where(psql.X("id").EQ(1)),
)
This feels like the natural way to build this query, however there are some subtle potential issues:
1
should probably be passed as an argument. In a real world application, this could lead to an SQL injection.
// SELECT * FROM users WHERE id = $1
psql.Select(
sm.From("users"),
sm.Where(psql.X("id").EQ(psql.Arg(1))),
)
This query will throw an error if we use a string
// !!!!INVALID QUERY!!!!
// SELECT * FROM users WHERE name = Stephen
psql.Select(
sm.From("users"),
sm.Where(psql.X("name").EQ("Stephen")),
)
The initial reason why these took any
was to make Bob easy to adopt. However, after using this in practice, it is likely that the user always wants to do something to make it an expression.
psql.Quote
psql.Arg
X
builderThe X
builder, while convenient doesn't quite fit in anywhere. Most queries will be started with a quote, and can then be fluently chained with other expressions.
In the interest of keeping the surface area of this pacakge small, I've decided to remove it until there is a concrete need.
P
builder methodThe P
builder method was for adding parentheses to a single expression. However, this overlaps with the Group
method with adds parentheses around a list of expressions separated with a comma.
Since using the Group
method with a single expression does the same thing as the P
method, the P
method now feels redundant.
Published by stephenafamo over 1 year ago
Published by stephenafamo over 1 year ago
Published by stephenafamo over 1 year ago
Fix an issue in v0.17.0 which causes errors when generating sqlite
models
Published by stephenafamo over 1 year ago
Now, Bob will generate join mods for model relationships
models.SelectJoin(ctx).Users.InnerJoin.Posts
ON DUPLICATE KEY UPDATE
(#14)Published by stephenafamo over 1 year ago
um.Set
update mod works to allow more query building