volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

Type time in Postgres #244

Closed saulortega closed 6 years ago

saulortega commented 6 years ago

What version of SQLBoiler are you using (sqlboiler --version)?

SQLBoiler v2.6.0

If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)

go test ./models/

If this happened at runtime what code produced the issue? (if not applicable leave blank)

What is the output of the command above with the -d flag added to it? (Provided you are comfortable sharing this, it contains a blueprint of your schema)

-d flag not recognized: flag provided but not defined: -d

Only go test ./models/:

go test ./models/
--- FAIL: TestDelete (0.00s)
    --- FAIL: TestDelete/Shifts (0.00s)
        shifts_test.go:38: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
        shifts_test.go:42: models: unable to delete from shifts: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:47: models: failed to count shifts rows: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
--- FAIL: TestQueryDeleteAll (0.00s)
    --- FAIL: TestQueryDeleteAll/Shifts (0.01s)
        shifts_test.go:68: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
        shifts_test.go:72: models: unable to delete all from shifts: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:77: models: failed to count shifts rows: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
--- FAIL: TestSliceDeleteAll (0.00s)
    --- FAIL: TestSliceDeleteAll/Shifts (0.01s)
        shifts_test.go:98: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
        shifts_test.go:104: models: unable to delete all from shift slice: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:109: models: failed to count shifts rows: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
--- FAIL: TestExists (0.00s)
    --- FAIL: TestExists/Shifts (0.01s)
        shifts_test.go:129: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
        shifts_test.go:134: Unable to check if Shift exists: models: unable to check if shifts exists: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:137: Expected ShiftExistsG to return true, but got false.
--- FAIL: TestFind (0.00s)
    --- FAIL: TestFind/Shifts (0.00s)
        shifts_test.go:153: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
        shifts_test.go:158: models: unable to select from shifts: bind failed to execute query: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:162: want a record, got nil
--- FAIL: TestBind (0.00s)
    --- FAIL: TestBind/Shifts (0.01s)
        shifts_test.go:178: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
        shifts_test.go:182: bind failed to execute query: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
--- FAIL: TestOne (0.00s)
    --- FAIL: TestOne/Shifts (0.00s)
        shifts_test.go:199: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
        shifts_test.go:203: models: failed to execute a one query for shifts: bind failed to execute query: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
--- FAIL: TestAll (0.00s)
    --- FAIL: TestAll/Shifts (0.01s)
        shifts_test.go:226: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «A»
        shifts_test.go:229: models: unable to insert into shifts: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:234: models: failed to assign all query results to Shift slice: bind failed to execute query: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:238: want 2 records, got: 0
--- FAIL: TestCount (0.00s)
    --- FAIL: TestCount/Shifts (0.01s)
        shifts_test.go:259: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «A»
        shifts_test.go:262: models: unable to insert into shifts: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:267: models: failed to count shifts rows: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:271: want 2 records, got: 0
--- FAIL: TestInsert (0.00s)
    --- FAIL: TestInsert/Shifts (0.00s)
        shifts_test.go:426: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
        shifts_test.go:431: models: failed to count shifts rows: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:435: want one record, got: 0
    --- FAIL: TestInsert/Shifts#01 (0.01s)
        shifts_test.go:452: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «G»
        shifts_test.go:457: models: failed to count shifts rows: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:461: want one record, got: 0
--- FAIL: TestToOne (0.01s)
    --- FAIL: TestToOne/ScheduleToShiftUsingMondayShift (0.00s)
        schedules_test.go:483: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «X»
    --- FAIL: TestToOne/ScheduleToShiftUsingTuesdayShift (0.00s)
        schedules_test.go:535: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «X»
    --- FAIL: TestToOne/ScheduleToShiftUsingWednesdayShift (0.00s)
        schedules_test.go:587: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «X»
    --- FAIL: TestToOne/ScheduleToShiftUsingThursdayShift (0.00s)
        schedules_test.go:639: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «X»
    --- FAIL: TestToOne/ScheduleToShiftUsingFridayShift (0.00s)
        schedules_test.go:691: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «X»
    --- FAIL: TestToOne/ScheduleToShiftUsingSaturdayShift (0.00s)
        schedules_test.go:743: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «X»
    --- FAIL: TestToOne/ScheduleToShiftUsingSundayShift (0.00s)
        schedules_test.go:795: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «X»
--- FAIL: TestToMany (0.01s)
    --- FAIL: TestToMany/ShiftToMondayShiftSchedules (0.00s)
        shifts_test.go:479: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
    --- FAIL: TestToMany/ShiftToTuesdayShiftSchedules (0.00s)
        shifts_test.go:553: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
    --- FAIL: TestToMany/ShiftToWednesdayShiftSchedules (0.00s)
        shifts_test.go:627: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
    --- FAIL: TestToMany/ShiftToThursdayShiftSchedules (0.00s)
        shifts_test.go:701: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
    --- FAIL: TestToMany/ShiftToFridayShiftSchedules (0.00s)
        shifts_test.go:775: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
    --- FAIL: TestToMany/ShiftToSaturdayShiftSchedules (0.00s)
        shifts_test.go:849: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
    --- FAIL: TestToMany/ShiftToSundayShiftSchedules (0.00s)
        shifts_test.go:923: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
--- FAIL: TestToOneSet (0.01s)
    --- FAIL: TestToOneSet/ScheduleToShiftUsingMondayShift (0.00s)
        schedules_test.go:853: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «T»
    --- FAIL: TestToOneSet/ScheduleToShiftUsingTuesdayShift (0.00s)
        schedules_test.go:960: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «T»
    --- FAIL: TestToOneSet/ScheduleToShiftUsingWednesdayShift (0.00s)
        schedules_test.go:1067: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «T»
    --- FAIL: TestToOneSet/ScheduleToShiftUsingThursdayShift (0.00s)
        schedules_test.go:1174: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «T»
    --- FAIL: TestToOneSet/ScheduleToShiftUsingFridayShift (0.00s)
        schedules_test.go:1281: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «T»
    --- FAIL: TestToOneSet/ScheduleToShiftUsingSaturdayShift (0.00s)
        schedules_test.go:1388: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «T»
    --- FAIL: TestToOneSet/ScheduleToShiftUsingSundayShift (0.00s)
        schedules_test.go:1495: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «T»
--- FAIL: TestToOneRemove (0.01s)
    --- FAIL: TestToOneRemove/ScheduleToShiftUsingMondayShift (0.00s)
        schedules_test.go:908: failed to insert into foreign table: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «T»
    --- FAIL: TestToOneRemove/ScheduleToShiftUsingTuesdayShift (0.00s)
        schedules_test.go:1015: failed to insert into foreign table: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «T»
    --- FAIL: TestToOneRemove/ScheduleToShiftUsingWednesdayShift (0.00s)
        schedules_test.go:1122: failed to insert into foreign table: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «T»
    --- FAIL: TestToOneRemove/ScheduleToShiftUsingThursdayShift (0.00s)
        schedules_test.go:1229: failed to insert into foreign table: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «T»
    --- FAIL: TestToOneRemove/ScheduleToShiftUsingFridayShift (0.00s)
        schedules_test.go:1336: failed to insert into foreign table: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «T»
    --- FAIL: TestToOneRemove/ScheduleToShiftUsingSaturdayShift (0.00s)
        schedules_test.go:1443: failed to insert into foreign table: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «T»
    --- FAIL: TestToOneRemove/ScheduleToShiftUsingSundayShift (0.00s)
        schedules_test.go:1550: failed to insert into foreign table: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «T»
--- FAIL: TestToManyAdd (0.01s)
    --- FAIL: TestToManyAdd/ShiftToMondayShiftSchedules (0.00s)
        shifts_test.go:1004: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManyAdd/ShiftToTuesdayShiftSchedules (0.00s)
        shifts_test.go:1252: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManyAdd/ShiftToWednesdayShiftSchedules (0.00s)
        shifts_test.go:1500: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManyAdd/ShiftToThursdayShiftSchedules (0.00s)
        shifts_test.go:1748: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManyAdd/ShiftToFridayShiftSchedules (0.00s)
        shifts_test.go:1996: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManyAdd/ShiftToSaturdayShiftSchedules (0.00s)
        shifts_test.go:2244: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManyAdd/ShiftToSundayShiftSchedules (0.00s)
        shifts_test.go:2492: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
--- FAIL: TestToManySet (0.01s)
    --- FAIL: TestToManySet/ShiftToMondayShiftSchedules (0.00s)
        shifts_test.go:1079: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManySet/ShiftToTuesdayShiftSchedules (0.00s)
        shifts_test.go:1327: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManySet/ShiftToWednesdayShiftSchedules (0.00s)
        shifts_test.go:1575: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManySet/ShiftToThursdayShiftSchedules (0.00s)
        shifts_test.go:1823: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManySet/ShiftToFridayShiftSchedules (0.00s)
        shifts_test.go:2071: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManySet/ShiftToSaturdayShiftSchedules (0.00s)
        shifts_test.go:2319: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManySet/ShiftToSundayShiftSchedules (0.00s)
        shifts_test.go:2567: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
--- FAIL: TestToManyRemove (0.01s)
    --- FAIL: TestToManyRemove/ShiftToMondayShiftSchedules (0.00s)
        shifts_test.go:1169: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManyRemove/ShiftToTuesdayShiftSchedules (0.00s)
        shifts_test.go:1417: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManyRemove/ShiftToWednesdayShiftSchedules (0.00s)
        shifts_test.go:1665: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManyRemove/ShiftToThursdayShiftSchedules (0.00s)
        shifts_test.go:1913: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManyRemove/ShiftToFridayShiftSchedules (0.00s)
        shifts_test.go:2161: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManyRemove/ShiftToSaturdayShiftSchedules (0.00s)
        shifts_test.go:2409: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
    --- FAIL: TestToManyRemove/ShiftToSundayShiftSchedules (0.00s)
        shifts_test.go:2657: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «B»
--- FAIL: TestReload (0.00s)
    --- FAIL: TestReload/Shifts (0.00s)
        shifts_test.go:2732: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
        shifts_test.go:2736: models: unable to select from shifts: bind failed to execute query: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
--- FAIL: TestReloadAll (0.00s)
    --- FAIL: TestReloadAll/Shifts (0.00s)
        shifts_test.go:2753: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
        shifts_test.go:2759: models: unable to reload all in ShiftSlice: bind failed to execute query: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
--- FAIL: TestSelect (0.00s)
    --- FAIL: TestSelect/Shifts (0.01s)
        shifts_test.go:2775: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
        shifts_test.go:2780: models: failed to assign all query results to Shift slice: bind failed to execute query: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:2784: want one record, got: 0
--- FAIL: TestUpdate (0.00s)
    --- FAIL: TestUpdate/Shifts (0.01s)
        shifts_test.go:2810: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
        shifts_test.go:2815: models: failed to count shifts rows: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:2819: want one record, got: 0
        shifts_test.go:2827: models: unable to update shifts row: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
--- FAIL: TestSliceUpdateAll (0.00s)
    --- FAIL: TestSliceUpdateAll/Shifts (0.01s)
        shifts_test.go:2848: models: unable to insert into shifts: pq: la sintaxis de entrada no es válida para tipo time: «D»
        shifts_test.go:2853: models: failed to count shifts rows: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:2857: want one record, got: 0
        shifts_test.go:2883: models: unable to update all in shift slice: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
--- FAIL: TestUpsert (0.00s)
    --- FAIL: TestUpsert/Shifts (0.01s)
        shifts_test.go:2904: Unable to upsert Shift: models: unable to upsert shifts: pq: la sintaxis de entrada no es válida para tipo time: «G»
        shifts_test.go:2909: models: failed to count shifts rows: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:2912: want one record, got: 0
        shifts_test.go:2921: Unable to upsert Shift: models: unable to upsert shifts: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:2926: models: failed to count shifts rows: pq: transacción abortada, las órdenes serán ignoradas hasta el fin de bloque de transacción
        shifts_test.go:2929: want one record, got: 0
FAIL

Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)

CREATE TABLE public.shifts
(
    id bigint NOT NULL DEFAULT nextval('shifts_id_seq'::regclass),
    description character varying COLLATE pg_catalog."default" NOT NULL,
    start_time time(6) without time zone,
    end_time time(6) without time zone,
    next_day boolean NOT NULL DEFAULT false,
    enabled boolean NOT NULL DEFAULT true,
    created_at timestamp without time zone NOT NULL DEFAULT now(),
    updated_at timestamp without time zone,
    deleted_at timestamp without time zone,
    CONSTRAINT shifts_pkey PRIMARY KEY (id)
)

Further information. What did you do, what did you expect?

I expected a time.Time type, not string:

// Shift is an object representing the database table.
type Shift struct {
    ID          int64       `boil:"id" json:"id" toml:"id" yaml:"id"`
    Description string      `boil:"description" json:"description" toml:"description" yaml:"description"`
    StartTime   null.String `boil:"start_time" json:"start_time,omitempty" toml:"start_time" yaml:"start_time,omitempty"`
    EndTime     null.String `boil:"end_time" json:"end_time,omitempty" toml:"end_time" yaml:"end_time,omitempty"`
    NextDay     bool        `boil:"next_day" json:"next_day" toml:"next_day" yaml:"next_day"`
    Enabled     bool        `boil:"enabled" json:"enabled" toml:"enabled" yaml:"enabled"`
    CreatedAt   time.Time   `boil:"created_at" json:"created_at" toml:"created_at" yaml:"created_at"`
    UpdatedAt   null.Time   `boil:"updated_at" json:"updated_at,omitempty" toml:"updated_at" yaml:"updated_at,omitempty"`
    DeletedAt   null.Time   `boil:"deleted_at" json:"deleted_at,omitempty" toml:"deleted_at" yaml:"deleted_at,omitempty"`

    R *shiftR `boil:"-" json:"-" toml:"-" yaml:"-"`
    L shiftL  `boil:"-" json:"-" toml:"-" yaml:"-"`
}
saulortega commented 6 years ago

Maybe you have to add "time with time zone" and "time without time zone" in postgres.go:

case "date", "time", "timestamp without time zone", "timestamp with time zone":
            c.Type = "time.Time"
aarondl commented 6 years ago

Very likely. Have you tried this change to see if it helped?

saulortega commented 6 years ago

I just tried, and yes, it works with this simple change.

I submited a PR: https://github.com/volatiletech/sqlboiler/pull/253