-
Notifications
You must be signed in to change notification settings - Fork 962
schema/field: add the option to use dialect specific types #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
My comment in #343: Hey @cliedeman, sorry for the delay, I'm focused on the mutation and hooks layers and didn't have time to finalize the custom fields interface. I thought about creating an interface that will provides the following values: database-type, Go-type and predicates (maybe create a separate package named When creating a new IMO, we should migrate all existing fields to it (without breaking existing programs), and support the popular database types per dialect (like pg.hstore, mysql.datetime, etc). One of the advantages of migrating existing types, is to allow users define database primitive types as Go typedefs. For example, use this Go type: |
@a8m that makes sense and feel like a natural evolution of the api. I created an updated Draft PR using the public Append method and injecting a custom predicate which works nicely - #369 but this should wait until after the custom field interface is done So from the comment above If I understand correctly all fields should be generalised to be similar to the UUID example (ignoring UnaryOp, BinaryOp and custom predicates for the moment)
I know this feature is not on the roadmap. Does that mean it will only be implemented post v1 or is it up for grabs? |
Hey, I got back to this now, and I hope to push this ASAP.
Of course, nothing is set in stone yet and you're welcome to share your thoughts. |
Would this be able to handle a situation like what I'm dealing with right now? I've been attempting to use ent for PostGIS queries. It partially works, but the problem that I've run into is that even if I use a custom predicate in a Speaking of which, would it be possible to get a method of client that returns the underlying driver so that in cases like these it's easier to get around limitations of ent and do raw SQL when I really need to? I can get around it by creating the driver manually and using Edit: Just wanted to clarify that there doesn't seem to be a way to do it with predicates and Edit 2: Was able to get it working using areaTable := sql.Table(areaTable)
locs, err := db.Location.Query().
Where(func(s *sql.Selector) {
s.Join(areaTable).On(areaTable.C(area.FieldID), areaID)
}).
Where(func(s *sql.Selector) {
s.P().Join(sql.Raw(fmt.Sprintf(
`ST_Contains(geometry(%v), geometry(%v))`,
areaTable.C(area.FieldArea),
s.Table().C(location.FieldLocation),
))).Pad().Join(sql.Raw(`AND`))
}).
All(ctx) Seems a bit finicky, but it worked, at least. |
Hey @DeedleFake,
You can use the template option for this case. It's also mentioned in #85.
I'll give it a look later today and I'll try to find a nicer solution for it. |
I think that this could be solved quite a bit simpler if two things were changed:
If both of these were changed, it should be possible to do areaTable := sql.Table(areaTable)
locs, err := db.Location.Query().
Where(func(s *sql.Selector) {
s.Join(areaTable).On(sql.P().Custom(sql.Raw(fmt.Sprintf(
"ST_Contains(geometry(%v), geometry(%v))",
areaTable.C(area.FieldArea),
s.Table().C(location.FieldLocation),
))))
}).
All(ctx) |
The text was updated successfully, but these errors were encountered: