A great TypeScript database combo: TypeORM and CockroachDB

A great TypeScript database combo: TypeORM and CockroachDB

So you’re building a TypeScript application. You’ll need a database to power it, and an ORM to link your application to that database. We’d like to suggest a powerful combination that’s surprisingly easy to set up: TypeORM (a popular TypeScript ORM) and CockroachDB.

This combination is so powerful, in fact, that we’ve created a narrative-driven tutorial about a powerful wizard that will help you get set up with CockroachDB and link your new distributed SQL database to your application.

(You can also learn how to do this in our docs, but you’ll have more fun playing through the narrative tutorial!)

Why CockroachDB and TypeORM?

TypeORM is a TypeScript ORM (object-relational mapper) library that makes it easy to link your TypeScript application up to a relational database database.

TypeORM supports MySQL, SQlite, Postgres, MS SQL Server, and a host of other traditional options. It also works seamlessly with CockroachDB, a cloud-native distributed database that combines the consistency advantages of a traditional RDBMS with the automated scaling, high availability, and survivability of a cloud-based distributed database.

As you’ll find if you work through the tutorial, connecting your TypeScript application to CockroachDB is fast and straightforward.

And since CockroachDB is available in a serverless cloud distribution for free, it raises the question: why not build your application with CockroachDB from the get-go? You can use the same familiar SQL you’d use with Postgres, but with a bunch of extra advantages, including:

  • Online schema changes – you can iterate fast and make changes without downtime.
  • Automated data replication – your data is distributed without you having to even think about nodes or shards.
  • Automated elastic scaling – skip the operational complexity and guesswork that often come with scaling by choosing a database that scales up and down as you need it, automatically.

CockroachDB is also highly performant, so whether you’re working on a small side project or a web application that’ll be used by millions of people, it won’t slow you down.

How to connect your TypeScript application to CockroachDB

Our tutorial will walk you through this process in greater detail (as will our docs), but if you don’t need that level of detail to get started, here’s a quick overview of what it takes to link your TypeScript app to a cloud-based CockroachDB database:

  1. Sign up for a CockroachDB account and create a free cluster.
  2. Download the CockroachDB client and connect to your new cluster.
  3. Create your database using the same SQL commands you already know.
  4. Edit your application’s ormconfig.ts file with the relevant information to point it to your new CockroachDB database.
  5. Install the Node.js pg driver.
  6. Run your application and confirm that everything is working as expected.

Again, the details are available in the narrative tutorial or our documentation if you need them. You can also get help at any time in our Slack community.

About the author

Charlie Custer github link linkedin link

Charlie is a former teacher, tech journalist, and filmmaker who’s now combined those three professions into writing and making videos about databases and application development (and occasionally messing with NLP and Python to create weird things in his spare time).

Keep Reading

Hands-On SQL Tutorials for Beginners: App Development Fundamentals

Structured Query Language (SQL) was developed to work with relational databases that organize and store information in …

Read more
How to get started with CockroachDB Dedicated

Distributed, cloud-native databases are the future, but setting one up is complicated, right?

It doesn’t have to be! In …

Read more
How to do a Postgres database migration: Tips from LaunchDarkly

What’s the best way to do a database migration?

It’s a challenging question. No single approach is going to be the best …

Read more