Creating a Database
You can import an existing SQLite databases, or create new databases using the SQLite Cloud UI, API, or client libraries.
Uploading an existing SQLite Database
Via HTTP API
You can upload an existing SQLite database to your cluster using the SQLite Cloud UI or the Weblite API.
To upload a local SQLite database via weblite, make a POST request to the /v2/weblite/<database-name>.sqlite
endpoint.
curl -X 'POST' \
'https://<your-project-id>.sqlite.cloud:8090/v2/weblite/<database-name>.sqlite' \
-H 'accept: application/json' \
-H 'Authorization: Bearer sqlitecloud://<your-project-id>.sqlite.cloud:8860?apikey=<your-api-key>' \
-d ''
To upload a local SQLite database via the SQLite Cloud UI, navigate to the Database tab in the left-hand navigation. Click the “Upload Database” button and select your local SQLite database.
Via Dashboard UI
To import a database from the UI, navigate to the Databases tab and click the “Upload Database” button.
Select the database file you want to upload, and click “Upload Database”. The database will be available in your cluster within a few minutes.
Creating a new database
From the Dashboard
To create a new database from the SQLite Cloud UI, navigate to the Databases tab and click the “Create Database” button.
The default encoding is set to UTF-8, and the default page size is 4096KB.
From the API
To create a new database or upload an existing database via Weblite, our REST API, you can make a request with the following parameters:
curl -X 'POST' \
'https://<your-project-id>.sqlite.cloud:8090/v2/weblite/<database-name>.sqlite' \
-H 'accept: application/json' \
-H 'Authorization: Bearer sqlitecloud://<your-project-id>.sqlite.cloud:8860?apikey=<your-api-key>' \
-d ''
From client libraries
To create a new database from a client library, connect to your cluster using a connection string without a specified database.
Then, use the CREATE DATABASE command to create a new database.
To start using the database within the connection, you can use the USE DATABASE
command.
import { Database } from '@sqlitecloud/drivers';
// note that no database name is specified in the connection string path
const db = new Database('sqlitecloud://<your-project-id>.sqlite.cloud:<your-host-port>?apikey=<your-api-key>')
const createDatabase = async () => await db.sql`CREATE DATABASE <database-name>;`;
createDatabase().then((res) => console.log(res));
// "OK"
db.exec('USE DATABASE <database-name>;')
// now you can use the database
const fetchAlbums = async () => await db.exec`SELECT * FROM albums;`;
fetchAlbums().then((albums) => console.log(albums));
// [{ Title: 'For Those About To Rock We Salute You', ... }, ...]