⚙️ CitadelSQL SDK (Recommended)
The official SDK provides a persistent connection object for all your queries.
Include it once and use CitadelSQL like any modern database.
<script src="https://sql.astrocitadelltd.com/sdk.js"></script>
<script>
(async () => {
const connection = new CitadelSQL("ekene", "astro2025");
await connection.connect();
await connection.createTable("users", {
id: "NUMBER",
name: "TEXT",
email: "VARCHAR(80)",
joined: "DATE"
});
await connection.insert("users", {
name: "Ifeoma",
email: "ifeoma@astro.com",
joined: "2025-10-27"
});
const users = await connection.select("users");
console.log(users.rows);
})();
</script>
Available Methods
- connect() → Authenticates and stores a session token.
- query(sql) → Runs any SQL or db.* command.
- createTable(name, fields) → Creates new table.
- insert(table, record) → Inserts JSON record.
- select(table, where) → Returns rows matching filter.
- db(command) → Directly execute
db.*shorthand.
🚀 Axios Integration (Manual API)
Use Axios for fine-grained control of CitadelSQL API requests. Perfect for Node.js back-end or when integrating into existing apps.
import axios from "axios";
const API = "https://sql.astrocitadelltd.com/sql";
async function main() {
// Connect to CitadelSQL
const { data: conn } = await axios.post(`${API}/connect`, {
user: "ekene",
pass: "astro2025"
});
const token = conn.token;
// Create a table
await axios.post(`${API}/query`, {
token,
sql: "CREATE TABLE customers (id NUMBER, name TEXT, email VARCHAR(80), joined DATE)"
});
// Insert a record
await axios.post(`${API}/query`, {
token,
sql: "INSERT INTO customers (name,email,joined) VALUES ('Ifeoma','ifeoma@astro.com','2025-10-27')"
});
// Select data
const res = await axios.post(`${API}/query`, {
token,
sql: "SELECT * FROM customers"
});
console.log(res.data.rows);
}
main();
🧠 SQL Syntax
Run standard SQL directly through the API or SDK:
CREATE TABLE users (id NUMBER, name TEXT, email VARCHAR(60), created DATE);
INSERT INTO users (name,email,created)
VALUES ('Ekene','ekene@astro.com','2025-10-27');
SELECT * FROM users WHERE name='Ekene';
🧩 db.* Syntax (JavaScript-Style)
The db.* shorthand provides a JavaScript-like way to run commands:
db.insert users name=Ekene,email=ekene@astro.com,created=2025-10-27 db.select users where name='Ekene'
It’s ideal for scripting and low-code automation.
📦 Supported Data Types
- NUMBER — Integer or float values.
- TEXT — Unlimited string length.
- VARCHAR(n) — String limited to
ncharacters. - DATE — ISO date (YYYY-MM-DD).
🔗 REST API Endpoints
POST /sql/createUser → Create account (returns permanent token) POST /sql/connect → Log in or connect with token POST /sql/query → Run SQL or db.* query
All endpoints return JSON. Tokens identify user-specific data stored under
/data/sql_users/<username>/.
Quick Links: