Update CircleCI to support MySQL

This commit is contained in:
go-jet 2019-08-08 12:02:32 +02:00
parent f9b900b303
commit 0ab25e4464
28 changed files with 198 additions and 240 deletions

View file

@ -8,14 +8,14 @@ jobs:
# specify the version # specify the version
- image: circleci/golang:1.11 - image: circleci/golang:1.11
- image: circleci/postgres:10.6-alpine - image: circleci/postgres:10.8-alpine
environment: # environment variables for primary container environment: # environment variables for primary container
POSTGRES_USER: jet POSTGRES_USER: jet
POSTGRES_PASSWORD: jet POSTGRES_PASSWORD: jet
POSTGRES_DB: jetdb POSTGRES_DB: jetdb
- image: circleci/php:7.1-apache-node-browsers # The primary container where steps are run - image: circleci/mysql:8.0
- image: circleci/mysql:8.0.4 command: [--default-authentication-plugin=mysql_native_password]
environment: environment:
MYSQL_ROOT_PASSWORD: jet MYSQL_ROOT_PASSWORD: jet
MYSQL_DATABASE: dvds MYSQL_DATABASE: dvds
@ -30,7 +30,6 @@ jobs:
steps: steps:
- checkout - checkout
# specify any bash command here prefixed with `run: `
- run: - run:
name: Install dependencies name: Install dependencies
command: | command: |
@ -71,17 +70,23 @@ jobs:
command: | command: |
sudo apt-get install default-mysql-client sudo apt-get install default-mysql-client
- run: cat /var/run/mysqld/mysqld.sock - run:
name: Init MySQL database
command: |
mysql -h 127.0.0.1 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';"
mysql -h 127.0.0.1 -u root -pjet -e "set global sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';"
mysql -h 127.0.0.1 -u jet -pjet -e "create database test_sample"
- run: - run:
name: Init Postgres and MySQL database name: Init Postgres database
command: | command: |
cd tests cd tests
go run ./init/init.go go run ./init/init.go -testsuite all
cd .. cd ..
- run: mkdir -p $TEST_RESULTS - run: mkdir -p $TEST_RESULTS
- run: go test -v ./... -coverpkg=github.com/go-jet/jet/postgres/...,github.com/go-jet/mysql/...,github.com/go-jet/jet/execution/...,github.com/go-jet/jet/generator/...,github.com/go-jet/jet/internal/... -coverprofile=cover.out 2>&1 | go-junit-report > $TEST_RESULTS/results.xml - run: go test -v ./... -coverpkg=github.com/go-jet/jet/postgres/...,github.com/go-jet/mysql/...,github.com/go-jet/jet/execution/...,github.com/go-jet/jet/generator/...,github.com/go-jet/jet/internal/... -coverprofile=cover.out # 2>&1 | go-junit-report > $TEST_RESULTS/results.xml
- run: - run:
name: Upload code coverage name: Upload code coverage

View file

@ -1,6 +1,6 @@
// //
// Code generated by go-jet DO NOT EDIT. // Code generated by go-jet DO NOT EDIT.
// Generated at Wednesday, 17-Jul-19 13:11:01 CEST // Generated at Thursday, 08-Aug-19 16:59:58 CEST
// //
// WARNING: Changes to this file may cause incorrect behavior // WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated // and will be lost if the code is regenerated
@ -8,18 +8,18 @@
package enum package enum
import "github.com/go-jet/jet" import "github.com/go-jet/jet/postgres"
var MpaaRating = &struct { var MpaaRating = &struct {
G jet.StringExpression G postgres.StringExpression
Pg jet.StringExpression Pg postgres.StringExpression
Pg13 jet.StringExpression Pg13 postgres.StringExpression
R jet.StringExpression R postgres.StringExpression
Nc17 jet.StringExpression Nc17 postgres.StringExpression
}{ }{
G: jet.NewEnumValue("G"), G: postgres.NewEnumValue("G"),
Pg: jet.NewEnumValue("PG"), Pg: postgres.NewEnumValue("PG"),
Pg13: jet.NewEnumValue("PG-13"), Pg13: postgres.NewEnumValue("PG-13"),
R: jet.NewEnumValue("R"), R: postgres.NewEnumValue("R"),
Nc17: jet.NewEnumValue("NC-17"), Nc17: postgres.NewEnumValue("NC-17"),
} }

View file

@ -1,6 +1,6 @@
// //
// Code generated by go-jet DO NOT EDIT. // Code generated by go-jet DO NOT EDIT.
// Generated at Wednesday, 17-Jul-19 13:11:01 CEST // Generated at Thursday, 08-Aug-19 16:59:58 CEST
// //
// WARNING: Changes to this file may cause incorrect behavior // WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated // and will be lost if the code is regenerated

View file

@ -1,6 +1,6 @@
// //
// Code generated by go-jet DO NOT EDIT. // Code generated by go-jet DO NOT EDIT.
// Generated at Wednesday, 17-Jul-19 13:11:01 CEST // Generated at Thursday, 08-Aug-19 16:59:58 CEST
// //
// WARNING: Changes to this file may cause incorrect behavior // WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated // and will be lost if the code is regenerated

View file

@ -1,6 +1,6 @@
// //
// Code generated by go-jet DO NOT EDIT. // Code generated by go-jet DO NOT EDIT.
// Generated at Wednesday, 17-Jul-19 13:11:01 CEST // Generated at Thursday, 08-Aug-19 16:59:58 CEST
// //
// WARNING: Changes to this file may cause incorrect behavior // WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated // and will be lost if the code is regenerated

View file

@ -1,6 +1,6 @@
// //
// Code generated by go-jet DO NOT EDIT. // Code generated by go-jet DO NOT EDIT.
// Generated at Wednesday, 17-Jul-19 13:11:01 CEST // Generated at Thursday, 08-Aug-19 16:59:58 CEST
// //
// WARNING: Changes to this file may cause incorrect behavior // WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated // and will be lost if the code is regenerated

View file

@ -1,6 +1,6 @@
// //
// Code generated by go-jet DO NOT EDIT. // Code generated by go-jet DO NOT EDIT.
// Generated at Wednesday, 17-Jul-19 13:11:01 CEST // Generated at Thursday, 08-Aug-19 16:59:58 CEST
// //
// WARNING: Changes to this file may cause incorrect behavior // WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated // and will be lost if the code is regenerated

View file

@ -1,6 +1,6 @@
// //
// Code generated by go-jet DO NOT EDIT. // Code generated by go-jet DO NOT EDIT.
// Generated at Wednesday, 17-Jul-19 13:11:01 CEST // Generated at Thursday, 08-Aug-19 16:59:58 CEST
// //
// WARNING: Changes to this file may cause incorrect behavior // WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated // and will be lost if the code is regenerated

View file

@ -1,6 +1,6 @@
// //
// Code generated by go-jet DO NOT EDIT. // Code generated by go-jet DO NOT EDIT.
// Generated at Wednesday, 17-Jul-19 13:11:01 CEST // Generated at Thursday, 08-Aug-19 16:59:58 CEST
// //
// WARNING: Changes to this file may cause incorrect behavior // WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated // and will be lost if the code is regenerated

View file

@ -1,6 +1,6 @@
// //
// Code generated by go-jet DO NOT EDIT. // Code generated by go-jet DO NOT EDIT.
// Generated at Wednesday, 17-Jul-19 13:11:01 CEST // Generated at Thursday, 08-Aug-19 16:59:58 CEST
// //
// WARNING: Changes to this file may cause incorrect behavior // WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated // and will be lost if the code is regenerated
@ -9,22 +9,22 @@
package table package table
import ( import (
"github.com/go-jet/jet" "github.com/go-jet/jet/postgres"
) )
var Actor = newActorTable() var Actor = newActorTable()
type ActorTable struct { type ActorTable struct {
jet.Table postgres.Table
//Columns //Columns
ActorID jet.ColumnInteger ActorID postgres.ColumnInteger
FirstName jet.ColumnString FirstName postgres.ColumnString
LastName jet.ColumnString LastName postgres.ColumnString
LastUpdate jet.ColumnTimestamp LastUpdate postgres.ColumnTimestamp
AllColumns jet.ColumnList AllColumns postgres.IColumnList
MutableColumns jet.ColumnList MutableColumns postgres.IColumnList
} }
// creates new ActorTable with assigned alias // creates new ActorTable with assigned alias
@ -38,14 +38,14 @@ func (a *ActorTable) AS(alias string) *ActorTable {
func newActorTable() *ActorTable { func newActorTable() *ActorTable {
var ( var (
ActorIDColumn = jet.IntegerColumn("actor_id") ActorIDColumn = postgres.IntegerColumn("actor_id")
FirstNameColumn = jet.StringColumn("first_name") FirstNameColumn = postgres.StringColumn("first_name")
LastNameColumn = jet.StringColumn("last_name") LastNameColumn = postgres.StringColumn("last_name")
LastUpdateColumn = jet.TimestampColumn("last_update") LastUpdateColumn = postgres.TimestampColumn("last_update")
) )
return &ActorTable{ return &ActorTable{
Table: jet.NewTable("dvds", "actor", ActorIDColumn, FirstNameColumn, LastNameColumn, LastUpdateColumn), Table: postgres.NewTable("dvds", "actor", ActorIDColumn, FirstNameColumn, LastNameColumn, LastUpdateColumn),
//Columns //Columns
ActorID: ActorIDColumn, ActorID: ActorIDColumn,
@ -53,7 +53,7 @@ func newActorTable() *ActorTable {
LastName: LastNameColumn, LastName: LastNameColumn,
LastUpdate: LastUpdateColumn, LastUpdate: LastUpdateColumn,
AllColumns: jet.ColumnList{ActorIDColumn, FirstNameColumn, LastNameColumn, LastUpdateColumn}, AllColumns: postgres.ColumnList(ActorIDColumn, FirstNameColumn, LastNameColumn, LastUpdateColumn),
MutableColumns: jet.ColumnList{FirstNameColumn, LastNameColumn, LastUpdateColumn}, MutableColumns: postgres.ColumnList(FirstNameColumn, LastNameColumn, LastUpdateColumn),
} }
} }

View file

@ -1,6 +1,6 @@
// //
// Code generated by go-jet DO NOT EDIT. // Code generated by go-jet DO NOT EDIT.
// Generated at Wednesday, 17-Jul-19 13:11:01 CEST // Generated at Thursday, 08-Aug-19 16:59:58 CEST
// //
// WARNING: Changes to this file may cause incorrect behavior // WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated // and will be lost if the code is regenerated
@ -9,21 +9,21 @@
package table package table
import ( import (
"github.com/go-jet/jet" "github.com/go-jet/jet/postgres"
) )
var Category = newCategoryTable() var Category = newCategoryTable()
type CategoryTable struct { type CategoryTable struct {
jet.Table postgres.Table
//Columns //Columns
CategoryID jet.ColumnInteger CategoryID postgres.ColumnInteger
Name jet.ColumnString Name postgres.ColumnString
LastUpdate jet.ColumnTimestamp LastUpdate postgres.ColumnTimestamp
AllColumns jet.ColumnList AllColumns postgres.IColumnList
MutableColumns jet.ColumnList MutableColumns postgres.IColumnList
} }
// creates new CategoryTable with assigned alias // creates new CategoryTable with assigned alias
@ -37,20 +37,20 @@ func (a *CategoryTable) AS(alias string) *CategoryTable {
func newCategoryTable() *CategoryTable { func newCategoryTable() *CategoryTable {
var ( var (
CategoryIDColumn = jet.IntegerColumn("category_id") CategoryIDColumn = postgres.IntegerColumn("category_id")
NameColumn = jet.StringColumn("name") NameColumn = postgres.StringColumn("name")
LastUpdateColumn = jet.TimestampColumn("last_update") LastUpdateColumn = postgres.TimestampColumn("last_update")
) )
return &CategoryTable{ return &CategoryTable{
Table: jet.NewTable("dvds", "category", CategoryIDColumn, NameColumn, LastUpdateColumn), Table: postgres.NewTable("dvds", "category", CategoryIDColumn, NameColumn, LastUpdateColumn),
//Columns //Columns
CategoryID: CategoryIDColumn, CategoryID: CategoryIDColumn,
Name: NameColumn, Name: NameColumn,
LastUpdate: LastUpdateColumn, LastUpdate: LastUpdateColumn,
AllColumns: jet.ColumnList{CategoryIDColumn, NameColumn, LastUpdateColumn}, AllColumns: postgres.ColumnList(CategoryIDColumn, NameColumn, LastUpdateColumn),
MutableColumns: jet.ColumnList{NameColumn, LastUpdateColumn}, MutableColumns: postgres.ColumnList(NameColumn, LastUpdateColumn),
} }
} }

View file

@ -1,6 +1,6 @@
// //
// Code generated by go-jet DO NOT EDIT. // Code generated by go-jet DO NOT EDIT.
// Generated at Wednesday, 17-Jul-19 13:11:01 CEST // Generated at Thursday, 08-Aug-19 16:59:58 CEST
// //
// WARNING: Changes to this file may cause incorrect behavior // WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated // and will be lost if the code is regenerated
@ -9,31 +9,31 @@
package table package table
import ( import (
"github.com/go-jet/jet" "github.com/go-jet/jet/postgres"
) )
var Film = newFilmTable() var Film = newFilmTable()
type FilmTable struct { type FilmTable struct {
jet.Table postgres.Table
//Columns //Columns
FilmID jet.ColumnInteger FilmID postgres.ColumnInteger
Title jet.ColumnString Title postgres.ColumnString
Description jet.ColumnString Description postgres.ColumnString
ReleaseYear jet.ColumnInteger ReleaseYear postgres.ColumnInteger
LanguageID jet.ColumnInteger LanguageID postgres.ColumnInteger
RentalDuration jet.ColumnInteger RentalDuration postgres.ColumnInteger
RentalRate jet.ColumnFloat RentalRate postgres.ColumnFloat
Length jet.ColumnInteger Length postgres.ColumnInteger
ReplacementCost jet.ColumnFloat ReplacementCost postgres.ColumnFloat
Rating jet.ColumnString Rating postgres.ColumnString
LastUpdate jet.ColumnTimestamp LastUpdate postgres.ColumnTimestamp
SpecialFeatures jet.ColumnString SpecialFeatures postgres.ColumnString
Fulltext jet.ColumnString Fulltext postgres.ColumnString
AllColumns jet.ColumnList AllColumns postgres.IColumnList
MutableColumns jet.ColumnList MutableColumns postgres.IColumnList
} }
// creates new FilmTable with assigned alias // creates new FilmTable with assigned alias
@ -47,23 +47,23 @@ func (a *FilmTable) AS(alias string) *FilmTable {
func newFilmTable() *FilmTable { func newFilmTable() *FilmTable {
var ( var (
FilmIDColumn = jet.IntegerColumn("film_id") FilmIDColumn = postgres.IntegerColumn("film_id")
TitleColumn = jet.StringColumn("title") TitleColumn = postgres.StringColumn("title")
DescriptionColumn = jet.StringColumn("description") DescriptionColumn = postgres.StringColumn("description")
ReleaseYearColumn = jet.IntegerColumn("release_year") ReleaseYearColumn = postgres.IntegerColumn("release_year")
LanguageIDColumn = jet.IntegerColumn("language_id") LanguageIDColumn = postgres.IntegerColumn("language_id")
RentalDurationColumn = jet.IntegerColumn("rental_duration") RentalDurationColumn = postgres.IntegerColumn("rental_duration")
RentalRateColumn = jet.FloatColumn("rental_rate") RentalRateColumn = postgres.FloatColumn("rental_rate")
LengthColumn = jet.IntegerColumn("length") LengthColumn = postgres.IntegerColumn("length")
ReplacementCostColumn = jet.FloatColumn("replacement_cost") ReplacementCostColumn = postgres.FloatColumn("replacement_cost")
RatingColumn = jet.StringColumn("rating") RatingColumn = postgres.StringColumn("rating")
LastUpdateColumn = jet.TimestampColumn("last_update") LastUpdateColumn = postgres.TimestampColumn("last_update")
SpecialFeaturesColumn = jet.StringColumn("special_features") SpecialFeaturesColumn = postgres.StringColumn("special_features")
FulltextColumn = jet.StringColumn("fulltext") FulltextColumn = postgres.StringColumn("fulltext")
) )
return &FilmTable{ return &FilmTable{
Table: jet.NewTable("dvds", "film", FilmIDColumn, TitleColumn, DescriptionColumn, ReleaseYearColumn, LanguageIDColumn, RentalDurationColumn, RentalRateColumn, LengthColumn, ReplacementCostColumn, RatingColumn, LastUpdateColumn, SpecialFeaturesColumn, FulltextColumn), Table: postgres.NewTable("dvds", "film", FilmIDColumn, TitleColumn, DescriptionColumn, ReleaseYearColumn, LanguageIDColumn, RentalDurationColumn, RentalRateColumn, LengthColumn, ReplacementCostColumn, RatingColumn, LastUpdateColumn, SpecialFeaturesColumn, FulltextColumn),
//Columns //Columns
FilmID: FilmIDColumn, FilmID: FilmIDColumn,
@ -80,7 +80,7 @@ func newFilmTable() *FilmTable {
SpecialFeatures: SpecialFeaturesColumn, SpecialFeatures: SpecialFeaturesColumn,
Fulltext: FulltextColumn, Fulltext: FulltextColumn,
AllColumns: jet.ColumnList{FilmIDColumn, TitleColumn, DescriptionColumn, ReleaseYearColumn, LanguageIDColumn, RentalDurationColumn, RentalRateColumn, LengthColumn, ReplacementCostColumn, RatingColumn, LastUpdateColumn, SpecialFeaturesColumn, FulltextColumn}, AllColumns: postgres.ColumnList(FilmIDColumn, TitleColumn, DescriptionColumn, ReleaseYearColumn, LanguageIDColumn, RentalDurationColumn, RentalRateColumn, LengthColumn, ReplacementCostColumn, RatingColumn, LastUpdateColumn, SpecialFeaturesColumn, FulltextColumn),
MutableColumns: jet.ColumnList{TitleColumn, DescriptionColumn, ReleaseYearColumn, LanguageIDColumn, RentalDurationColumn, RentalRateColumn, LengthColumn, ReplacementCostColumn, RatingColumn, LastUpdateColumn, SpecialFeaturesColumn, FulltextColumn}, MutableColumns: postgres.ColumnList(TitleColumn, DescriptionColumn, ReleaseYearColumn, LanguageIDColumn, RentalDurationColumn, RentalRateColumn, LengthColumn, ReplacementCostColumn, RatingColumn, LastUpdateColumn, SpecialFeaturesColumn, FulltextColumn),
} }
} }

View file

@ -1,6 +1,6 @@
// //
// Code generated by go-jet DO NOT EDIT. // Code generated by go-jet DO NOT EDIT.
// Generated at Wednesday, 17-Jul-19 13:11:01 CEST // Generated at Thursday, 08-Aug-19 16:59:58 CEST
// //
// WARNING: Changes to this file may cause incorrect behavior // WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated // and will be lost if the code is regenerated
@ -9,21 +9,21 @@
package table package table
import ( import (
"github.com/go-jet/jet" "github.com/go-jet/jet/postgres"
) )
var FilmActor = newFilmActorTable() var FilmActor = newFilmActorTable()
type FilmActorTable struct { type FilmActorTable struct {
jet.Table postgres.Table
//Columns //Columns
ActorID jet.ColumnInteger ActorID postgres.ColumnInteger
FilmID jet.ColumnInteger FilmID postgres.ColumnInteger
LastUpdate jet.ColumnTimestamp LastUpdate postgres.ColumnTimestamp
AllColumns jet.ColumnList AllColumns postgres.IColumnList
MutableColumns jet.ColumnList MutableColumns postgres.IColumnList
} }
// creates new FilmActorTable with assigned alias // creates new FilmActorTable with assigned alias
@ -37,20 +37,20 @@ func (a *FilmActorTable) AS(alias string) *FilmActorTable {
func newFilmActorTable() *FilmActorTable { func newFilmActorTable() *FilmActorTable {
var ( var (
ActorIDColumn = jet.IntegerColumn("actor_id") ActorIDColumn = postgres.IntegerColumn("actor_id")
FilmIDColumn = jet.IntegerColumn("film_id") FilmIDColumn = postgres.IntegerColumn("film_id")
LastUpdateColumn = jet.TimestampColumn("last_update") LastUpdateColumn = postgres.TimestampColumn("last_update")
) )
return &FilmActorTable{ return &FilmActorTable{
Table: jet.NewTable("dvds", "film_actor", ActorIDColumn, FilmIDColumn, LastUpdateColumn), Table: postgres.NewTable("dvds", "film_actor", ActorIDColumn, FilmIDColumn, LastUpdateColumn),
//Columns //Columns
ActorID: ActorIDColumn, ActorID: ActorIDColumn,
FilmID: FilmIDColumn, FilmID: FilmIDColumn,
LastUpdate: LastUpdateColumn, LastUpdate: LastUpdateColumn,
AllColumns: jet.ColumnList{ActorIDColumn, FilmIDColumn, LastUpdateColumn}, AllColumns: postgres.ColumnList(ActorIDColumn, FilmIDColumn, LastUpdateColumn),
MutableColumns: jet.ColumnList{LastUpdateColumn}, MutableColumns: postgres.ColumnList(LastUpdateColumn),
} }
} }

View file

@ -1,6 +1,6 @@
// //
// Code generated by go-jet DO NOT EDIT. // Code generated by go-jet DO NOT EDIT.
// Generated at Wednesday, 17-Jul-19 13:11:01 CEST // Generated at Thursday, 08-Aug-19 16:59:58 CEST
// //
// WARNING: Changes to this file may cause incorrect behavior // WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated // and will be lost if the code is regenerated
@ -9,21 +9,21 @@
package table package table
import ( import (
"github.com/go-jet/jet" "github.com/go-jet/jet/postgres"
) )
var FilmCategory = newFilmCategoryTable() var FilmCategory = newFilmCategoryTable()
type FilmCategoryTable struct { type FilmCategoryTable struct {
jet.Table postgres.Table
//Columns //Columns
FilmID jet.ColumnInteger FilmID postgres.ColumnInteger
CategoryID jet.ColumnInteger CategoryID postgres.ColumnInteger
LastUpdate jet.ColumnTimestamp LastUpdate postgres.ColumnTimestamp
AllColumns jet.ColumnList AllColumns postgres.IColumnList
MutableColumns jet.ColumnList MutableColumns postgres.IColumnList
} }
// creates new FilmCategoryTable with assigned alias // creates new FilmCategoryTable with assigned alias
@ -37,20 +37,20 @@ func (a *FilmCategoryTable) AS(alias string) *FilmCategoryTable {
func newFilmCategoryTable() *FilmCategoryTable { func newFilmCategoryTable() *FilmCategoryTable {
var ( var (
FilmIDColumn = jet.IntegerColumn("film_id") FilmIDColumn = postgres.IntegerColumn("film_id")
CategoryIDColumn = jet.IntegerColumn("category_id") CategoryIDColumn = postgres.IntegerColumn("category_id")
LastUpdateColumn = jet.TimestampColumn("last_update") LastUpdateColumn = postgres.TimestampColumn("last_update")
) )
return &FilmCategoryTable{ return &FilmCategoryTable{
Table: jet.NewTable("dvds", "film_category", FilmIDColumn, CategoryIDColumn, LastUpdateColumn), Table: postgres.NewTable("dvds", "film_category", FilmIDColumn, CategoryIDColumn, LastUpdateColumn),
//Columns //Columns
FilmID: FilmIDColumn, FilmID: FilmIDColumn,
CategoryID: CategoryIDColumn, CategoryID: CategoryIDColumn,
LastUpdate: LastUpdateColumn, LastUpdate: LastUpdateColumn,
AllColumns: jet.ColumnList{FilmIDColumn, CategoryIDColumn, LastUpdateColumn}, AllColumns: postgres.ColumnList(FilmIDColumn, CategoryIDColumn, LastUpdateColumn),
MutableColumns: jet.ColumnList{LastUpdateColumn}, MutableColumns: postgres.ColumnList(LastUpdateColumn),
} }
} }

View file

@ -1,6 +1,6 @@
// //
// Code generated by go-jet DO NOT EDIT. // Code generated by go-jet DO NOT EDIT.
// Generated at Wednesday, 17-Jul-19 13:11:01 CEST // Generated at Thursday, 08-Aug-19 16:59:58 CEST
// //
// WARNING: Changes to this file may cause incorrect behavior // WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated // and will be lost if the code is regenerated
@ -9,21 +9,21 @@
package table package table
import ( import (
"github.com/go-jet/jet" "github.com/go-jet/jet/postgres"
) )
var Language = newLanguageTable() var Language = newLanguageTable()
type LanguageTable struct { type LanguageTable struct {
jet.Table postgres.Table
//Columns //Columns
LanguageID jet.ColumnInteger LanguageID postgres.ColumnInteger
Name jet.ColumnString Name postgres.ColumnString
LastUpdate jet.ColumnTimestamp LastUpdate postgres.ColumnTimestamp
AllColumns jet.ColumnList AllColumns postgres.IColumnList
MutableColumns jet.ColumnList MutableColumns postgres.IColumnList
} }
// creates new LanguageTable with assigned alias // creates new LanguageTable with assigned alias
@ -37,20 +37,20 @@ func (a *LanguageTable) AS(alias string) *LanguageTable {
func newLanguageTable() *LanguageTable { func newLanguageTable() *LanguageTable {
var ( var (
LanguageIDColumn = jet.IntegerColumn("language_id") LanguageIDColumn = postgres.IntegerColumn("language_id")
NameColumn = jet.StringColumn("name") NameColumn = postgres.StringColumn("name")
LastUpdateColumn = jet.TimestampColumn("last_update") LastUpdateColumn = postgres.TimestampColumn("last_update")
) )
return &LanguageTable{ return &LanguageTable{
Table: jet.NewTable("dvds", "language", LanguageIDColumn, NameColumn, LastUpdateColumn), Table: postgres.NewTable("dvds", "language", LanguageIDColumn, NameColumn, LastUpdateColumn),
//Columns //Columns
LanguageID: LanguageIDColumn, LanguageID: LanguageIDColumn,
Name: NameColumn, Name: NameColumn,
LastUpdate: LastUpdateColumn, LastUpdate: LastUpdateColumn,
AllColumns: jet.ColumnList{LanguageIDColumn, NameColumn, LastUpdateColumn}, AllColumns: postgres.ColumnList(LanguageIDColumn, NameColumn, LastUpdateColumn),
MutableColumns: jet.ColumnList{NameColumn, LastUpdateColumn}, MutableColumns: postgres.ColumnList(NameColumn, LastUpdateColumn),
} }
} }

View file

@ -97,7 +97,7 @@ func jsonSave(path string, v interface{}) {
} }
} }
func printStatementInfo(stmt Statement) { func printStatementInfo(stmt SelectStatement) {
query, args, err := stmt.Sql() query, args, err := stmt.Sql()
panicOnError(err) panicOnError(err)

View file

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"github.com/go-jet/jet/generator/internal/metadata" "github.com/go-jet/jet/generator/internal/metadata"
"github.com/go-jet/jet/generator/internal/template" "github.com/go-jet/jet/generator/internal/template"
"github.com/go-jet/jet/internal/utils"
"github.com/go-jet/jet/mysql" "github.com/go-jet/jet/mysql"
"path" "path"
) )
@ -26,7 +27,7 @@ func Generate(destDir string, dbConn DBConnection) error {
if err != nil { if err != nil {
return err return err
} }
defer db.Close() defer utils.DBClose(db)
fmt.Println("Retrieving database information...") fmt.Println("Retrieving database information...")
// No schemas in MySQL // No schemas in MySQL

View file

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"github.com/go-jet/jet/generator/internal/metadata" "github.com/go-jet/jet/generator/internal/metadata"
"github.com/go-jet/jet/generator/internal/template" "github.com/go-jet/jet/generator/internal/template"
"github.com/go-jet/jet/internal/utils"
"github.com/go-jet/jet/postgres" "github.com/go-jet/jet/postgres"
"path" "path"
"strconv" "strconv"
@ -27,7 +28,7 @@ type DBConnection struct {
func Generate(destDir string, dbConn DBConnection) error { func Generate(destDir string, dbConn DBConnection) error {
db, err := openConnection(dbConn) db, err := openConnection(dbConn)
defer db.Close() defer utils.DBClose(db)
if err != nil { if err != nil {
return err return err

View file

@ -1,13 +0,0 @@
package snaker
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestDb(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Snaker Suite")
}

View file

@ -1,40 +1,16 @@
package snaker package snaker
import ( import (
. "github.com/onsi/ginkgo" "gotest.tools/assert"
. "github.com/onsi/gomega" "testing"
) )
var _ = Describe("Snaker", func() { func TestSnakeToCamel(t *testing.T) {
assert.Equal(t, SnakeToCamel(""), "")
Describe("SnakeToCamel test", func() { assert.Equal(t, SnakeToCamel("potato_"), "Potato")
It("should return an empty string on an empty input", func() { assert.Equal(t, SnakeToCamel("this_has_to_be_uppercased"), "ThisHasToBeUppercased")
Expect(SnakeToCamel("")).To(Equal("")) assert.Equal(t, SnakeToCamel("this_is_an_id"), "ThisIsAnID")
}) assert.Equal(t, SnakeToCamel("this_is_an_identifier"), "ThisIsAnIdentifier")
assert.Equal(t, SnakeToCamel("id"), "ID")
It("should not blow up on trailing _", func() { assert.Equal(t, SnakeToCamel("oauth_client"), "OAuthClient")
Expect(SnakeToCamel("potato_")).To(Equal("Potato")) }
})
It("should return a snaked text as camel case", func() {
Expect(SnakeToCamel("this_has_to_be_uppercased")).To(
Equal("ThisHasToBeUppercased"))
})
It("should return a snaked text as camel case, except the word ID", func() {
Expect(SnakeToCamel("this_is_an_id")).To(Equal("ThisIsAnID"))
})
It("should return 'id' not as uppercase", func() {
Expect(SnakeToCamel("this_is_an_identifier")).To(Equal("ThisIsAnIdentifier"))
})
It("should simply work with id", func() {
Expect(SnakeToCamel("id")).To(Equal("ID"))
})
It("should work with initialism where only certain characters are uppercase", func() {
Expect(SnakeToCamel("oauth_client")).To(Equal("OAuthClient"))
})
})
})

View file

@ -51,6 +51,25 @@ func (t *timestampzInterfaceImpl) GT_EQ(rhs TimestampzExpression) BoolExpression
return gtEq(t.parent, rhs) return gtEq(t.parent, rhs)
} }
//---------------------------------------------------//
type prefixTimestampzOperator struct {
expressionInterfaceImpl
timestampzInterfaceImpl
prefixOpExpression
}
func NewPrefixTimestampOperator(operator string, expression Expression) TimestampzExpression {
timeExpr := prefixTimestampzOperator{}
timeExpr.prefixOpExpression = newPrefixExpression(expression, operator)
timeExpr.expressionInterfaceImpl.parent = &timeExpr
timeExpr.timestampzInterfaceImpl.parent = &timeExpr
return &timeExpr
}
//------------------------------------------------- //-------------------------------------------------
type timestampzExpressionWrapper struct { type timestampzExpressionWrapper struct {

View file

@ -1,6 +1,7 @@
package utils package utils
import ( import (
"database/sql"
"github.com/go-jet/jet/internal/3rdparty/snaker" "github.com/go-jet/jet/internal/3rdparty/snaker"
"go/format" "go/format"
"os" "os"
@ -79,6 +80,14 @@ func CleanUpGeneratedFiles(dir string) error {
return nil return nil
} }
func DBClose(db *sql.DB) {
if db == nil {
return
}
db.Close()
}
// DirExists checks if folder at path exist. // DirExists checks if folder at path exist.
func DirExists(path string) (bool, error) { func DirExists(path string) (bool, error) {
_, err := os.Stat(path) _, err := os.Stat(path)

View file

@ -1,47 +0,0 @@
package postgres
import (
"testing"
)
var dateVar = Date(2000, 12, 30)
func TestDateExpressionEQ(t *testing.T) {
assertClauseSerialize(t, table1ColDate.EQ(table2ColDate), "(table1.col_date = table2.col_date)")
assertClauseSerialize(t, table1ColDate.EQ(dateVar), "(table1.col_date = $1::DATE)", "2000-12-30")
}
func TestDateExpressionNOT_EQ(t *testing.T) {
assertClauseSerialize(t, table1ColDate.NOT_EQ(table2ColDate), "(table1.col_date != table2.col_date)")
assertClauseSerialize(t, table1ColDate.NOT_EQ(dateVar), "(table1.col_date != $1::DATE)", "2000-12-30")
}
func TestDateExpressionIS_DISTINCT_FROM(t *testing.T) {
assertClauseSerialize(t, table1ColDate.IS_DISTINCT_FROM(table2ColDate), "(table1.col_date IS DISTINCT FROM table2.col_date)")
assertClauseSerialize(t, table1ColDate.IS_DISTINCT_FROM(dateVar), "(table1.col_date IS DISTINCT FROM $1::DATE)", "2000-12-30")
}
func TestDateExpressionIS_NOT_DISTINCT_FROM(t *testing.T) {
assertClauseSerialize(t, table1ColDate.IS_NOT_DISTINCT_FROM(table2ColDate), "(table1.col_date IS NOT DISTINCT FROM table2.col_date)")
assertClauseSerialize(t, table1ColDate.IS_NOT_DISTINCT_FROM(dateVar), "(table1.col_date IS NOT DISTINCT FROM $1::DATE)", "2000-12-30")
}
func TestDateExpressionGT(t *testing.T) {
assertClauseSerialize(t, table1ColDate.GT(table2ColDate), "(table1.col_date > table2.col_date)")
assertClauseSerialize(t, table1ColDate.GT(dateVar), "(table1.col_date > $1::DATE)", "2000-12-30")
}
func TestDateExpressionGT_EQ(t *testing.T) {
assertClauseSerialize(t, table1ColDate.GT_EQ(table2ColDate), "(table1.col_date >= table2.col_date)")
assertClauseSerialize(t, table1ColDate.GT_EQ(dateVar), "(table1.col_date >= $1::DATE)", "2000-12-30")
}
func TestDateExpressionLT(t *testing.T) {
assertClauseSerialize(t, table1ColDate.LT(table2ColDate), "(table1.col_date < table2.col_date)")
assertClauseSerialize(t, table1ColDate.LT(dateVar), "(table1.col_date < $1::DATE)", "2000-12-30")
}
func TestDateExpressionLT_EQ(t *testing.T) {
assertClauseSerialize(t, table1ColDate.LT_EQ(table2ColDate), "(table1.col_date <= table2.col_date)")
assertClauseSerialize(t, table1ColDate.LT_EQ(dateVar), "(table1.col_date <= $1::DATE)", "2000-12-30")
}

View file

@ -112,7 +112,7 @@ CREATE TABLE `all_types` (
`json` json NOT NULL, `json` json NOT NULL,
`json_ptr` json `json_ptr` json
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `all_types` VALUES INSERT INTO `all_types` VALUES
(false, true, (false, true,

View file

@ -46,8 +46,11 @@ func initMySQLDB() {
} }
for _, dbName := range mySQLDBs { for _, dbName := range mySQLDBs {
cmdLine := fmt.Sprintf("mysql -u %s -p%s %s < %s", cmdLine := fmt.Sprintf("mysql -h 127.0.0.1 -u %s -p%s %s < %s",
dbconfig.MySQLUser, dbconfig.MySQLPassword, dbName, "./init/data/mysql/"+dbName+".sql") dbconfig.MySQLUser, dbconfig.MySQLPassword, dbName, "./init/data/mysql/"+dbName+".sql")
fmt.Println(cmdLine)
cmd := exec.Command("sh", "-c", cmdLine) cmd := exec.Command("sh", "-c", cmdLine)
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr

View file

@ -803,6 +803,8 @@ func TestTimeLiterals(t *testing.T) {
).FROM(AllTypes). ).FROM(AllTypes).
LIMIT(1) LIMIT(1)
//fmt.Println(query.Sql())
testutils.AssertStatementSql(t, query, ` testutils.AssertStatementSql(t, query, `
SELECT $1::DATE AS "date", SELECT $1::DATE AS "date",
$2::time without time zone AS "time", $2::time without time zone AS "time",
@ -818,19 +820,21 @@ LIMIT $6;
Time time.Time Time time.Time
Timez time.Time Timez time.Time
Timestamp time.Time Timestamp time.Time
Timestampz time.Time //Timestampz time.Time
} }
err = query.Query(db, &dest) err = query.Query(db, &dest)
assert.NilError(t, err) assert.NilError(t, err)
//testutils.PrintJson(dest)
testutils.AssertJSON(t, dest, ` testutils.AssertJSON(t, dest, `
{ {
"Date": "2009-11-17T00:00:00Z", "Date": "2009-11-17T00:00:00Z",
"Time": "0000-01-01T20:34:58.651387Z", "Time": "0000-01-01T20:34:58.651387Z",
"Timez": "0000-01-01T20:34:58.651387+01:00", "Timez": "0000-01-01T20:34:58.651387+01:00",
"Timestamp": "2009-11-17T20:34:58.651387Z", "Timestamp": "2009-11-17T20:34:58.651387Z"
"Timestampz": "2009-11-17T20:34:58.651387+01:00"
} }
`) `)
} }