-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Epic: ORM for database modeling and migrations #32
Comments
Hey all as we were exploring the seeding issue that was coming up in the contributors guideline, some questions came up:
|
I don't know which one is the source of truth. Don't think either are actually. Production would be closest I think. I don't think it's wise to switch yet. I think we need to build out the |
Forgot to post my updates here. I looked into Prisma a bit last week, though ended up moving on to work on OpenSourceFellows/amplify-back-end#36 instead for most of the time. I was super impressed with Once I get a little farther and get a better feel for how day-to-day operations would work in a post-Prisma world, I would also love to get some feedback on how folks feel about using the Prisma ORM approach vs. our current Knex query builder approach. |
Hey @JamesMGreene was the following idea tied to this? This would also allow us to validate the addresses more directly for greater data integrity, e.g. require values for at least one line, a city, a state, and a zip code at the database level. Not an urgent requirement but something that would probably be wise in the long term." |
@alwell-kevin for reference |
Not a hard tie-in but would work well together. 🤷🏻♂️ |
@JamesMGreene : I was curious what you've found regarding attaching logic to the models generated around prisma. looking at https://www.prisma.io/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases/install-prisma-client-typescript-postgres, it seems like the models generated by prisma are generated and updated as prisma commands are called, however I don't get a sense that methods can be attached to these models for business logic that'd you want to use all over the place. I think https://www.prisma.io/docs/concepts/components/prisma-client/custom-models talks about this but not 💯 sure |
@andyfeller Ah, that's a very interesting observation! 😮 Yes, you appear to correct! It looks like Prisma is only providing static methods for working with the tables/collections, and the objects they return, while capable of including resolving relationships, are just plain objects rather than class instances (a.k.a. models) that could be extended with custom behaviors. 😳 Open feature request: prisma/prisma#5998 Not as ideal as I was imagining, though I'm also not sure that is a deal breaker, per se, given the potential benefits. 🤔 P.S. I see some npm packages for creating Sequelize models from Prisma schemas, which definitely makes me more anxious. 😅 |
Discussed using Objection ORM today in our backend pairing session, which is an ORM based on Knex (which we're currently using), so it might be a nice fit. cc @waldnzwrld |
I've been using https://bookshelfjs.org/ in another personal project and I like it. It's maintained and widely used. Can I suggest it? |
Thanks @waldnzwrld! @JamesMGreene, the documentation looks great - do we want to focus on this for wednesday? |
I've used Bookshelf in the past and been fine with it. 👌🏻
I would agree that Bookshelf is relatively widely used, though not as widely used as Objection. 👌🏻 However, on the point of Bookshelf being maintained, I definite disagree. 😕 Its latest published version on npm is almost 2 years old and its number of open issues are fairly high:
As far as usage ergonomics go, I found Bookshelf's APIs (e.g. fetching records) to feel a bit unnatural. Using the Objection's APIs feel a bit better than Bookshelf's out-of-the-box, IMHO, and look like they are probably more capable of advanced usage in the long haul ( Given our project's current needs, I think either one could work fine. 👍🏻 If I had to pick one, I'd probably start with Objection. 🤷🏻♂️ |
My experiences with Sequelize have all become cautionary tales, so I guided us away from using it at this point and instead favored just using Knex, which is a more basic "SQL query builder".
However, for maintainability's sake, it is probably worthwhile to consider an ORM for the long-term, especially with some contributors not being too familiar with databases.
I would suggest we investigate Prisma as a potential ORM in particular.🔺I think it has a lot of nice features that make it a more solid choice than Sequelize. It should also be able to completely replace our Knex usage, as far as I can tell at this point.Tasks
npm install --save objection
require('objection').Model.knex(knexClient)
campaigns
table #141letter_versions
table #142transactions
table #143 (:warning: currently unused)constituents
table (:warning: currently unused)sent_letters
table (:warning: currently unused)variants
table (:warning: currently unused)Status
objection-orm
that installs theobjection
module and sets up the project for creating models.server/db/models/
directory (only exists in theobjection-orm
branch)letter-version.js
LetterVersion
Example, at filename
server/db/models/letter-version.js
:The text was updated successfully, but these errors were encountered: