-
I essentially have the following: package jetgen
type Facility string package main()
type FacilitiesArray []jetgen.Facility
type Listing struct {
// Various stuff here
.
.
.
Facilities FacilitiesArray
}
func GetListing(...) (*Listing, error) {
selectStatement := SELECT(
// stuff
).FROM(
t.Listings
).WHERE(
t.Listings.ID.EQ(UUID(parsedID)),
)
var dest Listing
err = selectStatement.Query(db.DB, &dest)
if err != nil {
return nil, err
}
return Listing
} The above works, but the Facilities just becomes an array with one element with the sql array in it, e.g. "Facilities": ["{ELEVATOR,AIR_CONDITIONING,CHARGING,BROADBAND,GARAGE_PARKING,HIKING}"] So I want to implement the scan interface in order to parse the thing. So I do func (f *FacilitiesArray) Scan(src any) error {
logging.Logger.Error().Any("src", src).Msg("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
fmt.Println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
// This code doesn't make much sense at the moment, but I just want to get something to happen here
temp := []jetgen.Facility{"QUIET", "VIEW"}
*f = FacilitiesArray(temp)
return nil
} then the facilities I get is empty:
I also get no "AAAAAAAAAAAAAAAAAAAAAAAAA" in my console. So it seems like go-jet detects that there is a scanner available (because the facilities become null), but I can't see any evidence that the scanner is actually invoked. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
What is the database, driver and jet version? selectStatement := SELECT(
// stuff
).FROM( |
Beta Was this translation helpful? Give feedback.
-
The database is Postgres 17 The function is basically: facilitiesAgg := SELECT(
t.ListingFacilities.ListingID,
ARRAY_AGG(t.ListingFacilities.Facility).AS("facilities"),
).FROM(
t.ListingFacilities,
).GROUP_BY(
t.ListingFacilities.ListingID,
).AsTable("agg")
selectStatement := SELECT(
facilitiesAgg.AllColumns().Except(
t.ListingFacilities.ListingID,
).As(""),
).FROM(
t.Listings.LEFT_JOIN(
facilitiesAgg, t.Listings.ID.EQ(t.ListingFacilities.ListingID.From(facilitiesAgg)),
),
).WHERE(
t.Listings.ID.EQ(UUID(parsedID)),
)
logger.Error().Func(func(e *zerolog.Event) {
query, args := selectStatement.Sql()
e.Str("query", query).Any("args", args).Str("id", id)
}).Msg("Retrieving listing by ID")
var dest Listing
err = selectStatement.Query(db.DB, &dest)
if err != nil {
return nil, err
}
return &dest, nil So, just to re-iterate, when I don't define any scan method on Facilities array I get something, so the QRM selector works. Once I add the scan method I get null. |
Beta Was this translation helpful? Give feedback.
Since you added scan method
FacilitiesArray
is not complex object any more, but a field inListing
struct. So,facilities
column has no destination. To fix it:or