Skip to main content

Creating a Neon Database

Sign Up

Navigate to Neon's sign up page here and sign up with your email, Github, Google, or partner account.

Neon has several places in which to create a new database, the easiest is from the Neon console, click on the database dropdown menu and select 'new database', add a new database name keep the default branch and owner (which will be your Neon user name). Now that you have the database made we will need to add tables using SQL, click on the SQL editor on the left side of the screen.

For this example we will use tables that can be used with the todo tutorial after each new SQL command you will need to click on the 'Run' button on the bottom of the SQL edititor.

Create Tables

The first table will be a list table that will contain the names and id of lists that items will belong to and can be sorted by listid:

CREATE TABLE List (
ListID SERIAL NOT NULL PRIMARY KEY,
ListName varchar(255) NOT NULL
);

Second table will be a item table that will relate to the list table:

CREATE TABLE Item (
ItemID SERIAL NOT NULL PRIMARY KEY,
ItemName varchar(255) NOT NULL,
ListID INT,
CONSTRAINT FK_ListID
FOREIGN KEY (ListID)
REFERENCES List(ListID)
ON DELETE CASCACADE
);

Insert Values into Tables

Next, we will insert values into the list and item table:

INSERT INTO List (listname)
VALUES
('Tutorial');
INSERT INTO item (itemname, listid)
VALUES
('Create Tutorial', 1);

Devii Connection Setup

Create a Devii connection to your database. Refer to database connection instructions. Extract necessary information from your Neon Tech project dashboard (username, password, database name, hostname). The connection string format is:

psql 'postgresql://username:password@hostname/database_name?sslmode=require'

Optional: Devii Connection Verification

To check your connection, execute the following query in the Devii portal using the GraphiQL interface:

{
list {
listid
listname
item_collection {
itemid
itemname
}
}
}

You should receive a reply of:

{
"data": {
"list": [
{
"item_collection": [
{
"itemid": "1",
"itemname": " Create Tutorial"
},
],
"listid": "1",
"listname": " Tutorial"
}
]
}
}

Learn More

Interested in mastering SQL? We recommend the comprehensive SQL training available at W3Schools.