Quick Start
This tutorial will show you how to create and query your first Platter Postgres database with the platter CLI.
Choose one of the connection methods below to get started.
- Connection String
- Node
Prerequisites#
To interact with your database through a connection string, an installation of psql is recommended.
Setting Up the Project#
Make sure that you've signed up for a Platter account. To create databases and branches, you'll also need to add a payment method. See more about our pricing here.
Log in with your Platter email and password with:
Setting Up Postgres#
Once you've installed
platter, then you cancreateorbranch(see Concepts to learn more about feature branching) any Platter resource. Run the following command to create your first instance:Your new instance was created with a "trunk" branch. Future branches will be based off of this branch by default. This branch was given a name based on your local
gitconfiguration, falling back tomainif nogitconfiguration exists on your machine. To check the name of your new instance's trunk branch,listyour instances:This should give you a list that looks something like this:
Using psql#
If you have
psqlinstalled, you can use theurlcommand to connect directly to the trunk branch of your database instance:Once you've connected with
psql, you can interact with yourmainbranch's database directly. Try running the following commands to create anitemstable:Both commands should run succesffully, and subsequent queries to
itemsshould returnmy-new-item.
Prerequisites#
This tutorial assumes that you're working with a unix-style command line with an installation of git and Node.js is installed on your system and accessible in your $PATH. See nodejs.org for in-depth installation instructions.
Setting Up the Project#
Make sure that you've signed up for a Platter account. To create databases and branches, you'll also need to add a payment method. See more about our pricing here.
For the rest of this tutorial you'll need a project with a
package.json. To generate a brand-new directory and project, run:Install the Platter CLI as a
devDependency, like so:Log in with your Platter email and password with:
Setting Up Postgres#
Once you've installed
platter, then you cancreateorbranch(see Concepts to learn more about feature branching) any Platter resource. Run the following command to create your first instance and a Node.js client:After running the above command, you should have a Node.js client and TypeScript declaration file in a new
platterdirectory:You'll also notice a new
platterconfiguration section that has been automatically added to yourpackage.jsonthat looks like this:You can learn more about these configuration options in the Configuration section of the documentation.
Using the Node.js Client#
At this point, you have a running Postgres database that can be accessed from Node.js without a separate connection pool, proxy, or deploy step! Let's try making a query against that database from our website. Open up a
nodeREPL (with thenodecommand) and try the following:The client automatically aggregates results into an Array of row Objects with keys mapped to Postgres column names. In this case, you should see:
The
SELECT NOW()query in the previous step was run anonymously. All data in a database is protected by default, and that data and its permissions can only be modified with the credentials of the database owner. To populate this database with some data, grab an API key from https://dashboard.platter.dev/keys, open up a REPL withPLATTER_API_KEY=<your API key> node, then run the following:
Next Steps#
Congratulations! You now have a database that can be used anywhere, from the command-line to serverless functions. You also have a database that is public and easy-to-access for identified users, but still protected against malicious queries. And you've completely eliminated the need to manage your own servers, connection pools, cloud databases, or deployment processes along the way. Here's where to go from this point:
- To learn more about how to create and discard copies of your database as you work on features check out Branching
- To dive right into some practical examples, check out the Migrations and Netlify Functions guides.