| title | Writing data to your database |
|---|---|
| description | Learn how to write data to your SQLite Cloud cluster. |
| category | getting-started |
| status | publish |
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.
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.
-- 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');You can use the SQLite Cloud API to write data to your cluster.
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 ''You can also 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 ''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"