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
- image: circleci/golang:1.11
- image: circleci/postgres:10.6-alpine
- image: circleci/postgres:10.8-alpine
environment: # environment variables for primary container
POSTGRES_USER: jet
POSTGRES_PASSWORD: jet
POSTGRES_DB: jetdb
- image: circleci/php:7.1-apache-node-browsers # The primary container where steps are run
- image: circleci/mysql:8.0.4
- image: circleci/mysql:8.0
command: [--default-authentication-plugin=mysql_native_password]
environment:
MYSQL_ROOT_PASSWORD: jet
MYSQL_DATABASE: dvds
@ -30,7 +30,6 @@ jobs:
steps:
- checkout
# specify any bash command here prefixed with `run: `
- run:
name: Install dependencies
command: |
@ -71,17 +70,23 @@ jobs:
command: |
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:
name: Init Postgres and MySQL database
name: Init Postgres database
command: |
cd tests
go run ./init/init.go
go run ./init/init.go -testsuite all
cd ..
- 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:
name: Upload code coverage

View file

@ -1,6 +1,6 @@
//
// 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
// and will be lost if the code is regenerated
@ -8,18 +8,18 @@
package enum
import "github.com/go-jet/jet"
import "github.com/go-jet/jet/postgres"
var MpaaRating = &struct {
G jet.StringExpression
Pg jet.StringExpression
Pg13 jet.StringExpression
R jet.StringExpression
Nc17 jet.StringExpression
G postgres.StringExpression
Pg postgres.StringExpression
Pg13 postgres.StringExpression
R postgres.StringExpression
Nc17 postgres.StringExpression
}{
G: jet.NewEnumValue("G"),
Pg: jet.NewEnumValue("PG"),
Pg13: jet.NewEnumValue("PG-13"),
R: jet.NewEnumValue("R"),
Nc17: jet.NewEnumValue("NC-17"),
G: postgres.NewEnumValue("G"),
Pg: postgres.NewEnumValue("PG"),
Pg13: postgres.NewEnumValue("PG-13"),
R: postgres.NewEnumValue("R"),
Nc17: postgres.NewEnumValue("NC-17"),
}

View file

@ -1,6 +1,6 @@
//
// 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
// and will be lost if the code is regenerated

View file

@ -1,6 +1,6 @@
//
// 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
// and will be lost if the code is regenerated

View file

@ -1,6 +1,6 @@
//
// 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
// and will be lost if the code is regenerated

View file

@ -1,6 +1,6 @@
//
// 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
// and will be lost if the code is regenerated

View file

@ -1,6 +1,6 @@
//
// 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
// and will be lost if the code is regenerated

View file

@ -1,6 +1,6 @@
//
// 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
// and will be lost if the code is regenerated

View file

@ -1,6 +1,6 @@
//
// 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
// and will be lost if the code is regenerated

View file

@ -1,6 +1,6 @@
//
// 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
// and will be lost if the code is regenerated
@ -9,22 +9,22 @@
package table
import (
"github.com/go-jet/jet"
"github.com/go-jet/jet/postgres"
)
var Actor = newActorTable()
type ActorTable struct {
jet.Table
postgres.Table
//Columns
ActorID jet.ColumnInteger
FirstName jet.ColumnString
LastName jet.ColumnString
LastUpdate jet.ColumnTimestamp
ActorID postgres.ColumnInteger
FirstName postgres.ColumnString
LastName postgres.ColumnString
LastUpdate postgres.ColumnTimestamp
AllColumns jet.ColumnList
MutableColumns jet.ColumnList
AllColumns postgres.IColumnList
MutableColumns postgres.IColumnList
}
// creates new ActorTable with assigned alias
@ -38,14 +38,14 @@ func (a *ActorTable) AS(alias string) *ActorTable {
func newActorTable() *ActorTable {
var (
ActorIDColumn = jet.IntegerColumn("actor_id")
FirstNameColumn = jet.StringColumn("first_name")
LastNameColumn = jet.StringColumn("last_name")
LastUpdateColumn = jet.TimestampColumn("last_update")
ActorIDColumn = postgres.IntegerColumn("actor_id")
FirstNameColumn = postgres.StringColumn("first_name")
LastNameColumn = postgres.StringColumn("last_name")
LastUpdateColumn = postgres.TimestampColumn("last_update")
)
return &ActorTable{
Table: jet.NewTable("dvds", "actor", ActorIDColumn, FirstNameColumn, LastNameColumn, LastUpdateColumn),
Table: postgres.NewTable("dvds", "actor", ActorIDColumn, FirstNameColumn, LastNameColumn, LastUpdateColumn),
//Columns
ActorID: ActorIDColumn,
@ -53,7 +53,7 @@ func newActorTable() *ActorTable {
LastName: LastNameColumn,
LastUpdate: LastUpdateColumn,
AllColumns: jet.ColumnList{ActorIDColumn, FirstNameColumn, LastNameColumn, LastUpdateColumn},
MutableColumns: jet.ColumnList{FirstNameColumn, LastNameColumn, LastUpdateColumn},
AllColumns: postgres.ColumnList(ActorIDColumn, FirstNameColumn, LastNameColumn, LastUpdateColumn),
MutableColumns: postgres.ColumnList(FirstNameColumn, LastNameColumn, LastUpdateColumn),
}
}

View file

@ -1,6 +1,6 @@
//
// 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
// and will be lost if the code is regenerated
@ -9,21 +9,21 @@
package table
import (
"github.com/go-jet/jet"
"github.com/go-jet/jet/postgres"
)
var Category = newCategoryTable()
type CategoryTable struct {
jet.Table
postgres.Table
//Columns
CategoryID jet.ColumnInteger
Name jet.ColumnString
LastUpdate jet.ColumnTimestamp
CategoryID postgres.ColumnInteger
Name postgres.ColumnString
LastUpdate postgres.ColumnTimestamp
AllColumns jet.ColumnList
MutableColumns jet.ColumnList
AllColumns postgres.IColumnList
MutableColumns postgres.IColumnList
}
// creates new CategoryTable with assigned alias
@ -37,20 +37,20 @@ func (a *CategoryTable) AS(alias string) *CategoryTable {
func newCategoryTable() *CategoryTable {
var (
CategoryIDColumn = jet.IntegerColumn("category_id")
NameColumn = jet.StringColumn("name")
LastUpdateColumn = jet.TimestampColumn("last_update")
CategoryIDColumn = postgres.IntegerColumn("category_id")
NameColumn = postgres.StringColumn("name")
LastUpdateColumn = postgres.TimestampColumn("last_update")
)
return &CategoryTable{
Table: jet.NewTable("dvds", "category", CategoryIDColumn, NameColumn, LastUpdateColumn),
Table: postgres.NewTable("dvds", "category", CategoryIDColumn, NameColumn, LastUpdateColumn),
//Columns
CategoryID: CategoryIDColumn,
Name: NameColumn,
LastUpdate: LastUpdateColumn,
AllColumns: jet.ColumnList{CategoryIDColumn, NameColumn, LastUpdateColumn},
MutableColumns: jet.ColumnList{NameColumn, LastUpdateColumn},
AllColumns: postgres.ColumnList(CategoryIDColumn, NameColumn, LastUpdateColumn),
MutableColumns: postgres.ColumnList(NameColumn, LastUpdateColumn),
}
}

View file

@ -1,6 +1,6 @@
//
// 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
// and will be lost if the code is regenerated
@ -9,31 +9,31 @@
package table
import (
"github.com/go-jet/jet"
"github.com/go-jet/jet/postgres"
)
var Film = newFilmTable()
type FilmTable struct {
jet.Table
postgres.Table
//Columns
FilmID jet.ColumnInteger
Title jet.ColumnString
Description jet.ColumnString
ReleaseYear jet.ColumnInteger
LanguageID jet.ColumnInteger
RentalDuration jet.ColumnInteger
RentalRate jet.ColumnFloat
Length jet.ColumnInteger
ReplacementCost jet.ColumnFloat
Rating jet.ColumnString
LastUpdate jet.ColumnTimestamp
SpecialFeatures jet.ColumnString
Fulltext jet.ColumnString
FilmID postgres.ColumnInteger
Title postgres.ColumnString
Description postgres.ColumnString
ReleaseYear postgres.ColumnInteger
LanguageID postgres.ColumnInteger
RentalDuration postgres.ColumnInteger
RentalRate postgres.ColumnFloat
Length postgres.ColumnInteger
ReplacementCost postgres.ColumnFloat
Rating postgres.ColumnString
LastUpdate postgres.ColumnTimestamp
SpecialFeatures postgres.ColumnString
Fulltext postgres.ColumnString
AllColumns jet.ColumnList
MutableColumns jet.ColumnList
AllColumns postgres.IColumnList
MutableColumns postgres.IColumnList
}
// creates new FilmTable with assigned alias
@ -47,23 +47,23 @@ func (a *FilmTable) AS(alias string) *FilmTable {
func newFilmTable() *FilmTable {
var (
FilmIDColumn = jet.IntegerColumn("film_id")
TitleColumn = jet.StringColumn("title")
DescriptionColumn = jet.StringColumn("description")
ReleaseYearColumn = jet.IntegerColumn("release_year")
LanguageIDColumn = jet.IntegerColumn("language_id")
RentalDurationColumn = jet.IntegerColumn("rental_duration")
RentalRateColumn = jet.FloatColumn("rental_rate")
LengthColumn = jet.IntegerColumn("length")
ReplacementCostColumn = jet.FloatColumn("replacement_cost")
RatingColumn = jet.StringColumn("rating")
LastUpdateColumn = jet.TimestampColumn("last_update")
SpecialFeaturesColumn = jet.StringColumn("special_features")
FulltextColumn = jet.StringColumn("fulltext")
FilmIDColumn = postgres.IntegerColumn("film_id")
TitleColumn = postgres.StringColumn("title")
DescriptionColumn = postgres.StringColumn("description")
ReleaseYearColumn = postgres.IntegerColumn("release_year")
LanguageIDColumn = postgres.IntegerColumn("language_id")
RentalDurationColumn = postgres.IntegerColumn("rental_duration")
RentalRateColumn = postgres.FloatColumn("rental_rate")
LengthColumn = postgres.IntegerColumn("length")
ReplacementCostColumn = postgres.FloatColumn("replacement_cost")
RatingColumn = postgres.StringColumn("rating")
LastUpdateColumn = postgres.TimestampColumn("last_update")
SpecialFeaturesColumn = postgres.StringColumn("special_features")
FulltextColumn = postgres.StringColumn("fulltext")
)
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
FilmID: FilmIDColumn,
@ -80,7 +80,7 @@ func newFilmTable() *FilmTable {
SpecialFeatures: SpecialFeaturesColumn,
Fulltext: FulltextColumn,
AllColumns: jet.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},
AllColumns: postgres.ColumnList(FilmIDColumn, 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.
// 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
// and will be lost if the code is regenerated
@ -9,21 +9,21 @@
package table
import (
"github.com/go-jet/jet"
"github.com/go-jet/jet/postgres"
)
var FilmActor = newFilmActorTable()
type FilmActorTable struct {
jet.Table
postgres.Table
//Columns
ActorID jet.ColumnInteger
FilmID jet.ColumnInteger
LastUpdate jet.ColumnTimestamp
ActorID postgres.ColumnInteger
FilmID postgres.ColumnInteger
LastUpdate postgres.ColumnTimestamp
AllColumns jet.ColumnList
MutableColumns jet.ColumnList
AllColumns postgres.IColumnList
MutableColumns postgres.IColumnList
}
// creates new FilmActorTable with assigned alias
@ -37,20 +37,20 @@ func (a *FilmActorTable) AS(alias string) *FilmActorTable {
func newFilmActorTable() *FilmActorTable {
var (
ActorIDColumn = jet.IntegerColumn("actor_id")
FilmIDColumn = jet.IntegerColumn("film_id")
LastUpdateColumn = jet.TimestampColumn("last_update")
ActorIDColumn = postgres.IntegerColumn("actor_id")
FilmIDColumn = postgres.IntegerColumn("film_id")
LastUpdateColumn = postgres.TimestampColumn("last_update")
)
return &FilmActorTable{
Table: jet.NewTable("dvds", "film_actor", ActorIDColumn, FilmIDColumn, LastUpdateColumn),
Table: postgres.NewTable("dvds", "film_actor", ActorIDColumn, FilmIDColumn, LastUpdateColumn),
//Columns
ActorID: ActorIDColumn,
FilmID: FilmIDColumn,
LastUpdate: LastUpdateColumn,
AllColumns: jet.ColumnList{ActorIDColumn, FilmIDColumn, LastUpdateColumn},
MutableColumns: jet.ColumnList{LastUpdateColumn},
AllColumns: postgres.ColumnList(ActorIDColumn, FilmIDColumn, LastUpdateColumn),
MutableColumns: postgres.ColumnList(LastUpdateColumn),
}
}

View file

@ -1,6 +1,6 @@
//
// 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
// and will be lost if the code is regenerated
@ -9,21 +9,21 @@
package table
import (
"github.com/go-jet/jet"
"github.com/go-jet/jet/postgres"
)
var FilmCategory = newFilmCategoryTable()
type FilmCategoryTable struct {
jet.Table
postgres.Table
//Columns
FilmID jet.ColumnInteger
CategoryID jet.ColumnInteger
LastUpdate jet.ColumnTimestamp
FilmID postgres.ColumnInteger
CategoryID postgres.ColumnInteger
LastUpdate postgres.ColumnTimestamp
AllColumns jet.ColumnList
MutableColumns jet.ColumnList
AllColumns postgres.IColumnList
MutableColumns postgres.IColumnList
}
// creates new FilmCategoryTable with assigned alias
@ -37,20 +37,20 @@ func (a *FilmCategoryTable) AS(alias string) *FilmCategoryTable {
func newFilmCategoryTable() *FilmCategoryTable {
var (
FilmIDColumn = jet.IntegerColumn("film_id")
CategoryIDColumn = jet.IntegerColumn("category_id")
LastUpdateColumn = jet.TimestampColumn("last_update")
FilmIDColumn = postgres.IntegerColumn("film_id")
CategoryIDColumn = postgres.IntegerColumn("category_id")
LastUpdateColumn = postgres.TimestampColumn("last_update")
)
return &FilmCategoryTable{
Table: jet.NewTable("dvds", "film_category", FilmIDColumn, CategoryIDColumn, LastUpdateColumn),
Table: postgres.NewTable("dvds", "film_category", FilmIDColumn, CategoryIDColumn, LastUpdateColumn),
//Columns
FilmID: FilmIDColumn,
CategoryID: CategoryIDColumn,
LastUpdate: LastUpdateColumn,
AllColumns: jet.ColumnList{FilmIDColumn, CategoryIDColumn, LastUpdateColumn},
MutableColumns: jet.ColumnList{LastUpdateColumn},
AllColumns: postgres.ColumnList(FilmIDColumn, CategoryIDColumn, LastUpdateColumn),
MutableColumns: postgres.ColumnList(LastUpdateColumn),
}
}

View file

@ -1,6 +1,6 @@
//
// 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
// and will be lost if the code is regenerated
@ -9,21 +9,21 @@
package table
import (
"github.com/go-jet/jet"
"github.com/go-jet/jet/postgres"
)
var Language = newLanguageTable()
type LanguageTable struct {
jet.Table
postgres.Table
//Columns
LanguageID jet.ColumnInteger
Name jet.ColumnString
LastUpdate jet.ColumnTimestamp
LanguageID postgres.ColumnInteger
Name postgres.ColumnString
LastUpdate postgres.ColumnTimestamp
AllColumns jet.ColumnList
MutableColumns jet.ColumnList
AllColumns postgres.IColumnList
MutableColumns postgres.IColumnList
}
// creates new LanguageTable with assigned alias
@ -37,20 +37,20 @@ func (a *LanguageTable) AS(alias string) *LanguageTable {
func newLanguageTable() *LanguageTable {
var (
LanguageIDColumn = jet.IntegerColumn("language_id")
NameColumn = jet.StringColumn("name")
LastUpdateColumn = jet.TimestampColumn("last_update")
LanguageIDColumn = postgres.IntegerColumn("language_id")
NameColumn = postgres.StringColumn("name")
LastUpdateColumn = postgres.TimestampColumn("last_update")
)
return &LanguageTable{
Table: jet.NewTable("dvds", "language", LanguageIDColumn, NameColumn, LastUpdateColumn),
Table: postgres.NewTable("dvds", "language", LanguageIDColumn, NameColumn, LastUpdateColumn),
//Columns
LanguageID: LanguageIDColumn,
Name: NameColumn,
LastUpdate: LastUpdateColumn,
AllColumns: jet.ColumnList{LanguageIDColumn, NameColumn, LastUpdateColumn},
MutableColumns: jet.ColumnList{NameColumn, LastUpdateColumn},
AllColumns: postgres.ColumnList(LanguageIDColumn, 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()
panicOnError(err)

View file

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

View file

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/go-jet/jet/generator/internal/metadata"
"github.com/go-jet/jet/generator/internal/template"
"github.com/go-jet/jet/internal/utils"
"github.com/go-jet/jet/postgres"
"path"
"strconv"
@ -27,7 +28,7 @@ type DBConnection struct {
func Generate(destDir string, dbConn DBConnection) error {
db, err := openConnection(dbConn)
defer db.Close()
defer utils.DBClose(db)
if err != nil {
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
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"gotest.tools/assert"
"testing"
)
var _ = Describe("Snaker", func() {
Describe("SnakeToCamel test", func() {
It("should return an empty string on an empty input", func() {
Expect(SnakeToCamel("")).To(Equal(""))
})
It("should not blow up on trailing _", func() {
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"))
})
})
})
func TestSnakeToCamel(t *testing.T) {
assert.Equal(t, SnakeToCamel(""), "")
assert.Equal(t, SnakeToCamel("potato_"), "Potato")
assert.Equal(t, SnakeToCamel("this_has_to_be_uppercased"), "ThisHasToBeUppercased")
assert.Equal(t, SnakeToCamel("this_is_an_id"), "ThisIsAnID")
assert.Equal(t, SnakeToCamel("this_is_an_identifier"), "ThisIsAnIdentifier")
assert.Equal(t, SnakeToCamel("id"), "ID")
assert.Equal(t, SnakeToCamel("oauth_client"), "OAuthClient")
}

View file

@ -51,6 +51,25 @@ func (t *timestampzInterfaceImpl) GT_EQ(rhs TimestampzExpression) BoolExpression
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 {

View file

@ -1,6 +1,7 @@
package utils
import (
"database/sql"
"github.com/go-jet/jet/internal/3rdparty/snaker"
"go/format"
"os"
@ -79,6 +80,14 @@ func CleanUpGeneratedFiles(dir string) error {
return nil
}
func DBClose(db *sql.DB) {
if db == nil {
return
}
db.Close()
}
// DirExists checks if folder at path exist.
func DirExists(path string) (bool, error) {
_, 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_ptr` json
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `all_types` VALUES
(false, true,

View file

@ -46,8 +46,11 @@ func initMySQLDB() {
}
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")
fmt.Println(cmdLine)
cmd := exec.Command("sh", "-c", cmdLine)
cmd.Stderr = os.Stderr

View file

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