Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

upleveled/next-js-with-slonik-sept-2019

Repository files navigation

Next.js Slonik API Routes example

Setup

You'll need PostgreSQL for this.

Copy the .env.example file to a new file called .env and fill in the values described in the following table.

This user and database will be created by the migrations, and will be used by the Next.js application. The user will be given limited access only to the database specified:

Variable Description
PGHOST Name of the host to connect to - often localhost
PGUSER Database user
PGPASSWORD Password for the database user
PGDATABASE Database that the user has access to

In order to create this user and database, we will also need the ADMIN variables, which are PostgreSQL admin connection details.

Run Migrations to Set up Tables

The migrations that have been written using @slonik/migrator can be run using the following command:

node migrate up

To roll back the changes in the migrations, run the following command:

node migrate down

Create New Migrations

The @slonik/migrator tool can be used to create new migrations as well.

For example, to create a new migration called todo (for example, to create a database table called todo):

node migrate create todo

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •