bob

SQL query builder and ORM/Factory generator for Go with support for PostgreSQL, MySQL and SQLite

MIT License

Stars
760
Committers
22
bob - v0.28.1 Latest Release

Published by stephenafamo 4 months ago

Fixed

  • Also add the enum to the type array if an array of the enum is added. This is to prvent issues if the enum is only used in an array.
  • Handle null column names in expression indexes. (thanks @mbezhanov)

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.28.0...v0.28.1

bob - v0.28.0

Published by stephenafamo 4 months ago

Added

  • Added the pgtypes.Inet for inet type in PostgreSQL. (thanks @gstarikov)
  • Added the pgtypes.Macaddr for macaddr and macaddr8 types in PostgreSQL.
  • Added the pgtypes.LSN type for the pg_lsn type in PostgreSQL.
  • Added the pgtypes.TxIDSnapshot type for the txid_snapshot type in PostgreSQL.
  • Added the pgtypes.TSVector type for the tsvector type in PostgreSQL.
  • Added AliasOf property to codegen type definitions to allow for defining types that have their own randomization logic.
  • Added DependsOn property to codegen type definitions to allow for defining types that depend on other types. This ensures that necessary code for the dependent types is generated.
  • Add xml type definition for custom randomization logic.
  • Add the Cast() starter to all dialects to build CAST(expr AS type) expressions.
  • Load index information for MySQL, PostgreSQL, and SQLite tables. (thanks @mbezhanov)

Changed

  • Changed the parray package to pgtypes.
  • Moved HStore to the pgtypes package.
  • Simplified how random expressions are written for types by using standalone functions instead of a single generic function.
  • The default DebugPrinter now prints args a bit more nicely by using thier Value() method if they implement the driver.Valuer interface.
  • Only generate 2 random values when testing random expressions.

Removed

  • Removed types.Stringer[T]. It makes assumptions for how the type should be scanned and is not reliable.

Fixed

  • Do not add FROM clause to SELECT queries that are used as subqueries.
  • Enum values are now checked for validity after scanning.

New Contributors

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.27.1...v0.28.0

bob - v0.27.1

Published by stephenafamo 5 months ago

Fixed

  • Fixed bug in Count() queries not removing the offset from the original query. (thanks @daddz)

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.27.0...v0.27.1

bob - v0.27.0

Published by stephenafamo 5 months ago

Added

  • Add PreloadAs PreloadOption to override the join alias when preloading a relationship with a left join. (thanks @daddz)

  • Add AliasedAs() method to tableColumns and tableWhere types to use a custom alias.

  • Add AliasedAs() method to generated relationship join mods. This is avaible in two places:

    • one to change the alias of the table being queried

      models.SelectJoins.Jets.AliasedAs("j").InnerJoin.Pilots(ctx)
      
    • and the other to change the alias of the relationship.

      models.SelectJoins.Jets.InnerJoin.Pilots(ctx).AliasedAs("p")
      
  • Add fm mods to all supported dialects (psql, mysql and sqlite). These are mods for functions and are used to modify the function call. For example:

    // import "github.com/stephenafamo/bob/dialect/psql/fm"
    psql.F( "count", "*",)(fm.Filter(psql.Quote("status").EQ(psql.S("done"))))
    
  • Add MustCreate, MustCreateMany, CreateOrFail and CreateManyOrFail methods to generated factory Templates

Changed

  • Change the function call point for generated relationship join mods. This reduces the amount of allocations and only does the work for the relationship being used.

    // Before
    models.SelectJoins(ctx).Jets.InnerJoin.Pilots
    // After
    models.SelectJoins.Jets.InnerJoin.Pilots(ctx)
    
  • Changed the Count() function on Views to clone the query instead of changing the existing one. This makes queries reusable and the Count() function to behave as one would expect.

    // This now works as expected
    query := models.Jets.Query(ctx, db, /** list of various mods **/)
    count, err := query.Count()
    items, err := query.All()
    
  • Changed how functions are modified. Instead of chained methods, the F() starter now returns a function which can be called with mods:

    // Before
    psql.F( "count", "*",).FilterWhere(psql.Quote("status").EQ(psql.S("done"))),
    // After
    // import "github.com/stephenafamo/bob/dialect/psql/fm"
    psql.F( "count", "*",)(fm.Filter(psql.Quote("status").EQ(psql.S("done")))),
    

    This makes it possible to support more queries.

  • Use netip.Addr instead of netip.Prefix for Postgres cidr type.

  • Use decimal.Decimal instead of string for Postgres money type.

  • Use net.HardwareAddr for Postgres macaddr8 type, in addition to the macaddr type.

  • Code generation now generates struct tags for the generated model Setters as well, if configured through the Tags configuration option. Previoulsy, only the model struct fields were tagged. (thanks @singhsays)

Removed

  • Remove TableWhere function from the generated code. It was not used by the rest of the generated code and offered no clear benefit.
  • Removed As starter. It takes an Expression and is not needed since the Expression has an As method which can be used directly.

Fixed

  • Fix a bug with types.Stringer[T] where the wrong value was returned in the Value() method.

New Contributors

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.26.1...v0.27.0

bob - v0.26.1

Published by stephenafamo 5 months ago

Fixed

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.26.0...v0.26.1

bob - v0.26.0

Published by stephenafamo 5 months ago

Added

  • Add bobgen-sql a code generation driver for SQL schema files. Supports PostgreSQL and SQLite.
  • Add new properties compare_expr and compare_expr_imports to the types configuration. This is used when comparing primary keys and in testing.
  • Add never_required to relationships configuration. This makes sure the factories does not require the relationship to be set. Useful if you're not using foreign keys. (thanks @jacobmolby)
  • Add wrapper types for Stringer, TextMarshaler/Unmarshaler, and BinaryMarshaler/Unmarshaler to the types configuration.
  • Make generated enum types implement the fmt.Stringer, encoding.TextMarshaler, encoding.TextUnmarshaler, encoding.BinaryMarshaler and encoding.BinaryUnmarshaler interfaces.

Fixed

  • Properly detect reference columns for implicit foreign keys in SQLite.
  • Fix panic when generating random values for nullable columns. (thanks @jacobmolby)
  • Sort relationships and imports for deterministic generated code. (thanks @jacobmolby)
  • Correctly allow OVER () with an empty window definition in PostgreSQL. (thanks @relvacode)
  • Set GROUP BY to NULL if there are no expressions to group by.
  • Replace symbols in enum values with their unicode point to make them valid Go identifiers.
  • Properly detect implicit foreign keys in SQLite.
  • Fix issue with attaching multi-sided relationships. (thanks @jacobmolby)

New Contributors

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.25.0...v0.26.0

bob - v0.25.0

Published by stephenafamo 9 months ago

Changed

  • Update github.com/jaswdr/faker dependency from v1 to v2

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.24.0...v0.25.0

bob - v0.24.0

Published by stephenafamo 9 months ago

Added

  • Add randomization for all primitive types
  • Add test for factory type randomization
  • Drivers are now required to send in type definitions for generated types
  • Custom types can now be configured at a top level in the config file

Changed

  • Format generated files with gofumpt
  • Replace key in replacements configuration is now a string referring to the type defined in the types configuration.

Removed

  • Remove Imports from column definition.

Fixed

  • INTEGER columns are now correctly generated as int32 not int

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.23.2...v0.24.0

bob - v0.23.2

Published by stephenafamo 10 months ago

Fixed

  • Fix panic when inferring modify for relationships with no primary key
  • Skip factory enum generation if there are no enums
  • Return sql.ErrNoRows when Insert/Upsert returns nothing

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.23.1...v0.23.2

bob - v0.23.1

Published by stephenafamo 10 months ago

Fixed

  • Do not wrap Setter.Expressions() in parenthesis

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.23.0...v0.23.1

bob - v0.23.0

Published by stephenafamo 10 months ago

Added

  • Add bob.Cache() which saves the built SQL and args to prevent rebuilding the same query multiple times.
  • Add As() starter to alias expressions
  • Add OP() builder method for using custom operators
  • Add table.InsertQ(ctx, db) now includes the insert columns from the table model.
  • It is now possible to configure additional constraints for code generation.
  • Add um.SetCol() which maintains the old behavior of um.Set().
  • Generate additional Expressions() method for Setters to make it easier to use them in um.Set() or im.Set().

Changed

  • Aliases configuration for code generation no longer has a top level table key
  • When configuring relationships, from_unique, to_unique, key_nullable can no longer be configured. They are now inferred from the database.
  • When configuring relationships, to_key has been changed to modify and should be set to from, to or "" to indicate which side of the relationship to modify.
    If left empty, Bob will try to guess which side to modify based on the presence of primary keys and unique columns.
  • RelWhere.Value is now RelWhere.SQLValue
  • Change CONFLICT/DUPLICATE KEY UPDATE to use mods instead of a chainable methods.
  • Change um.Set() to take a list of expressions.
  • Rename Setter method from Insert() to InsertMod() to avoid confusion.

Fixed

  • Prevent generating duplicate relationships for many-to-many self-join relationships
  • Correctly use table alias in generated relationship join mods
  • Fix an issue where CTEs were encased in double parenthesis
  • Fix invalid SQL generated when doing JOIN USING
  • Correctly include "AS" in function query if alias is set
  • Setters are also generated for tables that have relationships, even if they have no primary key
  • Column aliases in CTEs are now correctly included in the final query
  • Fix several issues with generating code for multi-sided relationships
  • Fix an issue where loading many-to-many relationships cause no columns to be selected unless specified
  • Fix an issue where many-to-many relationships would not be able to use nested loaders

New Contributors

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.22.0...v0.23.0

bob - v0.22.0

Published by stephenafamo about 1 year ago

Added

  • Expand expressions when used in Raw (thanks @RangelReale)
  • Add InsertQ, UpdateQ, and DeleteQ methods to Table models to start INSERT, UPDATE and DELETE queries respectively.
  • Allow column comment for replacement matching (thanks @jroenf)
  • Add table query hooks to modify model queries
  • Include WhereOr and WhereAnd to make it easier to combine multiple generated where clauses
  • Print a warning if a replacement rule did not find a match (thanks @jacobmolby)

Changed

  • Export generated factory.Factory struct
  • Allow Limit and Offset to be used as Arguments in PostgreSQL (thanks @RangelReale)
  • Make model hooks take slices not single objects
  • Return rows affected from Exec() method of view queries instead of sql.Result
  • Chain comparison methods now take an Expression instead of any
  • Table models now require the types to implement orm.Table and orm.Setter interfaces.

Removed

  • Remove UpdateAll and DeleteAll methods on the Table models.

Fixed

  • Honor Only and Except in sqlite driver
  • Always surround subqueries with parenthesis when used as an expression
  • Fix mysql TablesInfo method and make sure we don't exclude entire table when targeting columns (thanks @jacobmolby)
  • Fix bug in sqlite foreign key and join table detection

New Contributors

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.21.1...v0.22.0

bob - v0.21.1

Published by stephenafamo over 1 year ago

Fixed

  • Fix Upsert and UpsertAll methods of mysql.Table

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.21.0...v0.21.1

bob - v0.21.0

Published by stephenafamo over 1 year ago

Changed

  • Force uniqueness of relationship names in psql driver

Fixed

  • Fix panic when attaching associated relationships
  • Make getting a random integer for preloading thread-safe

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.20.6...v0.21.0

bob - v0.20.6

Published by stephenafamo over 1 year ago

  • Check all members when loading relationships

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.20.5...v0.20.6

bob - v0.20.5

Published by stephenafamo over 1 year ago

  • Fix panic in Insert/Attach Relationship loop

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.20.4...v0.20.5

bob - v0.20.4

Published by stephenafamo over 1 year ago

  • Replace huandu/go-clone with qdm12/reprint

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.20.3...v0.20.4

bob - v0.20.3

Published by stephenafamo over 1 year ago

  • Fix cloning bug by replacing jinzhu/copier with huandu/go-clone

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.20.2...v0.20.3

bob - v0.20.2

Published by stephenafamo over 1 year ago

  • Account for windows when calculating models module path

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.20.1...v0.20.2

bob - v0.20.1

Published by stephenafamo over 1 year ago

  • Update the generated code to use github.com/gofrs/uuid/v5
  • Fix bug where auto-increment columns were marked as generated in the SQLite driver

Full Changelog: https://github.com/stephenafamo/bob/compare/v0.20.0...v0.20.1