packages/record/README.md
RedwoodRecord is an ORM (Object-Relational Mapping) built on top of Prisma. It may be extended in the future to wrap other database access packages.
RedwoodRecord is heavily inspired by ActiveRecord which ships with Ruby on Rails. It presents a natural interface to the underlying data in your database, without worry about the particulars of SQL syntax.
Usage documentation is available at https://redwoodjs.com/docs/redwoodrecord
RedwoodRecord is composed of 5 classes total:
There is also an errors.js file which contains all error messages that RedwoodRecord could throw.
RedwoodRecord depends on reading the Prisma schema file to determine relations to other tables. In order to avoid the async wait when parsing the schema with Prisma's built-in function, we have a task which parses the schema file and then saves out a JSON version to the cache .redwood directory. This task also creates an index.js file in your api/src/models directory that imports the models themselves and also adds some configuration to support relations without a circular dependency. The models are then re-exported.
This task is run with:
yarn rw record init
This task needs to be run whenever you create a new model, or change your database schema in a way that would add/remove a relation to another model.
We plan to make the task run automatically, watching for changes to your schema.prisma or models directory. But for now you'll need to run it manually!