Tabnine Live: Implement and validate Atlassian Jira issues with one click
October 10
8 am PT
Home / Blog /
Tabnine + Prisma: Making data easier to work with
//

Tabnine + Prisma: Making data easier to work with

//
Aydrian Howard /
2 minutes /
September 11, 2024

Prisma ORM is a Node.js and TypeScript ORM that’s used by 320K developers every month. It provides an intuitive schema that allows you to declare your database tables in a human-readable way. Prisma ORM then uses this schema to manage migrations and generate a type-safe client. 

The ORM was designed with both SQL veterans and developers brand new to databases in mind, providing autocompletion and an IDE extension to lessen the need to dig through documentation to build queries tailored to your schema. This design also lends itself to working well with Tabnine’s AI code assistant. 

Let’s take a look at how Tabnine can help accelerate working with a database when using Prisma ORM.

Using schema as context

The biggest challenge to using generative AI when working with databases is knowing the structure of the database. Without supplying a database schema as context, the models can only guess at the available tables and fields when generating a query. 

Prisma utilizes a schema file to declare the structure of the database. Tables can be created using their Schema API or be introspected from an existing database. Because this schema.prisma file exists in the project workspace, it can be indexed by Tabnine. Once indexed, Tabnine will be context-aware of the database and respond with more personalized results. 

Now let’s dive into how we can use Tabnine with Prisma.

Working with data models

Tables and relationships are created by scripting out new data models in the schema.prisma file. Prisma provides a robust DSL that allows you to define column types, relationships, indexes, and more. When working in the schema.prisma file, Tabnine will provide helpful auto completion while you type or based on a comment.

You can have Tabnine provide more information about a model by highlighting it and asking for an explanation in the chat.

Tabnine will generate new models and suggest alterations based on natural language prompts in the chat.

Once a schema has been defined, Tabnine can generate a seed function to populate the database with sample data.

The combination of context provided by the prisma.schema file and the knowledge within the LLM makes for a powerful tool to help you create the right database structure for your application.

Building queries

Once you have your database schema defined and the client generated using `npx prisma generate`, you’re ready to start querying your data. Tabnine will suggest autocompletions as you type or based on a comment. Since the client uses TypeScript, Intellisense will also be a big help as you build your queries.

Using the context provided by the schema.prisma file, the AI chat provides the best assistance.

Demystify complex queries by highlighting them and asking for an explanation.

Generate or refactor queries using natural language prompts.

You’re not limited by the Prisma API. You can ask the chat to generate full SQL statements.

These are just a few examples of what Tabnine is capable of when it has proper context for the database. Prisma’s schema file provides a clear picture of the database structure helping to produce more relevant results that are personalized to the project.

Not a Prisma user or fan of ORMs in general? Let us know how you would provide database context. Not yet a Tabnine user? Get your 90-day free trial of Tabnine Pro today.