If you hesitate to migrate to Prisma2
Prisma is an open-source database toolkit. It replaces traditional ORMs and makes database access easy with an auto-generated query builder for TypeScript & Node.js.
On June 18, 2019 was released Prisma v2 which has many fundamental improvements such as enabling usage of Prisma as a library (without the need for the Prisma server), more flexible database migrations, possibility to use transactions and a lot of others.
Here is an a few major reason to migrate from Prisma v1 to v2:
* On Prisma v2 the Prisma server is optional:
This is due to a fundamental architecture change: the query and migration engines that previously ran inside the Prisma server can now run as plain binaries alongside your application on the same host.
Prisma v1 is implemented in Scala which means it needs to run in the JVM, and Prisma v2 was rewritten in Rust.
Benefits of Rust include a significantly lower memory footprint, better performance and no more need to deploy, monitor and maintain an extra server to run Prisma v2.
Rust has shown to be the perfect language for Prisma, allowing us to write safe and extremely performant code.
* Performance improve made database seeding faster on 95% (based on my own experience😊) :
Test was made on the same machine and with the same dataset and db structure in postgresql 10.5:
— Prisma v1 populates database in 4m 0s
— Prisma v2 populates database in 2m 15s
* More flexible database migrations:
Prisma v2 Migrate is a powerful database schema migration tool. It uses a declarative data modeling syntax to describe database schema. It also stores the entire migration history and easily lets revert and replay migrations and also allows to run before-and-after hooks to execute scripts while migrating so now possible to populate the database with required values during a migration.
* One more powerful improvement — In Prisma v2 was added transactions:
Prisma Client provides a data access API to read and write data from a database. For relational databases, Prisma Client’s API abstracts over SQL where transactions are a common feature. Unfortunately Prisma Client doesn’t allow for the same flexibility a SQL-level transaction provides, but it covers most majority cases as creating, updating or deleting data across multiple tables in a single Prisma Client query.
So, if you gonna to migrate from Prisma1 to Prisma2 — just do it.
Possible that you’ll have some pain after migration but the game is worth the candle. As result — you will get fast and powerful ORM for your database.
And if for some reason you still don’t use ORM at all — you have a great chance to start use Prisma2. As benefit you will get:
* Easy way for connecting to the DB;
* You need only to create a proper schema and Prisma will automatically create all tables and relations;
* No need to thing about difficult SQL queries, because Prisma can get the data based on relations specified in the schema;
* And if you need input/output types — PrismaClient will provide them for you;