Open drepkovsky opened 1 year ago
@drepkovsky this would be super useful, especially for PostGIS or any other data types you might want to cast within the database query. I've been experimenting with temporary workarounds, there's two ways to potentially do this now without this 'selector'.
public".ST_AsGeoJSON("${dbName}") as "${dbName}
as a columnName. (This hardcodes the public schema in here though so this wouldn't work if you need this work on any other schemas too, but could be an config option in the column)
If we add support for custom selectors, as described here, the performance and implementation of the custom column would be a lot simpeler, since you could use the ST_
functions to cast as text, or GeoJSON, like in the examples above.
Edit: I've later edited this comment to include another example for point Nr 1, and further extend / improve the text
Related issue by one of the maintainers: https://github.com/drizzle-team/drizzle-orm/issues/554
need this asap!
π $30 bounty created by @john-griffin π To claim this bounty, submit your pull request on Algora π Before proceeding, please make sure you can receive payouts in your country π΅ Payment arrives in your account 2-5 days after the bounty is rewarded π― You keep 100% of the bounty award π Thank you for contributing to drizzle-team/drizzle-orm!
/attempt #1423
Describe what you want
When creating a custom type that doesn't have a straightforward select like a postgis geometry, for example.
We need to create a select function wrapper to properly select the field with this custom type.
That means we always need to specify this custom select when working with this table, also we are not able to use the relational query syntax because the there is no way to provide a custom sql fragment in the columns object (only true/false boolean specifying the field inclusion)
Proposal:
Add a selectFromDb option to customType factory function like so:
Now we when the field is being selected from db the
selectFromDb
function will be automatically called if specified for given field.