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.
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 <your-database-name>.sqlite;
-- Create your table
CREATE TABLE sports_cars (sc_id INTEGER PRIMARY KEY, sc_make TEXT NOT NULL, sc_year INTEGER NOT NULL);
-- Insert data into your table
INSERT INTO sports_cars (sc_make, sc_year) VALUES ('Ferrari', 2021);
Writing data with the Weblite API
You can use the Weblite API to run SQL commands against your cluster. Here is an example cURL request:
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 <your-database-name>.sqlite;')
db.exec('CREATE TABLE sports_cars (sc_id INTEGER PRIMARY KEY, sc_make TEXT NOT NULL, sc_year INTEGER NOT NULL);')
db.commit()
const insertData = async () => await db.sql('INSERT INTO sports_cars (sc_make, sc_year) VALUES (?, ?)', 'Ferrari', 2021);
insertData().then((res) => console.log(res));
// "OK"