{"action":"created","issue":{"url":"https://api.github.com/repos/Vincit/objection.js/issues/129","repository_url":"https://api.github.com/repos/Vincit/objection.js","labels_url":"https://api.github.com/repos/Vincit/objection.js/issues/129/labels{/name}","comments_url":"https://api.github.com/repos/Vincit/objection.js/issues/129/comments","events_url":"https://api.github.com/repos/Vincit/objection.js/issues/129/events","html_url":"https://github.com/Vincit/objection.js/issues/129","id":156245106,"number":129,"title":"Default transformation before query","user":{"login":"appedemic","id":3819227,"avatar_url":"https://avatars.githubusercontent.com/u/3819227?v=3","gravatar_id":"","url":"https://api.github.com/users/appedemic","html_url":"https://github.com/appedemic","followers_url":"https://api.github.com/users/appedemic/followers","following_url":"https://api.github.com/users/appedemic/following{/other_user}","gists_url":"https://api.github.com/users/appedemic/gists{/gist_id}","starred_url":"https://api.github.com/users/appedemic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/appedemic/subscriptions","organizations_url":"https://api.github.com/users/appedemic/orgs","repos_url":"https://api.github.com/users/appedemic/repos","events_url":"https://api.github.com/users/appedemic/events{/privacy}","received_events_url":"https://api.github.com/users/appedemic/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-05-23T10:08:37Z","updated_at":"2016-05-23T11:40:43Z","closed_at":null,"body":"Is it possible to define a default parse/format for a field at query level? I have two practical cases. One is a table with a binary field 'image' where I always want a base64 representation of the field. Now every time I query the model I need to do:\r\n\r\n```\r\nModel.query().select(Model.raw(\"encode(image, 'base64') AS image\")\r\n```\r\n\r\nAnother case is when using together with PostGIS and I want to store a position. At Model level I always want a {latitude, longitude} representation. Now every time I query the model I have to do:\r\n\r\n```\r\nModel.query().select(Model.raw(\"st_asgeojson(position) AS position\"))\r\n```\r\n\r\nIs there a way to make this field conversion default for a specific field? Similar to $parseJSON/$formatJSON but then before the query gets executed?"},"comment":{"url":"https://api.github.com/repos/Vincit/objection.js/issues/comments/220957272","html_url":"https://github.com/Vincit/objection.js/issues/129#issuecomment-220957272","issue_url":"https://api.github.com/repos/Vincit/objection.js/issues/129","id":220957272,"user":{"login":"elhigu","id":696345,"avatar_url":"https://avatars.githubusercontent.com/u/696345?v=3","gravatar_id":"","url":"https://api.github.com/users/elhigu","html_url":"https://github.com/elhigu","followers_url":"https://api.github.com/users/elhigu/followers","following_url":"https://api.github.com/users/elhigu/following{/other_user}","gists_url":"https://api.github.com/users/elhigu/gists{/gist_id}","starred_url":"https://api.github.com/users/elhigu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elhigu/subscriptions","organizations_url":"https://api.github.com/users/elhigu/orgs","repos_url":"https://api.github.com/users/elhigu/repos","events_url":"https://api.github.com/users/elhigu/events{/privacy}","received_events_url":"https://api.github.com/users/elhigu/received_events","type":"User","site_admin":false},"created_at":"2016-05-23T11:40:43Z","updated_at":"2016-05-23T11:40:43Z","body":"You could probably use postgresql views to implement automatic conversion in database side (http://www.postgresql.org/docs/current/static/sql-createview.html).\r\n\r\nOther way might be to use some `onBuild` hook to rewrite `.select()` part of builder in case if certain columns are queried... I don't know how that would be exactly possible implemented...\u001C"}}
{"actor":{"display_login":"elhigu"}}