Skip to content

Commit

Permalink
Move to go modules
Browse files Browse the repository at this point in the history
- Add documentation about modules
- Add documentation about v4
- Bump version
- Update changelog
  • Loading branch information
aarondl committed Apr 27, 2020
1 parent e076d64 commit 4df9241
Show file tree
Hide file tree
Showing 58 changed files with 443 additions and 2,753 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
## [v4.0.0] - 2020-04-26

**NOTE:** Your database drivers must be rebuilt upon moving to this release

### Added

- Add a `--add-soft-deletes` that changes the templates to use soft deletion
(thanks @namco1992)
- Add a `--no-back-referencing` flag to disable setting backreferences in
relationship helpers and eager loading. (thanks @namco1992)
- Add not in helpers (thanks @RichardLindhout)

### Changed

- Changed dependency scheme to go modules
- Changed randomize/strmangle to be external dependencies to avoid module
cycles with the null package.
- Changed the way comparisons work for keying caches which dramatically speeds
up cache lookups (thanks @zikaeroh)

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2017 Volatile Technologies Inc. All rights reserved.
Copyright (c) 2020 Volatile Technologies Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
Expand Down
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ or some other migration tool to manage this part of the database's life-cycle.

v3 has been released, please upgrade when possible, v2 is on life support only now.

# Note on v3 vs v4

v4 is identical virtually identical to v3 (it has 1 or 2 more features) but
was turned into modules.

## Why another ORM

While attempting to migrate a legacy Rails database, we realized how much ActiveRecord benefited us in terms of development velocity.
Expand Down Expand Up @@ -111,6 +116,7 @@ Table of Contents
- Strongly typed querying (usually no converting or binding to pointers)
- Hooks (Before/After Create/Select/Update/Delete/Upsert)
- Automatic CreatedAt/UpdatedAt
- Automatic DeletedAt
- Table and column whitelist/blacklist
- Relationships/Associations
- Eager loading (recursive)
Expand Down Expand Up @@ -399,18 +405,22 @@ sqlboiler psql
Flags:
--add-global-variants Enable generation for global variants
--add-panic-variants Enable generation for panic variants
--add-soft-deletes Enable soft deletion by updating deleted_at timestamp
-c, --config string Filename of config file to override default lookup
-d, --debug Debug mode prints stack traces on error
-h, --help help for sqlboiler
--no-auto-timestamps Disable automatic timestamps for created_at/updated_at
--no-back-referencing Disable back referencing in the loaded relationship structs
--no-context Disable context.Context usage in the generated code
--no-driver-templates Disable parsing of templates defined by the database driver
--no-hooks Disable hooks feature for your models
--no-rows-affected Disable rows affected in the generated API
--no-tests Disable generated go test files
-o, --output string The name of the folder to output to (default "models")
-p, --pkgname string The name you wish to assign to your generated package (default "models")
--struct-tag-casing string Decides the casing for go structure tag names. camel or snake (default "snake")
--struct-tag-casing string Decides the casing for go structure tag names. camel, title or snake (default snake) (default "snake")
-t, --tag strings Struct tags to be included on your models in addition to json, yaml, toml
--tag-ignore strings List of column names that should have tags values set to '-' (ignored during parsing)
--templates strings A templates directory, overrides the bindata'd template folders in sqlboiler
--version Print the version
--wipe Delete the output folder (rm -rf) before generation to ensure sanity
Expand Down Expand Up @@ -840,6 +850,10 @@ The most common causes of problems and panics are:
field in Go so sqlboiler assumes you do not want to insert that field and you want the default
value from the database. Use a whitelist/greylist to add that field to the list of fields
to insert.
- decimal library showing errors like: `pq: encode: unknown type types.NullDecimal`
is a result of a too-new and broken version of the github.com/ericlargergren/decimal
package, use the following version in your go.mod:
github.com/ericlagergren/decimal v0.0.0-20181231230500-73749d4874d5

For errors with other causes, it may be simple to debug yourself by looking at the generated code.
Setting `boil.DebugMode` to `true` can help with this. You can change the output using `boil.DebugWriter` (defaults to `os.Stdout`).
Expand Down Expand Up @@ -976,6 +990,23 @@ before being sent to the database (if they were going to be sent).
will be used. To set `created_at` to `null`, set `Valid` to false and `Time` to a non-zero value.
* The `updated_at` column will always be set to `time.Now()`.

### Automatic DeletedAt (Soft Delete)

Soft deletes are a way of deleting records in a database for the average query
without actually removing the data. This type of thing is important in certain
scenarios where data retention is important. It is typically done by adding a
`deleted` bool or a `deleted_at` timestamp to each table in the database
that can be soft deleted and subsequent queries on that table should always
make sure that `deleted != true` or `deleted_at is null` to prevent showing
"deleted" data.

SQLBoiler uses the `deleted_at` variant to provide this functionality. If your
table has a nullable timestamp field named `deleted_at` it will be a candidate
for soft-deletion.

*NOTE*: As of writing soft-delete is opt-in via `--add-soft-deletes` and is
liable to change in future versions.

### Query Building

We generate "Starter" methods for you. These methods are named as the plural versions of your model,
Expand Down
2 changes: 1 addition & 1 deletion boil/columns.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package boil

import (
"github.com/volatiletech/sqlboiler/strmangle"
"github.com/volatiletech/strmangle"
)

// Columns kinds
Expand Down
6 changes: 3 additions & 3 deletions boilingcore/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package boilingcore
import (
"fmt"

"github.com/volatiletech/sqlboiler/drivers"
"github.com/volatiletech/sqlboiler/strmangle"
"github.com/volatiletech/sqlboiler/v4/drivers"
"github.com/volatiletech/strmangle"
)

// Aliases defines aliases for the generation run
Expand Down Expand Up @@ -42,7 +42,7 @@ func FillAliases(a *Aliases, tables []drivers.Table) {

for _, t := range tables {
if t.IsJoinTable {
jt, ok := a.Tables[t.Name];
jt, ok := a.Tables[t.Name]
if !ok {
a.Tables[t.Name] = TableAlias{Relationships: make(map[string]RelationshipAlias)}
} else if jt.Relationships == nil {
Expand Down
2 changes: 1 addition & 1 deletion boilingcore/aliases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"reflect"
"testing"

"github.com/volatiletech/sqlboiler/drivers"
"github.com/volatiletech/sqlboiler/v4/drivers"
)

func TestAliasesTables(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions boilingcore/boilingcore.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"strings"

"github.com/friendsofgo/errors"
"github.com/volatiletech/sqlboiler/drivers"
"github.com/volatiletech/sqlboiler/importers"
"github.com/volatiletech/sqlboiler/strmangle"
"github.com/volatiletech/sqlboiler/templatebin"
"github.com/volatiletech/sqlboiler/v4/drivers"
"github.com/volatiletech/sqlboiler/v4/importers"
"github.com/volatiletech/sqlboiler/v4/templatebin"
"github.com/volatiletech/strmangle"
)

const (
Expand Down
6 changes: 3 additions & 3 deletions boilingcore/boilingcore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"strconv"
"testing"

"github.com/volatiletech/sqlboiler/importers"
"github.com/volatiletech/sqlboiler/v4/importers"

"github.com/volatiletech/sqlboiler/drivers"
_ "github.com/volatiletech/sqlboiler/drivers/mocks"
"github.com/volatiletech/sqlboiler/v4/drivers"
_ "github.com/volatiletech/sqlboiler/v4/drivers/mocks"
)

var state *State
Expand Down
4 changes: 2 additions & 2 deletions boilingcore/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"strings"

"github.com/spf13/cast"
"github.com/volatiletech/sqlboiler/drivers"
"github.com/volatiletech/sqlboiler/importers"
"github.com/volatiletech/sqlboiler/v4/drivers"
"github.com/volatiletech/sqlboiler/v4/importers"
)

// Config for the running of the commands
Expand Down
2 changes: 1 addition & 1 deletion boilingcore/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package boilingcore
import (
"testing"

"github.com/volatiletech/sqlboiler/drivers"
"github.com/volatiletech/sqlboiler/v4/drivers"
)

func TestConfig_OutputDirDepth(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion boilingcore/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"text/template"

"github.com/friendsofgo/errors"
"github.com/volatiletech/sqlboiler/importers"
"github.com/volatiletech/sqlboiler/v4/importers"
)

var (
Expand Down
6 changes: 3 additions & 3 deletions boilingcore/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"text/template"

"github.com/friendsofgo/errors"
"github.com/volatiletech/sqlboiler/drivers"
"github.com/volatiletech/sqlboiler/strmangle"
"github.com/volatiletech/sqlboiler/templatebin"
"github.com/volatiletech/sqlboiler/v4/drivers"
"github.com/volatiletech/sqlboiler/v4/templatebin"
"github.com/volatiletech/strmangle"
)

// templateData for sqlboiler templates
Expand Down
4 changes: 2 additions & 2 deletions boilingcore/text_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package boilingcore
import (
"strings"

"github.com/volatiletech/sqlboiler/drivers"
"github.com/volatiletech/sqlboiler/strmangle"
"github.com/volatiletech/sqlboiler/v4/drivers"
"github.com/volatiletech/strmangle"
)

// txtNameToOne creates the local and foreign function names for
Expand Down
2 changes: 1 addition & 1 deletion boilingcore/text_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package boilingcore
import (
"testing"

"github.com/volatiletech/sqlboiler/drivers"
"github.com/volatiletech/sqlboiler/v4/drivers"
)

func TestTxtNameToOne(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/binary_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os/exec"

"github.com/friendsofgo/errors"
"github.com/volatiletech/sqlboiler/importers"
"github.com/volatiletech/sqlboiler/v4/importers"
)

type binaryDriver string
Expand Down
2 changes: 1 addition & 1 deletion drivers/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package drivers
import (
"strings"

"github.com/volatiletech/sqlboiler/strmangle"
"github.com/volatiletech/strmangle"
)

// Column holds information about a database column.
Expand Down
4 changes: 2 additions & 2 deletions drivers/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"sort"

"github.com/friendsofgo/errors"
"github.com/volatiletech/sqlboiler/importers"
"github.com/volatiletech/sqlboiler/strmangle"
"github.com/volatiletech/sqlboiler/v4/importers"
"github.com/volatiletech/strmangle"
)

// These constants are used in the config map passed into the driver
Expand Down
2 changes: 1 addition & 1 deletion drivers/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package drivers
import (
"testing"

"github.com/volatiletech/sqlboiler/strmangle"
"github.com/volatiletech/strmangle"
)

type testMockDriver struct{}
Expand Down
14 changes: 7 additions & 7 deletions drivers/mocks/mock.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package mocks

import (
"github.com/volatiletech/sqlboiler/drivers"
"github.com/volatiletech/sqlboiler/importers"
"github.com/volatiletech/sqlboiler/strmangle"
"github.com/volatiletech/sqlboiler/v4/drivers"
"github.com/volatiletech/sqlboiler/v4/importers"
"github.com/volatiletech/strmangle"
)

func init() {
Expand All @@ -23,16 +23,16 @@ func (m *MockDriver) Imports() (importers.Collection, error) {
return importers.Collection{
BasedOnType: importers.Map{
"null.Int": {
ThirdParty: importers.List{`"github.com/volatiletech/null"`},
ThirdParty: importers.List{`"github.com/volatiletech/null/v8"`},
},
"null.String": {
ThirdParty: importers.List{`"github.com/volatiletech/null"`},
ThirdParty: importers.List{`"github.com/volatiletech/null/v8"`},
},
"null.Time": {
ThirdParty: importers.List{`"github.com/volatiletech/null"`},
ThirdParty: importers.List{`"github.com/volatiletech/null/v8"`},
},
"null.Bytes": {
ThirdParty: importers.List{`"github.com/volatiletech/null"`},
ThirdParty: importers.List{`"github.com/volatiletech/null/v8"`},
},

"time.Time": {
Expand Down
2 changes: 1 addition & 1 deletion drivers/registration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package drivers
import (
"testing"

"github.com/volatiletech/sqlboiler/importers"
"github.com/volatiletech/sqlboiler/v4/importers"
)

type testRegistrationDriver struct{}
Expand Down
Loading

0 comments on commit 4df9241

Please sign in to comment.