Giter Club home page Giter Club logo

Comments (9)

0x6e6562 avatar 0x6e6562 commented on August 12, 2024

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.

robconery avatar robconery commented on August 12, 2024

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.

0x6e6562 avatar 0x6e6562 commented on August 12, 2024

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.

robconery avatar robconery commented on August 12, 2024

Yeah - try piping on Moebius.Transformer.from_json - that should turn the string keys to atoms...

from moebius.

0x6e6562 avatar 0x6e6562 commented on August 12, 2024

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.

robconery avatar robconery commented on August 12, 2024

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.

0x6e6562 avatar 0x6e6562 commented on August 12, 2024

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.

0x6e6562 avatar 0x6e6562 commented on August 12, 2024

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.

0x6e6562 avatar 0x6e6562 commented on August 12, 2024

I think we should mark this issue as closed now - many thanks for your help @robconery :-)

from moebius.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.