Writing data to your database
After you’ve created a database in SQLite Cloud, you can start writing data to it. You can write data to your cluster using the SQLite Cloud UI, API, or client libraries.
Upload an existing SQLite Database
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.
Writing data with the SQLite Cloud UI
Navigate to the console tab in the left-hand navigation. From here, you can run SQL commands against your cluster. Use the optional dropdown menus to select a database and table.
Example
-- If you haven't selected a database yet, run the USE DATABASE command
USE DATABASE mydatabase.sqlite;
-- Create your table
CREATE TABLE sports_cars (sc_id INTEGER PRIMARY KEY, sc_name TEXT NOT NULL, sc_year INTEGER NOT NULL, image BLOB);
-- Insert data into your table
INSERT INTO sports_cars (sc_name, sc_year, image) VALUES ('Ferrari', 2021, 'https://example.com/ferrari.jpg');
Writing data with the Weblite API
You can use the API to run SQL commands against your cluster.
curl -X 'POST' \
'https://<your-project-id>.sqlite.cloud:8090/v2/weblite/sql' \
-H 'accept: application/json' \
-H 'Authorization: Bearer sqlitecloud://<your-project-id>.sqlite.cloud:8860?apikey=<your-api-key>' \
-d '<your-sql-here>'
Writing data with client libraries
To write data to your cluster using a client library, use the INSERT INTO SQL command.
import { Database } from '@sqlitecloud/drivers';
const db = new Database('sqlitecloud://<your-project-id>.sqlite.cloud:<your-host-port>?apikey=<your-api-key>')
db.exec('USE DATABASE mydatabase.sqlite;')
db.exec('CREATE TABLE sports_cars (sc_id INTEGER PRIMARY KEY, sc_name TEXT NOT NULL, sc_year INTEGER NOT NULL, image BLOB);')
db.commit()
const insertData = async () => await db.sql`INSERT INTO sports_cars (sc_name, sc_year, image) VALUES ('Ferrari', 2021, 'https://example.com/ferrari.jpg');`;
insertData().then((res) => console.log(res));
// "OK"