Comments (9)
For note, reading #48, it would appear that Moebius uses atoms by default - is this not the case for custom functions returning JSONB objects?
from moebius.
If you use the document abstraction then we turn the keys into atoms. Otherwise, the column is translated at JSON - and a correct translation of JSON is to have keys as strings.
from moebius.
I'm constructing the JSON as a view in the DB (using jsonb_build_object(...)
) rather than using JSONB columns. Is there an easy way to mimic the behavior of the document abstraction and override the default for JSON? At the moment I am post-processing the returned JSON to convert the keys to atoms, but given that this already exists in Moebius, I was wondering if I could do it at this level.
Or would this require a patch?
from moebius.
Yeah - try piping on Moebius.Transformer.from_json
- that should turn the string keys to atoms...
from moebius.
That looks promising!
However, I'm having difficulty understanding how the API works at this point. So I'm trying to change this:
function(:my_func, id) |> My.Db.run
to this:
function(:my_func, id) |> My.Db.execute |> Moebius.Transformer.from_json
because all of the My.Db.run
function heads that match on %Moebius.QueryCommand{}
appear to have hard coded a follow on pipe to Moebius.Transformer.to_list
.
However My.Db.execute/1
is not exposed.
Should I be using the API in a different way (e.g. not using the module alias)?
from moebius.
Oh - right. That won't work as it expects certain fields to be there. Here's another thought: maybe return the value as a string. You can set the field to be ::varchar(5000) or something. Then, in your code, you can use Poision.decode!(val, :atomize_keys!)
.
from moebius.
Yes, that would work as well. Potentially I could reconsider constructing the JSON in Postgres and instead deliver regular DB rows, have Moebius atomize them by default and then construct the JSON blob in the app.
from moebius.
For anybody following this thread, by casting the JSONB to TEXT, the following worked for me with Poison 2.0.1:
Poison.decode!(val, keys: :atoms)
from moebius.
I think we should mark this issue as closed now - many thanks for your help @robconery :-)
from moebius.
Related Issues (20)
- Update library HOT 5
- Make PostgresTypes configurable HOT 1
- Any plans of going to postgres 0.16.x HOT 6
- How do I ACTUALLY use it HOT 7
- Inflex not loading
- Proposal: ignore_conflict HOT 3
- What does this error mean? HOT 12
- Hang problem. HOT 1
- run_with_psql doesn't use the configured connection info HOT 3
- Updating array column: HOT 8
- readme talks about existence operator, but doesn't show it? HOT 4
- Async test HOT 2
- `pool_mod` option does not work HOT 11
- Allow caching query information
- Is is possible to run moebius and ecto together? HOT 1
- Return values for IO actions HOT 2
- Dependency conflict with phoenix in umbrella app HOT 1
- Date Test Fails
- Moebius.DocumentQuery return only one entry? HOT 3
- limit not being honored alongside search HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moebius.