Compare commits

...

38 commits

Author SHA1 Message Date
Alex Grintsvayg
e3c6bfd745 use interface to enable custom Tx types 2017-09-02 12:03:40 -04:00
Aaron L
86c580f537 Bump version to v2.5.1 2017-08-07 15:31:23 -07:00
Aaron L
040f9e41be Fix randomization of enum values
- Fix #179
2017-08-07 15:29:21 -07:00
Aaron L
50b854ef83 Merge branch 'ceshihao/fix-signed-bigint' 2017-08-07 15:22:20 -07:00
ceshihao
f0f386e97b fix null.Int64 when it is signed 2017-08-03 18:19:35 +08:00
Aaron L
9dd03ac6a8 Amend license 2017-07-30 20:35:06 -07:00
Aaron L
82bffe9144 Adjust import paths 2017-07-30 20:34:54 -07:00
Aaron L
c43e856136 Merge branch 'tchssk/readme-find' 2017-07-13 22:29:10 -07:00
Taichi Sasaki
ca4dc4433b Fix examples of Find in README 2017-07-06 07:05:32 +09:00
Aaron L
0b027fa01c Fix hook documentation to include error return
Fix #171
2017-07-02 11:16:21 -07:00
Patrick L. O'Brien
e96316501c Update logo 2017-06-29 01:44:44 +10:00
Patrick L. O'Brien
b27796cb28 Update logo 2017-06-29 01:42:07 +10:00
Aaron L
cc47da44fb Amend readme for constants 2017-06-27 21:10:47 -07:00
Aaron L
82e14d2e1a Bump version 2.5.0 2017-06-27 20:59:25 -07:00
Aaron L
229c6ebc35 Merge branch 'jfernstad/fix-area-plural-issue' into dev 2017-06-27 20:58:07 -07:00
Joakim Fernstad
6022d471e3 Fix area plural issue, add testcase
- Fix #168
2017-06-27 12:56:13 +02:00
Aaron L
e58ab28787 Merge branch 'master' into dev 2017-06-26 21:19:59 -07:00
Guy Tish
f5e53ac52b Added table columns and table names as anonymous struct 2017-06-26 14:14:16 +03:00
Aaron L
c00ebe1911 Correct nullability for tests in to_one
- Use the nullability of the fkey column in question to determine
  nullability for the entire struct to make things easy, otherwise
  we'd have to pluck out one at a time. This makes the tests pass
  instead of fail sporadically.
- Fix #160
2017-06-14 21:16:31 -07:00
Aaron L
35563d1bdf Fix selecting in one-to-many relatiosships
- This fix checks the query that's being prepared for any select
  statements, if there's none then add one so the query does what's
  expected.
- Fix #159
2017-06-14 20:53:39 -07:00
Aaron L
1e9753091b Merge branch 'randimize-enums-with-single-value' into dev 2017-06-14 20:23:40 -07:00
Genadi Samokovarov
64206cfe07 Fix randomization for enums with single value
Hey there,

I hit a bug that panicked the tests with:

    panic: invalid argument to Intn

The problem happened, because I have a Postgres `ENUM` with a single
value, that caused a `rand.Intn(0)` call, which panics on zero.

See: https://golang.org/src/math/rand/rand.go?s=4112:4142#L129
2017-06-14 16:53:55 +03:00
Aaron L
553cc9f680 Odd circleci fix for syntax? 2017-06-08 20:58:31 -07:00
Aaron L
c69639e6d9 One more fix to circle file 2017-06-08 20:56:11 -07:00
Aaron L
226517279f Disable MSSQL tests until they run again
- The mssql image seems to have gotten an update that causes our tests
  to freeze instead of run, it seems to do with the create database
  calls but I haven't had time to look into it.
- Remove commented old code from circle file
2017-06-08 20:53:53 -07:00
Aaron L
9107c9dea1 Another instance of helper slices in eager code
- Another instance of helper slice types seeping in. Convert the slice
  when it's found as part of a singular's R struct.
- Fix #158
2017-06-08 20:50:35 -07:00
Aaron L
2168a70c4f Stop using aliases in the relationship select
- This caused issues with mysql who doesn't understand the syntax:
  "delete from x as y where y.id = ?"
2017-06-04 12:29:04 -07:00
Aaron L
466ea1f55f Fix another occurrency of XSlice cast failures
- When eager loading, we pull the values back out of the R struct, at
  this point it's possible to get the "poisoned" XSlice type that
  nothing can deal with again.
2017-06-04 12:03:57 -07:00
Aaron L
833fd04c6b Fix random typo 2017-06-04 11:19:03 -07:00
Aaron L
7e5374eb22 Bump SQL Server CI image version 2017-05-15 22:25:15 -07:00
Aaron L
696d572164 Merge branch 'viper' into dev 2017-05-15 22:01:44 -07:00
Aaron L
4896aae393 Merge branch 'sql-syntax-highlighting' into dev 2017-05-15 22:01:13 -07:00
Alex Macleod
9700787bf9 Highlight Enum SQL 2017-05-12 13:57:03 +01:00
Alex Macleod
7d38cba663 Fix viper link 2017-05-12 13:46:55 +01:00
Aaron L
17f2ec5108 Bump to 2.4.0 2017-05-08 19:19:12 -07:00
Aaron L
1d29e337e3 Merge branch 'guns/sort-tables' into dev 2017-05-08 19:14:25 -07:00
Aaron L
8e8100f5f0 Merge branch 'lbryio/mysql-uint-fix' into dev
- Fix #146
2017-05-08 19:14:02 -07:00
guns
e22d6cf77b Sort Table slice to ensure stable template output 2017-05-03 04:04:54 -05:00
36 changed files with 298 additions and 232 deletions

View file

@ -13,14 +13,14 @@ jobs:
environment: environment:
MYSQL_ROOT_PASSWORD: mysqlpassword MYSQL_ROOT_PASSWORD: mysqlpassword
- image: microsoft/mssql-server-linux:ctp1-4 # - image: microsoft/mssql-server-linux:ctp2-0
environment: # environment:
ACCEPT_EULA: 'Y' # ACCEPT_EULA: 'Y'
SA_PASSWORD: 'R@@tr@@t1234' # SA_PASSWORD: 'R@@tr@@t1234'
environment: environment:
GOPATH: /go GOPATH: /go
ROOTPATH: /go/src/github.com/vattle/sqlboiler ROOTPATH: /go/src/github.com/volatiletech/sqlboiler
steps: steps:
- run: - run:
@ -72,31 +72,31 @@ jobs:
sleep 1 sleep 1
done done
- run: # - run:
name: Wait for MSSQL # name: Wait for MSSQL
command: > # command: >
for i in `seq 30`; do # for i in `seq 30`; do
echo "Waiting for mssql" # echo "Waiting for mssql"
set +o errexit # set +o errexit
sqlcmd -H localhost -U sa -P R@@tr@@t1234 -Q "select * from information_schema.tables;" > /dev/null # sqlcmd -H localhost -U sa -P R@@tr@@t1234 -Q "select * from information_schema.tables;" > /dev/null
status=$? # status=$?
set -o errexit # set -o errexit
if [ $status -eq 0 ]; then # if [ $status -eq 0 ]; then
break # break
fi # fi
if [ $i -eq 30 ]; then # if [ $i -eq 30 ]; then
echo "Failed to wait for mssql" # echo "Failed to wait for mssql"
exit 1 # exit 1
fi # fi
sleep 1 # sleep 1
done # done
- run: - run:
name: Make GOPATH name: Make GOPATH
command: mkdir -p /go/src/github.com/vattle/sqlboiler command: mkdir -p /go/src/github.com/volatiletech/sqlboiler
- checkout: - checkout:
path: /go/src/github.com/vattle/sqlboiler path: /go/src/github.com/volatiletech/sqlboiler
- run: - run:
name: Create PSQL DB name: Create PSQL DB
@ -108,17 +108,17 @@ jobs:
command: | command: |
mysql --host localhost --execute 'create database sqlboiler;' mysql --host localhost --execute 'create database sqlboiler;'
mysql --host localhost --database sqlboiler < $ROOTPATH/testdata/mysql_test_schema.sql mysql --host localhost --database sqlboiler < $ROOTPATH/testdata/mysql_test_schema.sql
- run: # - run:
name: Create MSSQL DB # name: Create MSSQL DB
command: | # command: |
sqlcmd -S localhost -U sa -P R@@tr@@t1234 -Q "create database sqlboiler;" # sqlcmd -S localhost -U sa -P R@@tr@@t1234 -Q "create database sqlboiler;"
sqlcmd -S localhost -U sa -P R@@tr@@t1234 -d sqlboiler -i $ROOTPATH/testdata/mssql_test_schema.sql # sqlcmd -S localhost -U sa -P R@@tr@@t1234 -d sqlboiler -i $ROOTPATH/testdata/mssql_test_schema.sql
- run: - run:
name: Build SQLBoiler name: Build SQLBoiler
command: | command: |
cd $ROOTPATH; go get -v -t cd $ROOTPATH; go get -v -t
cd $ROOTPATH; go build -v github.com/vattle/sqlboiler cd $ROOTPATH; go build -v github.com/volatiletech/sqlboiler
- run: - run:
name: 'Configure SQLBoiler: PSQL' name: 'Configure SQLBoiler: PSQL'
@ -126,9 +126,9 @@ jobs:
- run: - run:
name: 'Configure SQLBoiler: MySQL' name: 'Configure SQLBoiler: MySQL'
command: echo -e '[mysql]\nhost="localhost"\nport=3306\nuser="root"\npass="mysqlpassword"\ndbname="sqlboiler"\nsslmode="false"\n' >> $ROOTPATH/sqlboiler.toml command: echo -e '[mysql]\nhost="localhost"\nport=3306\nuser="root"\npass="mysqlpassword"\ndbname="sqlboiler"\nsslmode="false"\n' >> $ROOTPATH/sqlboiler.toml
- run: # - run:
name: 'Configure SQLBoiler: MSSQL' # name: 'Configure SQLBoiler: MSSQL'
command: echo -e '[mssql]\nhost="localhost"\nport=1433\nuser="sa"\npass="R@@tr@@t1234"\ndbname="sqlboiler"\nsslmode="disable"\n' >> $ROOTPATH/sqlboiler.toml # command: echo -e '[mssql]\nhost="localhost"\nport=1433\nuser="sa"\npass="R@@tr@@t1234"\ndbname="sqlboiler"\nsslmode="disable"\n' >> $ROOTPATH/sqlboiler.toml
- run: - run:
name: 'Generate: PSQL' name: 'Generate: PSQL'
@ -136,9 +136,9 @@ jobs:
- run: - run:
name: 'Generate: MySQL' name: 'Generate: MySQL'
command: cd $ROOTPATH; ./sqlboiler -o mysql mysql command: cd $ROOTPATH; ./sqlboiler -o mysql mysql
- run: # - run:
name: 'Generate: MSSQL' # name: 'Generate: MSSQL'
command: cd $ROOTPATH; ./sqlboiler -o mssql mssql # command: cd $ROOTPATH; ./sqlboiler -o mssql mssql
- run: - run:
name: Download generated and test deps name: Download generated and test deps
@ -150,7 +150,7 @@ jobs:
name: Run Tests name: Run Tests
command: | command: |
cd $ROOTPATH cd $ROOTPATH
cp ./testdata/mssql_test_schema.sql mssql/tables_schema.sql #cp ./testdata/mssql_test_schema.sql mssql/tables_schema.sql
go test -v -race ./... | tee test_out.txt go test -v -race ./... | tee test_out.txt
- run: - run:
@ -161,48 +161,3 @@ jobs:
- store_test_results: - store_test_results:
path: test_results path: test_results
#test:
# pre:
# - echo -e "[postgres]\nhost=\"localhost\"\nport=5432\nuser=\"ubuntu\"\ndbname=\"sqlboiler\"\n" > sqlboiler.toml
# - createdb -U ubuntu sqlboiler
# - psql -U ubuntu sqlboiler < ./testdata/postgres_test_schema.sql
#
# - echo -e "[mysql]\nhost=\"localhost\"\nport=3306\nuser=\"ubuntu\"\ndbname=\"sqlboiler\"\nsslmode=\"false\"\n" >> sqlboiler.toml
# - echo "create database sqlboiler;" | mysql -u ubuntu
# - mysql -u ubuntu sqlboiler < ./testdata/mysql_test_schema.sql
#
# - echo -e "[mssql]\nhost=\"localhost\"\nport=1433\nuser=\"sa\"\ndbname=\"sqlboiler\"\nsslmode=\"disable\"\n" >> sqlboiler.toml
# - docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=R@@tr@@t1234' -p 1433:1433 -d --name mssql microsoft/mssql-server-linux
# - sqlcmd -S localhost -U sa -P R@@tr@@t1234 -Q "create database sqlboiler;"
# - sqlcmd -S localhost -U sa -P R@@tr@@t1234 -d sqlboiler -i ./testdata/mssql_test_schema.sql
#
# - ./sqlboiler -o postgres postgres
# - ./sqlboiler -o mysql mysql
# - ./sqlboiler -o mssql mssql
# - cp ./testdata/mssql_test_schema.sql mssql/tables_schema.sql
# override:
# - go test -v -race ./... > $CIRCLE_ARTIFACTS/gotest.txt
# post:
# - cat $CIRCLE_ARTIFACTS/gotest.txt | go-junit-report > $CIRCLE_TEST_REPORTS/junit.xml
#
#machine:
# environment:
# GODIST: go1.7.linux-amd64.tar.gz
# PATH: /home/ubuntu/.go_workspace/bin:/usr/local/go/bin:/home/ubuntu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/mssql-tools/bin
# post:
# - mkdir -p download
# - test -e download/$GODIST || curl -o download/$GODIST https://storage.googleapis.com/golang/$GODIST
# - sudo rm -rf /usr/local/go
# - sudo tar -C /usr/local -xzf download/$GODIST
#
#dependencies:
# pre:
# - mkdir -p /home/ubuntu/.go_workspace/src/github.com/jstemmer
# - go get -u github.com/jstemmer/go-junit-report
#
# - curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
# - curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
# - sudo apt-get update; sudo apt-get install mssql-tools unixodbc-dev
# - docker pull microsoft/mssql-server-linux
# cache_directories:
# - ~/download

View file

@ -1,4 +1,4 @@
Copyright (c) 2016 The SQLBoiler Authors. All rights reserved. Copyright (c) 2017 Volatile Technologies Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are modification, are permitted provided that the following conditions are
@ -10,9 +10,9 @@ notice, this list of conditions and the following disclaimer.
copyright notice, this list of conditions and the following disclaimer copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the in the documentation and/or other materials provided with the
distribution. distribution.
* Neither the name of Vattle nor the names of its * Neither the name of Vattle or Volatile Technologies Inc. nor the
contributors may be used to endorse or promote products derived from names of its contributors may be used to endorse or promote products
this software without specific prior written permission. derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

View file

@ -1,12 +1,12 @@
![sqlboiler logo](http://i.imgur.com/NJtCT7y.png) ![sqlboiler logo](http://i.imgur.com/ilkv0r9.png)
[![License](https://img.shields.io/badge/license-BSD-blue.svg)](https://github.com/vattle/sqlboiler/blob/master/LICENSE) [![License](https://img.shields.io/badge/license-BSD-blue.svg)](https://github.com/volatiletech/sqlboiler/blob/master/LICENSE)
[![GoDoc](https://godoc.org/github.com/vattle/sqlboiler?status.svg)](https://godoc.org/github.com/vattle/sqlboiler) [![GoDoc](https://godoc.org/github.com/volatiletech/sqlboiler?status.svg)](https://godoc.org/github.com/volatiletech/sqlboiler)
[![Mail](https://img.shields.io/badge/mail%20list-sqlboiler-lightgrey.svg)](https://groups.google.com/a/volatile.tech/forum/#!forum/sqlboiler) [![Mail](https://img.shields.io/badge/mail%20list-sqlboiler-lightgrey.svg)](https://groups.google.com/a/volatile.tech/forum/#!forum/sqlboiler)
[![Mail-Annc](https://img.shields.io/badge/mail%20list-sqlboiler--announce-lightgrey.svg)](https://groups.google.com/a/volatile.tech/forum/#!forum/sqlboiler-announce) [![Mail-Annc](https://img.shields.io/badge/mail%20list-sqlboiler--announce-lightgrey.svg)](https://groups.google.com/a/volatile.tech/forum/#!forum/sqlboiler-announce)
[![Slack](https://img.shields.io/badge/slack-%23general-lightgrey.svg)](https://sqlboiler.from-the.cloud) [![Slack](https://img.shields.io/badge/slack-%23general-lightgrey.svg)](https://sqlboiler.from-the.cloud)
[![CircleCI](https://circleci.com/gh/vattle/sqlboiler.svg?style=shield)](https://circleci.com/gh/vattle/sqlboiler) [![CircleCI](https://circleci.com/gh/volatiletech/sqlboiler.svg?style=shield)](https://circleci.com/gh/volatiletech/sqlboiler)
[![Go Report Card](https://goreportcard.com/badge/vattle/sqlboiler)](http://goreportcard.com/report/vattle/sqlboiler) [![Go Report Card](https://goreportcard.com/badge/volatiletech/sqlboiler)](http://goreportcard.com/report/volatiletech/sqlboiler)
SQLBoiler is a tool to generate a Go ORM tailored to your database schema. SQLBoiler is a tool to generate a Go ORM tailored to your database schema.
@ -76,6 +76,7 @@ Table of Contents
* [Reload](#reload) * [Reload](#reload)
* [Exists](#exists) * [Exists](#exists)
* [Enums](#enums) * [Enums](#enums)
* [Constants](#constants)
* [FAQ](#faq) * [FAQ](#faq)
* [Won't compiling models for a huge database be very slow?](#wont-compiling-models-for-a-huge-database-be-very-slow) * [Won't compiling models for a huge database be very slow?](#wont-compiling-models-for-a-huge-database-be-very-slow)
* [Missing imports for generated package](#missing-imports-for-generated-package) * [Missing imports for generated package](#missing-imports-for-generated-package)
@ -122,7 +123,7 @@ For a comprehensive list of available operations and examples please see [Featur
```go ```go
import ( import (
// Import this so we don't have to use qm.Limit etc. // Import this so we don't have to use qm.Limit etc.
. "github.com/vattle/sqlboiler/queries/qm" . "github.com/volatiletech/sqlboiler/queries/qm"
) )
// Open handle to database like normal // Open handle to database like normal
@ -214,12 +215,12 @@ fmt.Println(len(users.R.FavoriteMovies))
#### Download #### Download
```shell ```shell
go get -u -t github.com/vattle/sqlboiler go get -u -t github.com/volatiletech/sqlboiler
``` ```
#### Configuration #### Configuration
Create a configuration file. Because the project uses [viper](github.com/spf13/viper), TOML, JSON and YAML Create a configuration file. Because the project uses [viper](https://github.com/spf13/viper), TOML, JSON and YAML
are all supported. Environment variables are also able to be used. are all supported. Environment variables are also able to be used.
We will assume TOML for the rest of the documentation. We will assume TOML for the rest of the documentation.
@ -295,7 +296,7 @@ generate models for, we can invoke the sqlboiler command line utility.
```text ```text
SQL Boiler generates a Go ORM from template files, tailored to your database schema. SQL Boiler generates a Go ORM from template files, tailored to your database schema.
Complete documentation is available at http://github.com/vattle/sqlboiler Complete documentation is available at http://github.com/volatiletech/sqlboiler
Usage: Usage:
sqlboiler [flags] <driver> sqlboiler [flags] <driver>
@ -625,7 +626,7 @@ when performing query building. Here is a list of all of your generated query mo
```go ```go
// Dot import so we can access query mods directly instead of prefixing with "qm." // Dot import so we can access query mods directly instead of prefixing with "qm."
import . "github.com/vattle/sqlboiler/queries/qm" import . "github.com/volatiletech/sqlboiler/queries/qm"
// Use a raw query against a generated struct (Pilot in this example) // Use a raw query against a generated struct (Pilot in this example)
// If this query mod exists in your call, it will override the others. // If this query mod exists in your call, it will override the others.
@ -736,7 +737,7 @@ in combination with your own custom, non-generated model.
### Binding ### Binding
For a comprehensive ruleset for `Bind()` you can refer to our [godoc](https://godoc.org/github.com/vattle/sqlboiler/queries#Bind). For a comprehensive ruleset for `Bind()` you can refer to our [godoc](https://godoc.org/github.com/volatiletech/sqlboiler/queries#Bind).
The `Bind()` [Finisher](#finisher) allows the results of a query built with The `Bind()` [Finisher](#finisher) allows the results of a query built with
the [Raw SQL](#raw-query) method or the [Query Builder](#query-building) methods to be bound the [Raw SQL](#raw-query) method or the [Query Builder](#query-building) methods to be bound
@ -956,15 +957,16 @@ it with the `AddModelHook` method. Here is an example of a before insert hook:
```go ```go
// Define my hook function // Define my hook function
func myHook(exec boil.Executor, p *Pilot) { func myHook(exec boil.Executor, p *Pilot) error {
// Do stuff // Do stuff
return nil
} }
// Register my before insert hook for pilots // Register my before insert hook for pilots
models.AddPilotHook(boil.BeforeInsertHook, myHook) models.AddPilotHook(boil.BeforeInsertHook, myHook)
``` ```
Your `ModelHook` will always be defined as `func(boil.Executor, *Model)` Your `ModelHook` will always be defined as `func(boil.Executor, *Model) error`
### Transactions ### Transactions
@ -989,7 +991,7 @@ tx.Rollback()
``` ```
It's also worth noting that there's a way to take advantage of `boil.SetDB()` It's also worth noting that there's a way to take advantage of `boil.SetDB()`
by using the [boil.Begin()](https://godoc.org/github.com/vattle/sqlboiler/boil#Begin) function. by using the [boil.Begin()](https://godoc.org/github.com/volatiletech/sqlboiler/boil#Begin) function.
This opens a transaction using the globally stored database. This opens a transaction using the globally stored database.
### Debug Logging ### Debug Logging
@ -1025,10 +1027,10 @@ Find is used to find a single row by primary key:
```go ```go
// Retrieve pilot with all columns filled // Retrieve pilot with all columns filled
pilot, err := models.PilotFind(db, 1) pilot, err := models.FindPilot(db, 1)
// Retrieve a subset of column values // Retrieve a subset of column values
jet, err := models.JetFind(db, 1, "name", "color") jet, err := models.FindJet(db, 1, "name", "color")
``` ```
### Insert ### Insert
@ -1191,7 +1193,7 @@ exists, err := models.Pilots(db, Where("id=?", 5)).Exists()
If your MySQL or Postgres tables use enums we will generate constants that hold their values If your MySQL or Postgres tables use enums we will generate constants that hold their values
that you can use in your queries. For example: that you can use in your queries. For example:
``` ```sql
CREATE TYPE workday AS ENUM('monday', 'tuesday', 'wednesday', 'thursday', 'friday'); CREATE TYPE workday AS ENUM('monday', 'tuesday', 'wednesday', 'thursday', 'friday');
CREATE TABLE event_one ( CREATE TABLE event_one (
@ -1223,6 +1225,41 @@ still be able to use your generated library, and it will still work as expected,
to get the tests to pass in this event is to either use a parsable enum value or use a regular column to get the tests to pass in this event is to either use a parsable enum value or use a regular column
instead of an enum. instead of an enum.
### Constants
The models package will also contain some structs that contain all of the table and column
names harvested from the database at generation time.
For table names they're generated under `models.TableNames`:
```go
// Generated code from models package
var TableNames = struct {
Messages string
Purchases string
}{
Messages: "messages",
Purchases: "purchases",
}
// Usage example:
fmt.Println(models.TableNames.Messages)
```
```go
// Generated code from models package
var MessageColumns = struct {
ID string
PurchaseID string
}{
ID: "id",
PurchaseID: "purchase_id",
}
// Usage example:
fmt.Println(models.MessageColumns.ID)
```
## FAQ ## FAQ
#### Won't compiling models for a huge database be very slow? #### Won't compiling models for a huge database be very slow?
@ -1261,12 +1298,12 @@ You *must* use a DSN flag in MySQL connections, see: [Requirements](#requirement
#### Where is the homepage? #### Where is the homepage?
The homepage for the [SQLBoiler](https://github.com/vattle/sqlboiler) [Golang ORM](https://github.com/vattle/sqlboiler) The homepage for the [SQLBoiler](https://github.com/volatiletech/sqlboiler) [Golang ORM](https://github.com/volatiletech/sqlboiler)
generator is located at: https://github.com/vattle/sqlboiler generator is located at: https://github.com/volatiletech/sqlboiler
## Benchmarks ## Benchmarks
If you'd like to run the benchmarks yourself check out our [boilbench](https://github.com/vattle/boilbench) repo. If you'd like to run the benchmarks yourself check out our [boilbench](https://github.com/volatiletech/boilbench) repo.
```bash ```bash
go test -bench . -benchmem go test -bench . -benchmem

View file

@ -3,7 +3,7 @@ package bdb
import ( import (
"strings" "strings"
"github.com/vattle/sqlboiler/strmangle" "github.com/volatiletech/sqlboiler/strmangle"
) )
// Column holds information about a database column. // Column holds information about a database column.

View file

@ -1,8 +1,8 @@
package drivers package drivers
import ( import (
"github.com/vattle/sqlboiler/bdb" "github.com/volatiletech/sqlboiler/bdb"
"github.com/vattle/sqlboiler/strmangle" "github.com/volatiletech/sqlboiler/strmangle"
) )
// MockDriver is a mock implementation of the bdb driver Interface // MockDriver is a mock implementation of the bdb driver Interface

View file

@ -8,7 +8,7 @@ import (
_ "github.com/denisenkom/go-mssqldb" _ "github.com/denisenkom/go-mssqldb"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/vattle/sqlboiler/bdb" "github.com/volatiletech/sqlboiler/bdb"
) )
// MSSQLDriver holds the database connection string and a handle // MSSQLDriver holds the database connection string and a handle

View file

@ -8,7 +8,7 @@ import (
"github.com/go-sql-driver/mysql" "github.com/go-sql-driver/mysql"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/vattle/sqlboiler/bdb" "github.com/volatiletech/sqlboiler/bdb"
) )
// TinyintAsBool is a global that is set from main.go if a user specifies // TinyintAsBool is a global that is set from main.go if a user specifies
@ -306,7 +306,7 @@ func (m *MySQLDriver) TranslateColumnType(c bdb.Column) bdb.Column {
if unsigned { if unsigned {
c.Type = "null.Uint64" c.Type = "null.Uint64"
} else { } else {
c.Type = "null.Uint64" c.Type = "null.Int64"
} }
case "float": case "float":
c.Type = "null.Float32" c.Type = "null.Float32"

View file

@ -10,8 +10,8 @@ import (
_ "github.com/lib/pq" _ "github.com/lib/pq"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/vattle/sqlboiler/bdb" "github.com/volatiletech/sqlboiler/bdb"
"github.com/vattle/sqlboiler/strmangle" "github.com/volatiletech/sqlboiler/strmangle"
) )
// PostgresDriver holds the database connection string and a handle // PostgresDriver holds the database connection string and a handle

View file

@ -1,7 +1,11 @@
// Package bdb supplies the sql(b)oiler (d)ata(b)ase abstractions. // Package bdb supplies the sql(b)oiler (d)ata(b)ase abstractions.
package bdb package bdb
import "github.com/pkg/errors" import (
"sort"
"github.com/pkg/errors"
)
// Interface for a database driver. Functionality required to support a specific // Interface for a database driver. Functionality required to support a specific
// database type (eg, MySQL, Postgres etc.) // database type (eg, MySQL, Postgres etc.)
@ -45,6 +49,8 @@ func Tables(db Interface, schema string, whitelist, blacklist []string) ([]Table
return nil, errors.Wrap(err, "unable to get table names") return nil, errors.Wrap(err, "unable to get table names")
} }
sort.Strings(names)
var tables []Table var tables []Table
for _, name := range names { for _, name := range names {
t := Table{ t := Table{

View file

@ -3,7 +3,7 @@ package bdb
import ( import (
"testing" "testing"
"github.com/vattle/sqlboiler/strmangle" "github.com/volatiletech/sqlboiler/strmangle"
) )
type testMockDriver struct{} type testMockDriver struct{}
@ -124,6 +124,14 @@ func TestTables(t *testing.T) {
t.Errorf("Expected len 7, got: %d\n", len(tables)) t.Errorf("Expected len 7, got: %d\n", len(tables))
} }
prev := ""
for i := range tables {
if prev >= tables[i].Name {
t.Error("tables are not sorted")
}
prev = tables[i].Name
}
pilots := GetTable(tables, "pilots") pilots := GetTable(tables, "pilots")
if len(pilots.Columns) != 2 { if len(pilots.Columns) != 2 {
t.Error() t.Error()

View file

@ -19,6 +19,11 @@ type Transactor interface {
// Beginner begins transactions. // Beginner begins transactions.
type Beginner interface { type Beginner interface {
Begin() (Transactor, error)
}
// SQLBeginner begins transactions (non-interface return type)
type SQLBeginner interface {
Begin() (*sql.Tx, error) Begin() (*sql.Tx, error)
} }
@ -26,8 +31,12 @@ type Beginner interface {
func Begin() (Transactor, error) { func Begin() (Transactor, error) {
creator, ok := currentDB.(Beginner) creator, ok := currentDB.(Beginner)
if !ok { if !ok {
creator2, ok2 := currentDB.(SQLBeginner)
if !ok2 {
panic("database does not support transactions") panic("database does not support transactions")
} }
return creator2.Begin()
}
return creator.Begin() return creator.Begin()
} }

View file

@ -13,10 +13,10 @@ import (
"text/template" "text/template"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/vattle/sqlboiler/bdb" "github.com/volatiletech/sqlboiler/bdb"
"github.com/vattle/sqlboiler/bdb/drivers" "github.com/volatiletech/sqlboiler/bdb/drivers"
"github.com/vattle/sqlboiler/queries" "github.com/volatiletech/sqlboiler/queries"
"github.com/vattle/sqlboiler/strmangle" "github.com/volatiletech/sqlboiler/strmangle"
) )
const ( const (
@ -267,7 +267,7 @@ func (s *State) processReplacements() error {
return nil return nil
} }
var basePackage = "github.com/vattle/sqlboiler" var basePackage = "github.com/volatiletech/sqlboiler"
func getBasePath(baseDirConfig string) (string, error) { func getBasePath(baseDirConfig string) (string, error) {
if len(baseDirConfig) > 0 { if len(baseDirConfig) > 0 {

View file

@ -6,7 +6,7 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/vattle/sqlboiler/bdb" "github.com/volatiletech/sqlboiler/bdb"
) )
// imports defines the optional standard imports and // imports defines the optional standard imports and
@ -171,25 +171,25 @@ func newImporter() importer {
}, },
thirdParty: importList{ thirdParty: importList{
`"github.com/pkg/errors"`, `"github.com/pkg/errors"`,
`"github.com/vattle/sqlboiler/boil"`, `"github.com/volatiletech/sqlboiler/boil"`,
`"github.com/vattle/sqlboiler/queries"`, `"github.com/volatiletech/sqlboiler/queries"`,
`"github.com/vattle/sqlboiler/queries/qm"`, `"github.com/volatiletech/sqlboiler/queries/qm"`,
`"github.com/vattle/sqlboiler/strmangle"`, `"github.com/volatiletech/sqlboiler/strmangle"`,
}, },
} }
imp.Singleton = mapImports{ imp.Singleton = mapImports{
"boil_queries": { "boil_queries": {
thirdParty: importList{ thirdParty: importList{
`"github.com/vattle/sqlboiler/boil"`, `"github.com/volatiletech/sqlboiler/boil"`,
`"github.com/vattle/sqlboiler/queries"`, `"github.com/volatiletech/sqlboiler/queries"`,
`"github.com/vattle/sqlboiler/queries/qm"`, `"github.com/volatiletech/sqlboiler/queries/qm"`,
}, },
}, },
"boil_types": { "boil_types": {
thirdParty: importList{ thirdParty: importList{
`"github.com/pkg/errors"`, `"github.com/pkg/errors"`,
`"github.com/vattle/sqlboiler/strmangle"`, `"github.com/volatiletech/sqlboiler/strmangle"`,
}, },
}, },
} }
@ -201,9 +201,9 @@ func newImporter() importer {
`"testing"`, `"testing"`,
}, },
thirdParty: importList{ thirdParty: importList{
`"github.com/vattle/sqlboiler/boil"`, `"github.com/volatiletech/sqlboiler/boil"`,
`"github.com/vattle/sqlboiler/randomize"`, `"github.com/volatiletech/sqlboiler/randomize"`,
`"github.com/vattle/sqlboiler/strmangle"`, `"github.com/volatiletech/sqlboiler/strmangle"`,
}, },
} }
@ -223,7 +223,7 @@ func newImporter() importer {
`"github.com/kat-co/vala"`, `"github.com/kat-co/vala"`,
`"github.com/pkg/errors"`, `"github.com/pkg/errors"`,
`"github.com/spf13/viper"`, `"github.com/spf13/viper"`,
`"github.com/vattle/sqlboiler/boil"`, `"github.com/volatiletech/sqlboiler/boil"`,
}, },
}, },
"boil_queries_test": { "boil_queries_test": {
@ -236,7 +236,7 @@ func newImporter() importer {
`"regexp"`, `"regexp"`,
}, },
thirdParty: importList{ thirdParty: importList{
`"github.com/vattle/sqlboiler/boil"`, `"github.com/volatiletech/sqlboiler/boil"`,
}, },
}, },
"boil_suites_test": { "boil_suites_test": {
@ -261,8 +261,8 @@ func newImporter() importer {
thirdParty: importList{ thirdParty: importList{
`"github.com/pkg/errors"`, `"github.com/pkg/errors"`,
`"github.com/spf13/viper"`, `"github.com/spf13/viper"`,
`"github.com/vattle/sqlboiler/bdb/drivers"`, `"github.com/volatiletech/sqlboiler/bdb/drivers"`,
`"github.com/vattle/sqlboiler/randomize"`, `"github.com/volatiletech/sqlboiler/randomize"`,
`_ "github.com/lib/pq"`, `_ "github.com/lib/pq"`,
}, },
}, },
@ -280,8 +280,8 @@ func newImporter() importer {
thirdParty: importList{ thirdParty: importList{
`"github.com/pkg/errors"`, `"github.com/pkg/errors"`,
`"github.com/spf13/viper"`, `"github.com/spf13/viper"`,
`"github.com/vattle/sqlboiler/bdb/drivers"`, `"github.com/volatiletech/sqlboiler/bdb/drivers"`,
`"github.com/vattle/sqlboiler/randomize"`, `"github.com/volatiletech/sqlboiler/randomize"`,
`_ "github.com/go-sql-driver/mysql"`, `_ "github.com/go-sql-driver/mysql"`,
}, },
}, },
@ -297,8 +297,8 @@ func newImporter() importer {
thirdParty: importList{ thirdParty: importList{
`"github.com/pkg/errors"`, `"github.com/pkg/errors"`,
`"github.com/spf13/viper"`, `"github.com/spf13/viper"`,
`"github.com/vattle/sqlboiler/bdb/drivers"`, `"github.com/volatiletech/sqlboiler/bdb/drivers"`,
`"github.com/vattle/sqlboiler/randomize"`, `"github.com/volatiletech/sqlboiler/randomize"`,
`_ "github.com/denisenkom/go-mssqldb"`, `_ "github.com/denisenkom/go-mssqldb"`,
}, },
}, },
@ -309,79 +309,79 @@ func newImporter() importer {
// TranslateColumnType to see the type assignments. // TranslateColumnType to see the type assignments.
imp.BasedOnType = mapImports{ imp.BasedOnType = mapImports{
"null.Float32": { "null.Float32": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"null.Float64": { "null.Float64": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"null.Int": { "null.Int": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"null.Int8": { "null.Int8": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"null.Int16": { "null.Int16": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"null.Int32": { "null.Int32": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"null.Int64": { "null.Int64": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"null.Uint": { "null.Uint": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"null.Uint8": { "null.Uint8": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"null.Uint16": { "null.Uint16": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"null.Uint32": { "null.Uint32": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"null.Uint64": { "null.Uint64": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"null.String": { "null.String": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"null.Bool": { "null.Bool": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"null.Time": { "null.Time": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"null.JSON": { "null.JSON": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"null.Bytes": { "null.Bytes": {
thirdParty: importList{`"gopkg.in/nullbio/null.v6"`}, thirdParty: importList{`"gopkg.in/volatiletech/null.v6"`},
}, },
"time.Time": { "time.Time": {
standard: importList{`"time"`}, standard: importList{`"time"`},
}, },
"types.JSON": { "types.JSON": {
thirdParty: importList{`"github.com/vattle/sqlboiler/types"`}, thirdParty: importList{`"github.com/volatiletech/sqlboiler/types"`},
}, },
"types.BytesArray": { "types.BytesArray": {
thirdParty: importList{`"github.com/vattle/sqlboiler/types"`}, thirdParty: importList{`"github.com/volatiletech/sqlboiler/types"`},
}, },
"types.Int64Array": { "types.Int64Array": {
thirdParty: importList{`"github.com/vattle/sqlboiler/types"`}, thirdParty: importList{`"github.com/volatiletech/sqlboiler/types"`},
}, },
"types.Float64Array": { "types.Float64Array": {
thirdParty: importList{`"github.com/vattle/sqlboiler/types"`}, thirdParty: importList{`"github.com/volatiletech/sqlboiler/types"`},
}, },
"types.BoolArray": { "types.BoolArray": {
thirdParty: importList{`"github.com/vattle/sqlboiler/types"`}, thirdParty: importList{`"github.com/volatiletech/sqlboiler/types"`},
}, },
"types.StringArray": { "types.StringArray": {
thirdParty: importList{`"github.com/vattle/sqlboiler/types"`}, thirdParty: importList{`"github.com/volatiletech/sqlboiler/types"`},
}, },
"types.Hstore": { "types.Hstore": {
thirdParty: importList{`"github.com/vattle/sqlboiler/types"`}, thirdParty: importList{`"github.com/volatiletech/sqlboiler/types"`},
}, },
} }

View file

@ -6,7 +6,7 @@ import (
"testing" "testing"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/vattle/sqlboiler/bdb" "github.com/volatiletech/sqlboiler/bdb"
) )
func TestImportsSort(t *testing.T) { func TestImportsSort(t *testing.T) {
@ -234,7 +234,7 @@ func TestCombineTypeImports(t *testing.T) {
`"fmt"`, `"fmt"`,
}, },
thirdParty: importList{ thirdParty: importList{
`"github.com/vattle/sqlboiler/boil"`, `"github.com/volatiletech/sqlboiler/boil"`,
}, },
} }
@ -245,8 +245,8 @@ func TestCombineTypeImports(t *testing.T) {
`"time"`, `"time"`,
}, },
thirdParty: importList{ thirdParty: importList{
`"github.com/vattle/sqlboiler/boil"`, `"github.com/volatiletech/sqlboiler/boil"`,
`"gopkg.in/nullbio/null.v6"`, `"gopkg.in/volatiletech/null.v6"`,
}, },
} }
@ -280,8 +280,8 @@ func TestCombineTypeImports(t *testing.T) {
`"time"`, `"time"`,
}, },
thirdParty: importList{ thirdParty: importList{
`"github.com/vattle/sqlboiler/boil"`, `"github.com/volatiletech/sqlboiler/boil"`,
`"gopkg.in/nullbio/null.v6"`, `"gopkg.in/volatiletech/null.v6"`,
}, },
} }
@ -297,11 +297,11 @@ func TestCombineImports(t *testing.T) {
a := imports{ a := imports{
standard: importList{"fmt"}, standard: importList{"fmt"},
thirdParty: importList{"github.com/vattle/sqlboiler", "gopkg.in/nullbio/null.v6"}, thirdParty: importList{"github.com/volatiletech/sqlboiler", "gopkg.in/volatiletech/null.v6"},
} }
b := imports{ b := imports{
standard: importList{"os"}, standard: importList{"os"},
thirdParty: importList{"github.com/vattle/sqlboiler"}, thirdParty: importList{"github.com/volatiletech/sqlboiler"},
} }
c := combineImports(a, b) c := combineImports(a, b)
@ -309,8 +309,8 @@ func TestCombineImports(t *testing.T) {
if c.standard[0] != "fmt" && c.standard[1] != "os" { if c.standard[0] != "fmt" && c.standard[1] != "os" {
t.Errorf("Wanted: fmt, os got: %#v", c.standard) t.Errorf("Wanted: fmt, os got: %#v", c.standard)
} }
if c.thirdParty[0] != "github.com/vattle/sqlboiler" && c.thirdParty[1] != "gopkg.in/nullbio/null.v6" { if c.thirdParty[0] != "github.com/volatiletech/sqlboiler" && c.thirdParty[1] != "gopkg.in/volatiletech/null.v6" {
t.Errorf("Wanted: github.com/vattle/sqlboiler, gopkg.in/nullbio/null.v6 got: %#v", c.thirdParty) t.Errorf("Wanted: github.com/volatiletech/sqlboiler, gopkg.in/volatiletech/null.v6 got: %#v", c.thirdParty)
} }
} }

View file

@ -14,7 +14,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
) )
var noEditDisclaimer = []byte(`// This file is generated by SQLBoiler (https://github.com/vattle/sqlboiler) var noEditDisclaimer = []byte(`// This file is generated by SQLBoiler (https://github.com/volatiletech/sqlboiler)
// and is meant to be re-generated in place and/or deleted at any time. // and is meant to be re-generated in place and/or deleted at any time.
// DO NOT EDIT // DO NOT EDIT

View file

@ -9,9 +9,9 @@ import (
"text/template" "text/template"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/vattle/sqlboiler/bdb" "github.com/volatiletech/sqlboiler/bdb"
"github.com/vattle/sqlboiler/queries" "github.com/volatiletech/sqlboiler/queries"
"github.com/vattle/sqlboiler/strmangle" "github.com/volatiletech/sqlboiler/strmangle"
) )
// templateData for sqlboiler templates // templateData for sqlboiler templates

View file

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/vattle/sqlboiler/bdb" "github.com/volatiletech/sqlboiler/bdb"
"github.com/vattle/sqlboiler/strmangle" "github.com/volatiletech/sqlboiler/strmangle"
) )
// TxtToOne contains text that will be used by templates for a one-to-many or // TxtToOne contains text that will be used by templates for a one-to-many or

View file

@ -5,8 +5,8 @@ import (
"testing" "testing"
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/vattle/sqlboiler/bdb" "github.com/volatiletech/sqlboiler/bdb"
"github.com/vattle/sqlboiler/bdb/drivers" "github.com/volatiletech/sqlboiler/bdb/drivers"
) )
func TestTxtsFromOne(t *testing.T) { func TestTxtsFromOne(t *testing.T) {

View file

@ -10,11 +10,11 @@ import (
"github.com/kat-co/vala" "github.com/kat-co/vala"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/vattle/sqlboiler/bdb/drivers" "github.com/volatiletech/sqlboiler/bdb/drivers"
"github.com/vattle/sqlboiler/boilingcore" "github.com/volatiletech/sqlboiler/boilingcore"
) )
const sqlBoilerVersion = "2.3.0" const sqlBoilerVersion = "2.5.1"
var ( var (
cmdState *boilingcore.State cmdState *boilingcore.State
@ -62,7 +62,7 @@ func main() {
Use: "sqlboiler [flags] <driver>", Use: "sqlboiler [flags] <driver>",
Short: "SQL Boiler generates an ORM tailored to your database schema.", Short: "SQL Boiler generates an ORM tailored to your database schema.",
Long: "SQL Boiler generates a Go ORM from template files, tailored to your database schema.\n" + Long: "SQL Boiler generates a Go ORM from template files, tailored to your database schema.\n" +
`Complete documentation is available at http://github.com/vattle/sqlboiler`, `Complete documentation is available at http://github.com/volatiletech/sqlboiler`,
Example: `sqlboiler postgres`, Example: `sqlboiler postgres`,
PreRunE: preRun, PreRunE: preRun,
RunE: run, RunE: run,

View file

@ -6,8 +6,8 @@ import (
"strings" "strings"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/vattle/sqlboiler/boil" "github.com/volatiletech/sqlboiler/boil"
"github.com/vattle/sqlboiler/strmangle" "github.com/volatiletech/sqlboiler/strmangle"
) )
type loadRelationshipState struct { type loadRelationshipState struct {
@ -206,9 +206,16 @@ func (l loadRelationshipState) loadRelationshipsRecurse(depth int, obj reflect.V
} }
bkind := kindStruct bkind := kindStruct
if reflect.Indirect(loadedObject).Kind() != reflect.Struct { if derefed := reflect.Indirect(loadedObject); derefed.Kind() != reflect.Struct {
bkind = kindPtrSliceStruct bkind = kindPtrSliceStruct
loadedObject = loadedObject.Addr()
// Convert away any helper slice types
// elemType is *elem (from []*elem or helperSliceType)
// sliceType is *[]*elem
elemType := derefed.Type().Elem()
sliceType := reflect.PtrTo(reflect.SliceOf(elemType))
loadedObject = loadedObject.Addr().Convert(sliceType)
} }
return l.loadRelationships(depth+1, loadedObject.Interface(), bkind) return l.loadRelationships(depth+1, loadedObject.Interface(), bkind)
} }
@ -241,6 +248,9 @@ func collectLoaded(key string, loadingFrom reflect.Value) (reflect.Value, bindKi
if loadedType.Elem().Kind() == reflect.Struct { if loadedType.Elem().Kind() == reflect.Struct {
bkind = kindStruct bkind = kindStruct
loadedType = reflect.SliceOf(loadedType) loadedType = reflect.SliceOf(loadedType)
} else {
// Ensure that we get rid of all the helper "XSlice" types
loadedType = reflect.SliceOf(loadedType.Elem())
} }
collection := reflect.MakeSlice(loadedType, 0, 0) collection := reflect.MakeSlice(loadedType, 0, 0)

View file

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/vattle/sqlboiler/boil" "github.com/volatiletech/sqlboiler/boil"
) )
var testEagerCounters struct { var testEagerCounters struct {

View file

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"reflect" "reflect"
"github.com/vattle/sqlboiler/strmangle" "github.com/volatiletech/sqlboiler/strmangle"
) )
// NonZeroDefaultSet returns the fields included in the // NonZeroDefaultSet returns the fields included in the

View file

@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
null "gopkg.in/nullbio/null.v6" null "gopkg.in/volatiletech/null.v6"
) )
type testObj struct { type testObj struct {

View file

@ -1,6 +1,6 @@
package qm package qm
import "github.com/vattle/sqlboiler/queries" import "github.com/volatiletech/sqlboiler/queries"
// QueryMod to modify the query object // QueryMod to modify the query object
type QueryMod func(q *queries.Query) type QueryMod func(q *queries.Query)

View file

@ -4,7 +4,7 @@ import (
"database/sql" "database/sql"
"fmt" "fmt"
"github.com/vattle/sqlboiler/boil" "github.com/volatiletech/sqlboiler/boil"
) )
// joinKind is the type of join // joinKind is the type of join
@ -188,6 +188,11 @@ func SetSelect(q *Query, sel []string) {
q.selectCols = sel q.selectCols = sel
} }
// GetSelect from the query
func GetSelect(q *Query) []string {
return q.selectCols
}
// SetCount on the query. // SetCount on the query.
func SetCount(q *Query) { func SetCount(q *Query) {
q.count = true q.count = true

View file

@ -7,7 +7,7 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/vattle/sqlboiler/strmangle" "github.com/volatiletech/sqlboiler/strmangle"
) )
var ( var (

View file

@ -8,8 +8,8 @@ import (
"sync" "sync"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/vattle/sqlboiler/boil" "github.com/volatiletech/sqlboiler/boil"
"github.com/vattle/sqlboiler/strmangle" "github.com/volatiletech/sqlboiler/strmangle"
) )
var ( var (

View file

@ -14,12 +14,12 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
null "gopkg.in/nullbio/null.v6" null "gopkg.in/volatiletech/null.v6"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/satori/go.uuid" "github.com/satori/go.uuid"
"github.com/vattle/sqlboiler/strmangle" "github.com/volatiletech/sqlboiler/strmangle"
"github.com/vattle/sqlboiler/types" "github.com/volatiletech/sqlboiler/types"
) )
var ( var (
@ -159,18 +159,17 @@ func randDate(s *Seed) time.Time {
// If canBeNull is true: // If canBeNull is true:
// The value has the possibility of being null or non-zero at random. // The value has the possibility of being null or non-zero at random.
func randomizeField(s *Seed, field reflect.Value, fieldType string, canBeNull bool) error { func randomizeField(s *Seed, field reflect.Value, fieldType string, canBeNull bool) error {
kind := field.Kind() kind := field.Kind()
typ := field.Type() typ := field.Type()
if strings.HasPrefix(fieldType, "enum") { if strings.HasPrefix(fieldType, "enum") {
enum, err := randEnumValue(fieldType) enum, err := randEnumValue(s, fieldType)
if err != nil { if err != nil {
return err return err
} }
if kind == reflect.Struct { if kind == reflect.Struct {
val := null.NewString(enum, rand.Intn(1) == 0) val := null.NewString(enum, s.nextInt()%2 == 0)
field.Set(reflect.ValueOf(val)) field.Set(reflect.ValueOf(val))
} else { } else {
field.Set(reflect.ValueOf(enum)) field.Set(reflect.ValueOf(enum))
@ -623,11 +622,11 @@ func getVariableRandValue(s *Seed, kind reflect.Kind, typ reflect.Type) interfac
return nil return nil
} }
func randEnumValue(enum string) (string, error) { func randEnumValue(s *Seed, enum string) (string, error) {
vals := strmangle.ParseEnumVals(enum) vals := strmangle.ParseEnumVals(enum)
if vals == nil || len(vals) == 0 { if vals == nil || len(vals) == 0 {
return "", fmt.Errorf("unable to parse enum string: %s", enum) return "", fmt.Errorf("unable to parse enum string: %s", enum)
} }
return vals[rand.Intn(len(vals)-1)], nil return vals[s.nextInt()%len(vals)], nil
} }

View file

@ -5,7 +5,7 @@ import (
"testing" "testing"
"time" "time"
null "gopkg.in/nullbio/null.v6" null "gopkg.in/volatiletech/null.v6"
) )
func TestRandomizeStruct(t *testing.T) { func TestRandomizeStruct(t *testing.T) {
@ -148,24 +148,36 @@ func TestRandomizeField(t *testing.T) {
func TestRandEnumValue(t *testing.T) { func TestRandEnumValue(t *testing.T) {
t.Parallel() t.Parallel()
s := NewSeed()
enum1 := "enum.workday('monday','tuesday')" enum1 := "enum.workday('monday','tuesday')"
enum2 := "enum('monday','tuesday')" enum2 := "enum('monday','tuesday')"
enum3 := "enum('monday')"
r1, err := randEnumValue(enum1) r1, err := randEnumValue(s, enum1)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
if r1 != "monday" && r1 != "tuesday" { if r1 != "monday" && r1 != "tuesday" {
t.Errorf("Expected monday or tueday, got: %q", r1) t.Errorf("Expected monday or tuesday, got: %q", r1)
} }
r2, err := randEnumValue(enum2) r2, err := randEnumValue(s, enum2)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
if r2 != "monday" && r2 != "tuesday" { if r2 != "monday" && r2 != "tuesday" {
t.Errorf("Expected monday or tueday, got: %q", r2) t.Errorf("Expected monday or tuesday, got: %q", r2)
}
r3, err := randEnumValue(s, enum3)
if err != nil {
t.Error(err)
}
if r3 != "monday" {
t.Errorf("Expected monday got: %q", r3)
} }
} }

View file

@ -1,6 +1,6 @@
package strmangle package strmangle
import "github.com/nullbio/inflect" import "github.com/volatiletech/inflect"
var boilRuleset *inflect.Ruleset var boilRuleset *inflect.Ruleset
@ -193,6 +193,7 @@ func newBoilRuleset() *inflect.Ruleset {
rs.AddSingularExact("is", "is", true) rs.AddSingularExact("is", "is", true)
rs.AddSingularExact("us", "us", true) rs.AddSingularExact("us", "us", true)
rs.AddSingularExact("as", "as", true) rs.AddSingularExact("as", "as", true)
rs.AddSingularExact("areas", "area", true)
rs.AddPluralExact("a", "a", true) rs.AddPluralExact("a", "a", true)
rs.AddPluralExact("i", "i", true) rs.AddPluralExact("i", "i", true)
rs.AddPluralExact("is", "is", true) rs.AddPluralExact("is", "is", true)

View file

@ -93,7 +93,7 @@ func SchemaTable(lq, rq string, driver string, schema string, table string) stri
return fmt.Sprintf(`%s%s%s`, lq, table, rq) return fmt.Sprintf(`%s%s%s`, lq, table, rq)
} }
// IdentQuote attempts to quote simple identifiers in SQL tatements // IdentQuote attempts to quote simple identifiers in SQL statements
func IdentQuote(lq byte, rq byte, s string) string { func IdentQuote(lq byte, rq byte, s string) string {
if strings.ToLower(s) == "null" || s == "?" { if strings.ToLower(s) == "null" || s == "?" {
return s return s

View file

@ -139,6 +139,7 @@ func TestSingular(t *testing.T) {
{"hello_people", "hello_person"}, {"hello_people", "hello_person"},
{"hello_person", "hello_person"}, {"hello_person", "hello_person"},
{"friends", "friend"}, {"friends", "friend"},
{"areas", "area"},
{"hello_there_people", "hello_there_person"}, {"hello_there_people", "hello_there_person"},
} }
@ -159,6 +160,7 @@ func TestPlural(t *testing.T) {
{"hello_person", "hello_people"}, {"hello_person", "hello_people"},
{"friend", "friends"}, {"friend", "friends"},
{"friends", "friends"}, {"friends", "friends"},
{"area", "areas"},
{"hello_there_person", "hello_there_people"}, {"hello_there_person", "hello_there_people"},
} }

View file

@ -17,6 +17,16 @@ type {{$modelName}} struct {
{{end -}} {{end -}}
} }
var {{$modelName}}Columns = struct {
{{range $column := .Table.Columns -}}
{{titleCase $column.Name}} string
{{end -}}
}{
{{range $column := .Table.Columns -}}
{{titleCase $column.Name}}: "{{$column.Name}}",
{{end -}}
}
{{- if .Table.IsJoinTable -}} {{- if .Table.IsJoinTable -}}
{{- else}} {{- else}}
// {{$modelNameCamel}}R is where relationships are stored. // {{$modelNameCamel}}R is where relationships are stored.

View file

@ -15,27 +15,30 @@ func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}G(mods ...qm.QueryMod
// {{$txt.Function.Name}} retrieves all the {{.ForeignTable | singular}}'s {{$txt.ForeignTable.NameHumanReadable}} with an executor // {{$txt.Function.Name}} retrieves all the {{.ForeignTable | singular}}'s {{$txt.ForeignTable.NameHumanReadable}} with an executor
{{- if not (eq $txt.Function.Name $txt.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}. {{- if not (eq $txt.Function.Name $txt.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}.
func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}(exec boil.Executor, mods ...qm.QueryMod) {{$varNameSingular}}Query { func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}(exec boil.Executor, mods ...qm.QueryMod) {{$varNameSingular}}Query {
queryMods := []qm.QueryMod{ var queryMods []qm.QueryMod
qm.Select("{{id 0 | $dot.Quotes}}.*"),
}
if len(mods) != 0 { if len(mods) != 0 {
queryMods = append(queryMods, mods...) queryMods = append(queryMods, mods...)
} }
{{if .ToJoinTable -}} {{if .ToJoinTable -}}
queryMods = append(queryMods, queryMods = append(queryMods,
qm.InnerJoin("{{.JoinTable | $dot.SchemaTable}} as {{id 1 | $dot.Quotes}} on {{id 0 | $dot.Quotes}}.{{.ForeignColumn | $dot.Quotes}} = {{id 1 | $dot.Quotes}}.{{.JoinForeignColumn | $dot.Quotes}}"), {{$schemaJoinTable := .JoinTable | $.SchemaTable -}}
qm.Where("{{id 1 | $dot.Quotes}}.{{.JoinLocalColumn | $dot.Quotes}}=?", o.{{$txt.LocalTable.ColumnNameGo}}), qm.InnerJoin("{{$schemaJoinTable}} on {{$schemaForeignTable}}.{{.ForeignColumn | $dot.Quotes}} = {{$schemaJoinTable}}.{{.JoinForeignColumn | $dot.Quotes}}"),
qm.Where("{{$schemaJoinTable}}.{{.JoinLocalColumn | $dot.Quotes}}=?", o.{{$txt.LocalTable.ColumnNameGo}}),
) )
{{else -}} {{else -}}
queryMods = append(queryMods, queryMods = append(queryMods,
qm.Where("{{id 0 | $dot.Quotes}}.{{.ForeignColumn | $dot.Quotes}}=?", o.{{$txt.LocalTable.ColumnNameGo}}), qm.Where("{{$schemaForeignTable}}.{{.ForeignColumn | $dot.Quotes}}=?", o.{{$txt.LocalTable.ColumnNameGo}}),
) )
{{end}} {{end}}
query := {{$txt.ForeignTable.NamePluralGo}}(exec, queryMods...) query := {{$txt.ForeignTable.NamePluralGo}}(exec, queryMods...)
queries.SetFrom(query.Query, "{{$schemaForeignTable}} as {{id 0 | $dot.Quotes}}") queries.SetFrom(query.Query, "{{$schemaForeignTable}}")
if len(queries.GetSelect(query.Query)) == 0 {
queries.SetSelect(query.Query, []string{"{{$schemaForeignTable}}.*"})
}
return query return query
} }

View file

@ -0,0 +1,9 @@
var TableNames = struct {
{{range $table := .Tables -}}
{{titleCase $table.Name}} string
{{end -}}
}{
{{range $table := .Tables -}}
{{titleCase $table.Name}}: "{{$table.Name}}",
{{end -}}
}

View file

@ -13,10 +13,10 @@ func test{{$txt.LocalTable.NameGo}}ToOne{{$txt.ForeignTable.NameGo}}Using{{$txt.
var foreign {{$txt.ForeignTable.NameGo}} var foreign {{$txt.ForeignTable.NameGo}}
seed := randomize.NewSeed() seed := randomize.NewSeed()
if err := randomize.Struct(seed, &local, {{$varNameSingular}}DBTypes, true, {{$varNameSingular}}ColumnsWithDefault...); err != nil { if err := randomize.Struct(seed, &local, {{$varNameSingular}}DBTypes, {{if .Nullable}}true{{else}}false{{end}}, {{$varNameSingular}}ColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize {{$txt.LocalTable.NameGo}} struct: %s", err) t.Errorf("Unable to randomize {{$txt.LocalTable.NameGo}} struct: %s", err)
} }
if err := randomize.Struct(seed, &foreign, {{$foreignVarNameSingular}}DBTypes, true, {{$foreignVarNameSingular}}ColumnsWithDefault...); err != nil { if err := randomize.Struct(seed, &foreign, {{$foreignVarNameSingular}}DBTypes, {{if .ForeignColumnNullable}}true{{else}}false{{end}}, {{$foreignVarNameSingular}}ColumnsWithDefault...); err != nil {
t.Errorf("Unable to randomize {{$txt.ForeignTable.NameGo}} struct: %s", err) t.Errorf("Unable to randomize {{$txt.ForeignTable.NameGo}} struct: %s", err)
} }