Additional tests.
This commit is contained in:
parent
4ee047a675
commit
89e93710aa
4 changed files with 262 additions and 26 deletions
|
|
@ -1688,3 +1688,192 @@ func TestCamelCaseModelJsonTag(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeneratorTestSample(t *testing.T) {
|
||||
|
||||
err := postgres.GenerateDSN(defaultDSN(), "test_sample", genTestDir2)
|
||||
require.NoError(t, err)
|
||||
|
||||
modelDir := filepath.Join(testRoot, "/postgres/.gentestdata2/jetdb/test_sample/model/")
|
||||
tableDir := filepath.Join(testRoot, "/postgres/.gentestdata2/jetdb/test_sample/table/")
|
||||
|
||||
testutils.AssertFileContent(t, modelDir+"/sample_arrays.go", `
|
||||
//
|
||||
// Code generated by go-jet DO NOT EDIT.
|
||||
//
|
||||
// WARNING: Changes to this file may cause incorrect behavior
|
||||
// and will be lost if the code is regenerated
|
||||
//
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
type SampleArrays struct {
|
||||
ID int32 `+"`sql:\"primary_key\"`"+`
|
||||
BoolArray *pq.BoolArray
|
||||
Int2ArrayPtr *pq.StringArray
|
||||
Int4Array pq.Int32Array
|
||||
Int8Array pq.Int64Array
|
||||
NumericArray pq.Float64Array
|
||||
DecimalArray pq.Float64Array
|
||||
RealArray pq.Float32Array
|
||||
DoubleArray pq.Float64Array
|
||||
TextArray pq.StringArray
|
||||
VarcharArray pq.StringArray
|
||||
CharArray pq.StringArray
|
||||
ByteaArray pq.ByteaArray
|
||||
DateArray pq.StringArray
|
||||
TimestampArray *pq.StringArray
|
||||
TimestamptzArray pq.StringArray
|
||||
TimeArray pq.StringArray
|
||||
TimetzArray pq.StringArray
|
||||
IntervalArray pq.StringArray
|
||||
UUIDArray pq.StringArray
|
||||
MoodEnumArray pq.StringArray
|
||||
}
|
||||
`)
|
||||
|
||||
testutils.AssertFileContent(t, tableDir+"/sample_arrays.go", `
|
||||
//
|
||||
// Code generated by go-jet DO NOT EDIT.
|
||||
//
|
||||
// WARNING: Changes to this file may cause incorrect behavior
|
||||
// and will be lost if the code is regenerated
|
||||
//
|
||||
|
||||
package table
|
||||
|
||||
import (
|
||||
"github.com/go-jet/jet/v2/postgres"
|
||||
)
|
||||
|
||||
var SampleArrays = newSampleArraysTable("test_sample", "sample_arrays", "")
|
||||
|
||||
type sampleArraysTable struct {
|
||||
postgres.Table
|
||||
|
||||
// Columns
|
||||
ID postgres.ColumnInteger
|
||||
BoolArray postgres.ColumnBoolArray
|
||||
Int2ArrayPtr postgres.ColumnIntegerArray
|
||||
Int4Array postgres.ColumnIntegerArray
|
||||
Int8Array postgres.ColumnIntegerArray
|
||||
NumericArray postgres.ColumnFloatArray
|
||||
DecimalArray postgres.ColumnFloatArray
|
||||
RealArray postgres.ColumnFloatArray
|
||||
DoubleArray postgres.ColumnFloatArray
|
||||
TextArray postgres.ColumnStringArray
|
||||
VarcharArray postgres.ColumnStringArray
|
||||
CharArray postgres.ColumnStringArray
|
||||
ByteaArray postgres.ColumnByteaArray
|
||||
DateArray postgres.ColumnDateArray
|
||||
TimestampArray postgres.ColumnTimestampArray
|
||||
TimestamptzArray postgres.ColumnTimestampzArray
|
||||
TimeArray postgres.ColumnTimeArray
|
||||
TimetzArray postgres.ColumnTimezArray
|
||||
IntervalArray postgres.ColumnIntervalArray
|
||||
UUIDArray postgres.ColumnStringArray
|
||||
MoodEnumArray postgres.ColumnStringArray
|
||||
|
||||
AllColumns postgres.ColumnList
|
||||
MutableColumns postgres.ColumnList
|
||||
DefaultColumns postgres.ColumnList
|
||||
}
|
||||
|
||||
type SampleArraysTable struct {
|
||||
sampleArraysTable
|
||||
|
||||
EXCLUDED sampleArraysTable
|
||||
}
|
||||
|
||||
// AS creates new SampleArraysTable with assigned alias
|
||||
func (a SampleArraysTable) AS(alias string) *SampleArraysTable {
|
||||
return newSampleArraysTable(a.SchemaName(), a.TableName(), alias)
|
||||
}
|
||||
|
||||
// Schema creates new SampleArraysTable with assigned schema name
|
||||
func (a SampleArraysTable) FromSchema(schemaName string) *SampleArraysTable {
|
||||
return newSampleArraysTable(schemaName, a.TableName(), a.Alias())
|
||||
}
|
||||
|
||||
// WithPrefix creates new SampleArraysTable with assigned table prefix
|
||||
func (a SampleArraysTable) WithPrefix(prefix string) *SampleArraysTable {
|
||||
return newSampleArraysTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||
}
|
||||
|
||||
// WithSuffix creates new SampleArraysTable with assigned table suffix
|
||||
func (a SampleArraysTable) WithSuffix(suffix string) *SampleArraysTable {
|
||||
return newSampleArraysTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||
}
|
||||
|
||||
func newSampleArraysTable(schemaName, tableName, alias string) *SampleArraysTable {
|
||||
return &SampleArraysTable{
|
||||
sampleArraysTable: newSampleArraysTableImpl(schemaName, tableName, alias),
|
||||
EXCLUDED: newSampleArraysTableImpl("", "excluded", ""),
|
||||
}
|
||||
}
|
||||
|
||||
func newSampleArraysTableImpl(schemaName, tableName, alias string) sampleArraysTable {
|
||||
var (
|
||||
IDColumn = postgres.IntegerColumn("id")
|
||||
BoolArrayColumn = postgres.BoolArrayColumn("bool_array")
|
||||
Int2ArrayPtrColumn = postgres.IntegerArrayColumn("int2_array_ptr")
|
||||
Int4ArrayColumn = postgres.IntegerArrayColumn("int4_array")
|
||||
Int8ArrayColumn = postgres.IntegerArrayColumn("int8_array")
|
||||
NumericArrayColumn = postgres.FloatArrayColumn("numeric_array")
|
||||
DecimalArrayColumn = postgres.FloatArrayColumn("decimal_array")
|
||||
RealArrayColumn = postgres.FloatArrayColumn("real_array")
|
||||
DoubleArrayColumn = postgres.FloatArrayColumn("double_array")
|
||||
TextArrayColumn = postgres.StringArrayColumn("text_array")
|
||||
VarcharArrayColumn = postgres.StringArrayColumn("varchar_array")
|
||||
CharArrayColumn = postgres.StringArrayColumn("char_array")
|
||||
ByteaArrayColumn = postgres.ByteaArrayColumn("bytea_array")
|
||||
DateArrayColumn = postgres.DateArrayColumn("date_array")
|
||||
TimestampArrayColumn = postgres.TimestampArrayColumn("timestamp_array")
|
||||
TimestamptzArrayColumn = postgres.TimestampzArrayColumn("timestamptz_array")
|
||||
TimeArrayColumn = postgres.TimeArrayColumn("time_array")
|
||||
TimetzArrayColumn = postgres.TimezArrayColumn("timetz_array")
|
||||
IntervalArrayColumn = postgres.IntervalArrayColumn("interval_array")
|
||||
UUIDArrayColumn = postgres.StringArrayColumn("uuid_array")
|
||||
MoodEnumArrayColumn = postgres.StringArrayColumn("mood_enum_array")
|
||||
allColumns = postgres.ColumnList{IDColumn, BoolArrayColumn, Int2ArrayPtrColumn, Int4ArrayColumn, Int8ArrayColumn, NumericArrayColumn, DecimalArrayColumn, RealArrayColumn, DoubleArrayColumn, TextArrayColumn, VarcharArrayColumn, CharArrayColumn, ByteaArrayColumn, DateArrayColumn, TimestampArrayColumn, TimestamptzArrayColumn, TimeArrayColumn, TimetzArrayColumn, IntervalArrayColumn, UUIDArrayColumn, MoodEnumArrayColumn}
|
||||
mutableColumns = postgres.ColumnList{BoolArrayColumn, Int2ArrayPtrColumn, Int4ArrayColumn, Int8ArrayColumn, NumericArrayColumn, DecimalArrayColumn, RealArrayColumn, DoubleArrayColumn, TextArrayColumn, VarcharArrayColumn, CharArrayColumn, ByteaArrayColumn, DateArrayColumn, TimestampArrayColumn, TimestamptzArrayColumn, TimeArrayColumn, TimetzArrayColumn, IntervalArrayColumn, UUIDArrayColumn, MoodEnumArrayColumn}
|
||||
defaultColumns = postgres.ColumnList{IDColumn, Int4ArrayColumn, Int8ArrayColumn, TextArrayColumn}
|
||||
)
|
||||
|
||||
return sampleArraysTable{
|
||||
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||
|
||||
//Columns
|
||||
ID: IDColumn,
|
||||
BoolArray: BoolArrayColumn,
|
||||
Int2ArrayPtr: Int2ArrayPtrColumn,
|
||||
Int4Array: Int4ArrayColumn,
|
||||
Int8Array: Int8ArrayColumn,
|
||||
NumericArray: NumericArrayColumn,
|
||||
DecimalArray: DecimalArrayColumn,
|
||||
RealArray: RealArrayColumn,
|
||||
DoubleArray: DoubleArrayColumn,
|
||||
TextArray: TextArrayColumn,
|
||||
VarcharArray: VarcharArrayColumn,
|
||||
CharArray: CharArrayColumn,
|
||||
ByteaArray: ByteaArrayColumn,
|
||||
DateArray: DateArrayColumn,
|
||||
TimestampArray: TimestampArrayColumn,
|
||||
TimestamptzArray: TimestamptzArrayColumn,
|
||||
TimeArray: TimeArrayColumn,
|
||||
TimetzArray: TimetzArrayColumn,
|
||||
IntervalArray: IntervalArrayColumn,
|
||||
UUIDArray: UUIDArrayColumn,
|
||||
MoodEnumArray: MoodEnumArrayColumn,
|
||||
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
DefaultColumns: defaultColumns,
|
||||
}
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue