Comments (7)
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.
@wiesson I think this issue supabase/postgrest-js#204 is more relevant.
from postgres-meta.
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 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.
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, likedropDefault
), 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
andPATCH
, 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.
🎉 This issue has been resolved in version 0.10.0 🎉
The release is available on GitHub release
Your semantic-release bot 📦🚀
from postgres-meta.
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)
- typescript generated type of pgvector/vector is string HOT 5
- Generate types for foreign tables HOT 5
- Generating types for a postgresql array results in Typescript unknown property HOT 4
- Feat: Indexes HOT 1
- supabase gen types generates duplicate identifiers HOT 3
- gentype producing wrong type for inner join HOT 1
- Typegen is not respecting unique table constraint HOT 3
- Permission denied error when generating types HOT 3
- SSL connection error with "PG_META_DB_SSL_ROOT_CERT" and "rejectUnauthorized" misconfiguration HOT 3
- Stopping the container is slow, resorting to SIGKILL
- How to get online postgre-meta version? HOT 1
- Generate types: "Json" type is incompatible with other types HOT 6
- Hardcoded metadata resulting in broken TypeScript type generation from the Supabase CLI HOT 1
- sslmode=require ignored on postgresql URL with gen types --db-url HOT 3
- Gen type throws an exception when table has no columns HOT 2
- Type generation script does not pick up correct type when a SQL function returns data from other table HOT 1
- Composite types can be null
- Generated DB types do not include function property in Table HOT 1
- Generating types in python format HOT 3
- [typescript gen] Add `CompositeTypes` helper HOT 2
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 postgres-meta.