Add support for additional array types.
This commit is contained in:
parent
45d4ced9b0
commit
4ee047a675
47 changed files with 1994 additions and 4277 deletions
|
|
@ -8,6 +8,7 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"github.com/lib/pq"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -23,6 +24,6 @@ type Film struct {
|
|||
ReplacementCost float64
|
||||
Rating *MpaaRating
|
||||
LastUpdate time.Time
|
||||
SpecialFeatures *string
|
||||
SpecialFeatures *pq.StringArray
|
||||
Fulltext string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,14 @@ const (
|
|||
MpaaRating_Nc17 MpaaRating = "NC-17"
|
||||
)
|
||||
|
||||
var MpaaRatingAllValues = []MpaaRating{
|
||||
MpaaRating_G,
|
||||
MpaaRating_Pg,
|
||||
MpaaRating_Pg13,
|
||||
MpaaRating_R,
|
||||
MpaaRating_Nc17,
|
||||
}
|
||||
|
||||
func (e *MpaaRating) Scan(value interface{}) error {
|
||||
var enumValue string
|
||||
switch val := value.(type) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ var Actor = newActorTable("dvds", "actor", "")
|
|||
type actorTable struct {
|
||||
postgres.Table
|
||||
|
||||
//Columns
|
||||
// Columns
|
||||
ActorID postgres.ColumnInteger
|
||||
FirstName postgres.ColumnString
|
||||
LastName postgres.ColumnString
|
||||
|
|
@ -24,6 +24,7 @@ type actorTable struct {
|
|||
|
||||
AllColumns postgres.ColumnList
|
||||
MutableColumns postgres.ColumnList
|
||||
DefaultColumns postgres.ColumnList
|
||||
}
|
||||
|
||||
type ActorTable struct {
|
||||
|
|
@ -67,6 +68,7 @@ func newActorTableImpl(schemaName, tableName, alias string) actorTable {
|
|||
LastUpdateColumn = postgres.TimestampColumn("last_update")
|
||||
allColumns = postgres.ColumnList{ActorIDColumn, FirstNameColumn, LastNameColumn, LastUpdateColumn}
|
||||
mutableColumns = postgres.ColumnList{FirstNameColumn, LastNameColumn, LastUpdateColumn}
|
||||
defaultColumns = postgres.ColumnList{ActorIDColumn}
|
||||
)
|
||||
|
||||
return actorTable{
|
||||
|
|
@ -80,5 +82,6 @@ func newActorTableImpl(schemaName, tableName, alias string) actorTable {
|
|||
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
DefaultColumns: defaultColumns,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,14 @@ var Category = newCategoryTable("dvds", "category", "")
|
|||
type categoryTable struct {
|
||||
postgres.Table
|
||||
|
||||
//Columns
|
||||
// Columns
|
||||
CategoryID postgres.ColumnInteger
|
||||
Name postgres.ColumnString
|
||||
LastUpdate postgres.ColumnTimestamp
|
||||
|
||||
AllColumns postgres.ColumnList
|
||||
MutableColumns postgres.ColumnList
|
||||
DefaultColumns postgres.ColumnList
|
||||
}
|
||||
|
||||
type CategoryTable struct {
|
||||
|
|
@ -65,6 +66,7 @@ func newCategoryTableImpl(schemaName, tableName, alias string) categoryTable {
|
|||
LastUpdateColumn = postgres.TimestampColumn("last_update")
|
||||
allColumns = postgres.ColumnList{CategoryIDColumn, NameColumn, LastUpdateColumn}
|
||||
mutableColumns = postgres.ColumnList{NameColumn, LastUpdateColumn}
|
||||
defaultColumns = postgres.ColumnList{CategoryIDColumn, LastUpdateColumn}
|
||||
)
|
||||
|
||||
return categoryTable{
|
||||
|
|
@ -77,5 +79,6 @@ func newCategoryTableImpl(schemaName, tableName, alias string) categoryTable {
|
|||
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
DefaultColumns: defaultColumns,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ var Film = newFilmTable("dvds", "film", "")
|
|||
type filmTable struct {
|
||||
postgres.Table
|
||||
|
||||
//Columns
|
||||
// Columns
|
||||
FilmID postgres.ColumnInteger
|
||||
Title postgres.ColumnString
|
||||
Description postgres.ColumnString
|
||||
|
|
@ -28,11 +28,12 @@ type filmTable struct {
|
|||
ReplacementCost postgres.ColumnFloat
|
||||
Rating postgres.ColumnString
|
||||
LastUpdate postgres.ColumnTimestamp
|
||||
SpecialFeatures postgres.ColumnString
|
||||
SpecialFeatures postgres.ColumnStringArray
|
||||
Fulltext postgres.ColumnString
|
||||
|
||||
AllColumns postgres.ColumnList
|
||||
MutableColumns postgres.ColumnList
|
||||
DefaultColumns postgres.ColumnList
|
||||
}
|
||||
|
||||
type FilmTable struct {
|
||||
|
|
@ -81,10 +82,11 @@ func newFilmTableImpl(schemaName, tableName, alias string) filmTable {
|
|||
ReplacementCostColumn = postgres.FloatColumn("replacement_cost")
|
||||
RatingColumn = postgres.StringColumn("rating")
|
||||
LastUpdateColumn = postgres.TimestampColumn("last_update")
|
||||
SpecialFeaturesColumn = postgres.StringColumn("special_features")
|
||||
SpecialFeaturesColumn = postgres.StringArrayColumn("special_features")
|
||||
FulltextColumn = postgres.StringColumn("fulltext")
|
||||
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}
|
||||
defaultColumns = postgres.ColumnList{FilmIDColumn, RentalDurationColumn, RentalRateColumn, ReplacementCostColumn, RatingColumn, LastUpdateColumn}
|
||||
)
|
||||
|
||||
return filmTable{
|
||||
|
|
@ -107,5 +109,6 @@ func newFilmTableImpl(schemaName, tableName, alias string) filmTable {
|
|||
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
DefaultColumns: defaultColumns,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,14 @@ var FilmActor = newFilmActorTable("dvds", "film_actor", "")
|
|||
type filmActorTable struct {
|
||||
postgres.Table
|
||||
|
||||
//Columns
|
||||
// Columns
|
||||
ActorID postgres.ColumnInteger
|
||||
FilmID postgres.ColumnInteger
|
||||
LastUpdate postgres.ColumnTimestamp
|
||||
|
||||
AllColumns postgres.ColumnList
|
||||
MutableColumns postgres.ColumnList
|
||||
DefaultColumns postgres.ColumnList
|
||||
}
|
||||
|
||||
type FilmActorTable struct {
|
||||
|
|
@ -65,6 +66,7 @@ func newFilmActorTableImpl(schemaName, tableName, alias string) filmActorTable {
|
|||
LastUpdateColumn = postgres.TimestampColumn("last_update")
|
||||
allColumns = postgres.ColumnList{ActorIDColumn, FilmIDColumn, LastUpdateColumn}
|
||||
mutableColumns = postgres.ColumnList{LastUpdateColumn}
|
||||
defaultColumns = postgres.ColumnList{LastUpdateColumn}
|
||||
)
|
||||
|
||||
return filmActorTable{
|
||||
|
|
@ -77,5 +79,6 @@ func newFilmActorTableImpl(schemaName, tableName, alias string) filmActorTable {
|
|||
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
DefaultColumns: defaultColumns,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,14 @@ var FilmCategory = newFilmCategoryTable("dvds", "film_category", "")
|
|||
type filmCategoryTable struct {
|
||||
postgres.Table
|
||||
|
||||
//Columns
|
||||
// Columns
|
||||
FilmID postgres.ColumnInteger
|
||||
CategoryID postgres.ColumnInteger
|
||||
LastUpdate postgres.ColumnTimestamp
|
||||
|
||||
AllColumns postgres.ColumnList
|
||||
MutableColumns postgres.ColumnList
|
||||
DefaultColumns postgres.ColumnList
|
||||
}
|
||||
|
||||
type FilmCategoryTable struct {
|
||||
|
|
@ -65,6 +66,7 @@ func newFilmCategoryTableImpl(schemaName, tableName, alias string) filmCategoryT
|
|||
LastUpdateColumn = postgres.TimestampColumn("last_update")
|
||||
allColumns = postgres.ColumnList{FilmIDColumn, CategoryIDColumn, LastUpdateColumn}
|
||||
mutableColumns = postgres.ColumnList{LastUpdateColumn}
|
||||
defaultColumns = postgres.ColumnList{LastUpdateColumn}
|
||||
)
|
||||
|
||||
return filmCategoryTable{
|
||||
|
|
@ -77,5 +79,6 @@ func newFilmCategoryTableImpl(schemaName, tableName, alias string) filmCategoryT
|
|||
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
DefaultColumns: defaultColumns,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,14 @@ var Language = newLanguageTable("dvds", "language", "")
|
|||
type languageTable struct {
|
||||
postgres.Table
|
||||
|
||||
//Columns
|
||||
// Columns
|
||||
LanguageID postgres.ColumnInteger
|
||||
Name postgres.ColumnString
|
||||
LastUpdate postgres.ColumnTimestamp
|
||||
|
||||
AllColumns postgres.ColumnList
|
||||
MutableColumns postgres.ColumnList
|
||||
DefaultColumns postgres.ColumnList
|
||||
}
|
||||
|
||||
type LanguageTable struct {
|
||||
|
|
@ -65,6 +66,7 @@ func newLanguageTableImpl(schemaName, tableName, alias string) languageTable {
|
|||
LastUpdateColumn = postgres.TimestampColumn("last_update")
|
||||
allColumns = postgres.ColumnList{LanguageIDColumn, NameColumn, LastUpdateColumn}
|
||||
mutableColumns = postgres.ColumnList{NameColumn, LastUpdateColumn}
|
||||
defaultColumns = postgres.ColumnList{LanguageIDColumn, LastUpdateColumn}
|
||||
)
|
||||
|
||||
return languageTable{
|
||||
|
|
@ -77,5 +79,6 @@ func newLanguageTableImpl(schemaName, tableName, alias string) languageTable {
|
|||
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
DefaultColumns: defaultColumns,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ var ActorInfo = newActorInfoTable("dvds", "actor_info", "")
|
|||
type actorInfoTable struct {
|
||||
postgres.Table
|
||||
|
||||
//Columns
|
||||
// Columns
|
||||
ActorID postgres.ColumnInteger
|
||||
FirstName postgres.ColumnString
|
||||
LastName postgres.ColumnString
|
||||
|
|
@ -24,6 +24,7 @@ type actorInfoTable struct {
|
|||
|
||||
AllColumns postgres.ColumnList
|
||||
MutableColumns postgres.ColumnList
|
||||
DefaultColumns postgres.ColumnList
|
||||
}
|
||||
|
||||
type ActorInfoTable struct {
|
||||
|
|
@ -67,6 +68,7 @@ func newActorInfoTableImpl(schemaName, tableName, alias string) actorInfoTable {
|
|||
FilmInfoColumn = postgres.StringColumn("film_info")
|
||||
allColumns = postgres.ColumnList{ActorIDColumn, FirstNameColumn, LastNameColumn, FilmInfoColumn}
|
||||
mutableColumns = postgres.ColumnList{ActorIDColumn, FirstNameColumn, LastNameColumn, FilmInfoColumn}
|
||||
defaultColumns = postgres.ColumnList{}
|
||||
)
|
||||
|
||||
return actorInfoTable{
|
||||
|
|
@ -80,5 +82,6 @@ func newActorInfoTableImpl(schemaName, tableName, alias string) actorInfoTable {
|
|||
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
DefaultColumns: defaultColumns,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ var CustomerList = newCustomerListTable("dvds", "customer_list", "")
|
|||
type customerListTable struct {
|
||||
postgres.Table
|
||||
|
||||
//Columns
|
||||
// Columns
|
||||
ID postgres.ColumnInteger
|
||||
Name postgres.ColumnString
|
||||
Address postgres.ColumnString
|
||||
|
|
@ -29,6 +29,7 @@ type customerListTable struct {
|
|||
|
||||
AllColumns postgres.ColumnList
|
||||
MutableColumns postgres.ColumnList
|
||||
DefaultColumns postgres.ColumnList
|
||||
}
|
||||
|
||||
type CustomerListTable struct {
|
||||
|
|
@ -77,6 +78,7 @@ func newCustomerListTableImpl(schemaName, tableName, alias string) customerListT
|
|||
SidColumn = postgres.IntegerColumn("sid")
|
||||
allColumns = postgres.ColumnList{IDColumn, NameColumn, AddressColumn, ZipCodeColumn, PhoneColumn, CityColumn, CountryColumn, NotesColumn, SidColumn}
|
||||
mutableColumns = postgres.ColumnList{IDColumn, NameColumn, AddressColumn, ZipCodeColumn, PhoneColumn, CityColumn, CountryColumn, NotesColumn, SidColumn}
|
||||
defaultColumns = postgres.ColumnList{}
|
||||
)
|
||||
|
||||
return customerListTable{
|
||||
|
|
@ -95,5 +97,6 @@ func newCustomerListTableImpl(schemaName, tableName, alias string) customerListT
|
|||
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
DefaultColumns: defaultColumns,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
|
||||
# Quick start example
|
||||
|
||||
This package contains sample usage for Jet framework.
|
||||
|
||||
Jet generated files of interest are in `./gen` folder.
|
||||
|
||||
`quick-start.go` - contains code explained at main [README.md](../../README.md#quick-start),
|
||||
with a difference of redirecting json output to files(`dest.json` and `dest2.json`) rather then to a
|
||||
standard output.
|
||||
|
||||
`./gen`, `dest.json` and `dest2.json` - added into git for presentation purposes.
|
||||
|
||||
# Quick start example
|
||||
|
||||
This package contains sample usage for Jet framework.
|
||||
|
||||
Jet generated files of interest are in `./gen` folder.
|
||||
|
||||
`quick-start.go` - contains code explained at main [README.md](../../README.md#quick-start),
|
||||
with a difference of redirecting json output to files(`dest.json` and `dest2.json`) rather then to a
|
||||
standard output.
|
||||
|
||||
`./gen`, `dest.json` and `dest2.json` - added into git for presentation purposes.
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -35,9 +35,9 @@ func main() {
|
|||
|
||||
// Write query
|
||||
stmt := SELECT(
|
||||
Actor.ActorID, Actor.FirstName, Actor.LastName, Actor.LastUpdate,
|
||||
Actor.ActorID, Actor.FirstName, Actor.LastName, Actor.LastUpdate, // or just Actor.AllColumns
|
||||
Film.AllColumns,
|
||||
Language.AllColumns.Except(Language.LastUpdate),
|
||||
Language.AllColumns.Except(Language.LastUpdate), // all language columns except last_update
|
||||
Category.AllColumns,
|
||||
).FROM(
|
||||
Actor.
|
||||
|
|
@ -47,10 +47,13 @@ func main() {
|
|||
INNER_JOIN(FilmCategory, FilmCategory.FilmID.EQ(Film.FilmID)).
|
||||
INNER_JOIN(Category, Category.CategoryID.EQ(FilmCategory.CategoryID)),
|
||||
).WHERE(
|
||||
Language.Name.EQ(Char(20)("English")).
|
||||
AND(Category.Name.NOT_EQ(Text("Action"))).
|
||||
AND(Film.Length.GT(Int(180))).
|
||||
AND(Film.Rating.NOT_EQ(enum.MpaaRating.R)),
|
||||
AND(
|
||||
Language.Name.EQ(Char(20)("English")), // string columns Language.Name and Category.Name can be compared only with string expression
|
||||
Category.Name.NOT_EQ(Text("Action")),
|
||||
Film.Length.GT(Int32(180)), // Film.Length is integer column and can be compared only with integer expression
|
||||
Film.Rating.NOT_EQ(enum.MpaaRating.R),
|
||||
String("Trailers").EQ(ANY(Film.SpecialFeatures)), // type safety is also enforced on array element types
|
||||
),
|
||||
).ORDER_BY(
|
||||
Actor.ActorID.ASC(),
|
||||
Film.FilmID.ASC(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue