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 ProjectMake 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:
Postgres#
Setting UpOnce you've installed
platter
, then you cancreate
orbranch
(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
git
configuration, falling back tomain
if nogit
configuration exists on your machine. To check the name of your new instance's trunk branch,list
your instances:This should give you a list that looks something like this:
psql
#
Using If you have
psql
installed, you can use theurl
command to connect directly to the trunk branch of your database instance:Once you've connected with
psql
, you can interact with yourmain
branch's database directly. Try running the following commands to create anitems
table:Both commands should run succesffully, and subsequent queries to
items
should 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 ProjectMake 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:
Postgres#
Setting UpOnce you've installed
platter
, then you cancreate
orbranch
(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
platter
directory:You'll also notice a new
platter
configuration section that has been automatically added to yourpackage.json
that looks like this:You can learn more about these configuration options in the Configuration section of the documentation.
#
Using the Node.js ClientAt 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
node
REPL (with thenode
command) 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 StepsCongratulations! 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.