Coder Social home page Coder Social logo

Comments (7)

kiwicopple avatar kiwicopple commented on August 26, 2024 3

yeah it's already used in prod so it will definitely break. The camel -> snake conversions will be safer because we aren't using query params, but we are using response keys/objects.

at this point it's probably less effort to be 100% camel

Probably not with the changes to production but regardless, we should prioritize the effort going forward over the effort now. Writing less code is always my number 1 concern, more than blindly following a convention.

My gut is snake_case is going to save us a mountain of effort going forward, but I'll leave the final decision to you

Side note, I used to always write snake-camel converters between my PG database and my API. When I started using postgREST I stopped doing that and it actually made things conceptually simpler - camel = code, snake = database. Also reduced my LOC. This convention isn't unheard of either, but not really necessary here.

from postgres-meta.

soedirgo avatar soedirgo commented on August 26, 2024 2

@wiesson I think this issue supabase/postgrest-js#204 is more relevant.

from postgres-meta.

kiwicopple avatar kiwicopple commented on August 26, 2024 1

Good call Bobbie

Postgres (snake_case)
OpenAPI spec (camelCase)
It'd be more idiomatic to use camelCase.

Despite being REST idiomatic, I think there are some important benefits of snake_case:

  • it's idiomatic to postgres (snake_case doesn't break Open API as far as I can tell, but camelCase does break Postgres)
  • less casting - no need to cast each time between snake and camel - better code simplicity

It's easy to say to developers "our API uses snake_case", but harder to code snake<->camel just because of convention.

I think at the moment we are mixing the two (includeSystemSchemas), and this is bad. My preference would be to make everything snake_case (include_system_schemas). Let me know your thoughts

from postgres-meta.

wiesson avatar wiesson commented on August 26, 2024 1

@wiesson I think this issue supabase/postgrest-js#204 is more relevant.

Oh yes, this is what I was looking for! I just hoped, postgREST could already do this :)

from postgres-meta.

soedirgo avatar soedirgo commented on August 26, 2024

In general, I prefer consistent and predictable design at the cost of implementation complexity. In this case:

  • The only place we need to change snake -> camel is, I think, the SQL templates, which are well-isolated. While we can change the API to be 100% snake_case, we're still going to live with snake & camel within pg-api.

  • For inbound property names (POST, PATCH), these won't directly interact with Postgres (there are also some fields I added for convenience, like dropDefault), so it shouldn't break Postgres.

  • For outbound property names (GET, res.data), it's a bit of effort to tweak the templates, but the API becomes cleaner. On that note, I haven't seen other DB interfaces/ORMs adopting snake_case.

  • Given that we want to provide an easy-to-use interface for less-than-powerusers, I think we should prioritize having a clean API. As per the 2 points above, all interactions with the DB are intercepted, so breaking Postgres due to naming shouldn't be a concern.

  • The last one, and this one is my bad, I blindly used camelCase for most (all?) of POST and PATCH, at this point it's probably less effort to be 100% camel than 100% snake.

P.S. My biggest concern is breaking prod. How much interaction is there with pg-api at the moment? Maybe we can make it stable enough before we ship?

from postgres-meta.

github-actions avatar github-actions commented on August 26, 2024

🎉 This issue has been resolved in version 0.10.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

from postgres-meta.

wiesson avatar wiesson commented on August 26, 2024

Side note, I used to always write snake-camel converters between my PG database and my API. When I started using postgREST I stopped doing that and it actually made things conceptually simpler - camel = code, snake = database. Also reduced my LOC. This convention isn't unheard of either, but not really necessary here.

@kiwicopple - is postgREST able to automatically convert from snake to camel and vice versa for me? I have the issue right now, we are transitioning from the firestore and everything is based on camelCase but I understand that it is a way easier within postgres to have snake case (I don't want to handle quotes etc).

// edit: Maybe this is the wrong place to ask that topic

from postgres-meta.

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.