Setup guide for configuring Turso using environment variables in an application deployed to Vercel.
In this setup guide, we are deploying a web application made in Nuxt that's using Turso as its database.
The project being deployed is available on this GitHub repo.
Run the following CLI command:
turso db create topwebframeworks
Run the following CLI command
turso db shell topwebframeworks
Copy and paste the following SQL statements to the shell to create tables, indexes, and seed the database with sample data.
-- create frameworks table
create table frameworks (
id integer primary key,
name varchar (50) not null,
language varchar (50) not null,
url text not null,
stars integer not null
);
-- "name" column unique index
create unique index idx_frameworks_name on frameworks (name);
-- "url" column unique index
create unique index idx_frameworks_url on frameworks (url);
-- seed some data
insert into frameworks(name, language, url, stars) values("Vue.js" , "JavaScript", "<https://github.com/vuejs/vue>", 203000);
insert into frameworks(name, language, url, stars) values("React", "JavaScript", "<https://github.com/facebook/react>", 206000);
insert into frameworks(name, language, url, stars) values("Angular", "TypeScript", "<https://github.com/angular/angular>", 87400);
insert into frameworks(name, language, url, stars) values("ASP.NET Core", "C#", "<https://github.com/dotnet/aspnetcore>", 31400);
insert into frameworks(name, language, url, stars) values("Express", "JavaScript", "<https://github.com/expressjs/express>", 60500);
insert into frameworks(name, language, url, stars) values("Django", "Python", "<https://github.com/django/django>", 69800);
insert into frameworks(name, language, url, stars) values("Ruby on Rails", "Ruby", "<https://github.com/rails/rails>", 52600);
insert into frameworks(name, language, url, stars) values("Spring", "Java", "<https://github.com/spring-projects/spring-framework>", 51400);
insert into frameworks(name, language, url, stars) values("Laravel", "PHP", "<https://github.com/laravel/laravel>", 73100);
insert into frameworks(name, language, url, stars) values("Flask", "Python", "<https://github.com/pallets/flask>", 62500);
insert into frameworks(name, language, url, stars) values("Ruby", "Ruby", "<https://github.com/ruby/ruby>", 41000);
insert into frameworks(name, language, url, stars) values("Symfony", "PHP", "<https://github.com/symfony/symfony>", 28200);
insert into frameworks(name, language, url, stars) values("CodeIgniter", "PHP", "<https://github.com/bcit-ci/CodeIgniter>", 18200);
insert into frameworks(name, language, url, stars) values("CakePHP", "PHP", "<https://github.com/cakephp/cakephp>", 8600);
insert into frameworks(name, language, url, stars) values("Qwik", "TypeScript", "<https://github.com/BuilderIO/qwik>", 16400);
Type the following at the shell prompt to terminate the shell:
.quit
Vercel will create a copy of the GitHub repository containing the project's source to your GitHub account to facilitate continuous integration.
After filing up the project's name and selecting the Git scope, click create to proceed.
The app (Top Web Frameworks) requires two environment variables to facilitate the connection to the database created earlier: NUXT_TURSO_DB_URL
and NUXT_TURSO_DB_AUTH_TOKEN
.
These values are required by the libSQL TypeScript client SDK to initialize the client and connect to the Turso database.
Vercel prompts you for these variables after you complete the previous step.
NUXT_TURSO_DB_URL
Run the following CLI command:
turso db show topwebframeworks --url
It outputs the URL for the database. Copy that string into the NUXT_TURSO_DB_URL
variable.
NUXT_TURSO_DB_AUTH_TOKEN
Run the following CLI command:
turso db tokens create topwebframeworks
It outputs a non-expiring authentication token that allows the libSQL client library used by the app to connect to the database.
Copy the resulting string into the NUXT_TURSO_DB_AUTH_TOKEN
variable.
Click the “Deploy” button to finalise the project's deployment.
When the project completes deploying, you'll be redirected to the project deployment's congratulatory page seen below.
In step 1, you created and seeded the database with some data. You can view the deployed app by clicking the project's screenshot at the end of step 2 to view the seeded data and verify that the app is correctly connected to Turso.
Here onwards, Vercel will automate continuous deployments whenever you push to the created git repository's production branch unless this setting is manually disabled.
To manually set up your project for deployment on Vercel, without the help of the “Vercel deploy button” in step 2, you can instead use the Vercel dashboard to manually pick your GitHub repo and configure its environment variables.
The following instructions will walk you through this process using the same source repository.
Visit the project on GitHub and fork the repository to your account.
Open your Vercel dashboard, select “Add New”, and pick “Project”.
If you've not authorised Vercel on your GitHub account you'll be requested to provide such access.
Likewise, at the repository level.
Next, pick the forked GitHub repository and import it.
Set the site settings for your project on Vercel, including the project's name, build, and output configurations. (For most frameworks, as is the case here, Vercel auto-detects and populates the default configuration for the project.)
The app (Top Web Frameworks) requires two environment variables to facilitate the connection to the database created earlier: NUXT_TURSO_DB_URL
and NUXT_TURSO_DB_AUTH_TOKEN
.
Expand the “Environment Variables” section on the site settings page.
These values are required by the libSQL TypeScript client SDK to initialize the client and connect to the Turso database.
NUXT_TURSO_DB_URL
On the available environment section fields, add NUXT_TURSO_DB_URL
as a new environment key.
Run the following CLI command:
turso db show topwebframeworks --url
It outputs the URL for the database. Copy that string into the NUXT_TURSO_DB_URL
variable, and click the “Add” button.
NUXT_TURSO_DB_AUTH_TOKEN
Add NUXT_TURSO_DB_AUTH_TOKEN
as a new environment key.
Run the following CLI command:
turso db tokens create topwebframeworks -e none
It outputs a non-expiring authentication token that allows the libSQL client library used by the app to connect to the database. The -e
flag in the command is the short for --expiration
.
Copy the resulting string into the NUXT_TURSO_DB_AUTH_TOKEN
variable, and click the “Add” button.
After the deployment is completed, you'll be directed to a congratulatory page like the one below.
Click the site preview screenshot on the previous step to see the deployed site.