convex-db

द्वारा convex-dev

Convex DB का उपयोग करें — एक लैटिस-समर्थित SQL डेटाबेस। उपयोग तब करें जब उपयोगकर्ताओं को क्वेरी लिखने, JDBC या PostgreSQL क्लाइंट के माध्यम से कनेक्ट करने, टेबल बनाने, डेटा डालने/क्वेरी करने में मदद कर रहे हों,…

npx skills add https://github.com/convex-dev/convex --skill convex-db

Using Convex DB

Convex DB provides SQL access over lattice data. Connect via JDBC, PostgreSQL wire protocol, or the direct lattice API.

Reference: convex-db/README.md for full documentation including replication, PostgreSQL server setup, and architecture details.

Connecting

JDBC (Java)

// In-memory
Connection conn = DriverManager.getConnection("jdbc:convex:mydb");

// Persistent (Etch-backed, survives restarts)
Connection conn = DriverManager.getConnection("jdbc:convex:file:/data/mydb.etch");

Driver auto-registers via ServiceLoader. Class: convex.db.jdbc.ConvexDriver

PostgreSQL Clients (psql, DBeaver, DataGrip, Python, etc.)

# Start the PG server
java -cp convex-db.jar convex.db.psql.PgServer -p 5432 -d mydb

# Then connect with any PG client
psql -h localhost -p 5432 -d mydb
import psycopg2
conn = psycopg2.connect(host="localhost", port=5432, dbname="mydb")

Creating Tables

CREATE TABLE users (id, name, email)

Column 0 (first column) is always the primary key. Types are inferred from inserted data.

Names follow the SQL standard by default: unquoted names fold to upper case and compare exactly, so this creates USERS. A table created through the lattice API as users must be quoted in SQL ("users"), unless the database's identifier policy is :lower (IdentifierPolicy.LOWER.applyTo(db)), as a PostgreSQL user would expect.

Inserting Data

INSERT INTO users VALUES (1, 'Alice', 'alice@example.com')

For bulk loading, use prepared statements with batch:

PreparedStatement ps = conn.prepareStatement("INSERT INTO users VALUES (?, ?, ?)");
for (int i = 0; i < 10000; i++) {
    ps.setLong(1, i);
    ps.setString(2, "Name-" + i);
    ps.setString(3, "email-" + i + "@example.com");
    ps.addBatch();
}
ps.executeBatch();

Querying

-- Point lookup (fast — O(log n) via PK index pushdown)
SELECT * FROM users WHERE id = 1

-- Filtering, sorting, pagination
SELECT name, email FROM users WHERE name LIKE 'A%' ORDER BY name LIMIT 10

-- Joins
SELECT c.name, o.amount
FROM customers c INNER JOIN orders o ON c.id = o.customer_id

-- Aggregations
SELECT department, COUNT(*), AVG(salary)
FROM employees GROUP BY department HAVING COUNT(*) > 5

Supported SQL

  • DDL: CREATE TABLE, DROP TABLE
  • DML: INSERT, UPDATE, DELETE
  • Queries: SELECT, WHERE, ORDER BY, LIMIT, OFFSET
  • Joins: INNER JOIN, LEFT JOIN, RIGHT JOIN, CROSS JOIN
  • Aggregations: GROUP BY, HAVING, COUNT, SUM, AVG, MIN, MAX
  • Expressions: CASE WHEN, COALESCE, CAST, BETWEEN, IN, LIKE, IS NULL
  • Functions: ABS, FLOOR, CEIL, SQRT, UPPER, LOWER, TRIM, SUBSTRING, LENGTH, CONCAT

Transactions

conn.setAutoCommit(false);
stmt.execute("INSERT INTO users VALUES (2, 'Bob', 'bob@example.com')");
stmt.execute("UPDATE users SET email = 'new@example.com' WHERE id = 1");
conn.commit();    // atomic merge — all changes become visible
// or conn.rollback() to discard

Column Types

SQL TypeCVM TypeNotes
BIGINTAIntegerAny CVM integer; read as NUMERIC (BigDecimal)
INTEGERCVMLong64-bit signed integer; read as BIGINT
DOUBLECVMDouble64-bit float
VARCHARAStringUnicode string
BOOLEANCVMBooltrue/false
VARBINARY / BLOBABlobBinary data
TIMESTAMPCVMLongMilliseconds since epoch
ANYACellDynamic type

Direct Lattice API

For programmatic access without SQL overhead:

// The merge policy is the application's choice; RowLWW merges rows by last write
ConvexDB cdb = ConvexDB.create(RowLWW::merge);
SQLDatabase db = cdb.database("mydb");

// Create table
db.tables().createTable("users", new String[]{"id", "name", "email"});

// Insert
db.tables().insert("users", 1, "Alice", "alice@example.com");

// Point lookup
AVector<ACell> row = db.tables().selectByKey("users", 1);

// Scan all
Index<ABlob, AVector<ACell>> all = db.tables().selectAll("users");

// Delete
db.tables().deleteByKey("users", 1);

Performance Tips

  • Use PK lookups (WHERE id = ?) for point queries — O(log n) via index pushdown
  • Use PreparedStatements — plans compile once, reuse across executions
  • Use batch inserts for bulk loading — significantly faster than individual statements
  • Full scans are O(n) — filter on PK when possible

Building and Testing

Run from the repository root — see the build-convex skill.

# Build (-am also builds convex-core, which this depends on)
./mvnw -B -T1C install -pl convex-db -am

# Run tests
./mvnw -B -T1C test -pl convex-db -am

convex-dev की और Skills

account
convex-dev
Convex खाते बनाएँ या जाँचें। उपयोग तब करें जब उपयोगकर्ता नया खाता सेट करना, खाते का विवरण देखना, या कुंजियाँ प्रबंधित करना चाहता हो।
build-convex
convex-dev
कॉन्वेक्स प्रोजेक्ट को स्रोत से बनाएँ। तब उपयोग करें जब कोई योगदानकर्ता कॉन्वेक्स को संकलित, परीक्षण या पैकेज करना चाहता हो।
cad3-encoding
convex-dev
CAD3 एन्कोडिंग प्रारूप — सेल, एम्बेडेड बनाम ब्रांच संदर्भ, वैल्यू आईडी, वैधता नियम। एन्कोडर, डिकोडर, सीरियलाइज़ेशन, हैशिंग या… पर काम करते समय उपयोग करें।
cad-reference
convex-dev
Convex आर्किटेक्चर दस्तावेज़ों (CADs) का सूचकांक, जो Convex के लिए मानक विनिर्देश हैं। प्रोटोकॉल बदलने से पहले यह जानने के लिए उपयोग करें कि कौन सा CAD किस सबसिस्टम को नियंत्रित करता है,…
cns
convex-dev
Convex Name System (CNS) नामों को हल करें या पंजीकृत करें। जब उपयोगकर्ता CNS नाम खोजना, नया नाम पंजीकृत करना, या किसी नाम के लक्ष्य को अपडेट करना चाहे तब उपयोग करें।
convex-lisp
convex-dev
Convex Lisp भाषा संदर्भ — CVM प्रथाएँ, लाइब्रेरी कोड कॉल करना, एक्टर परिभाषाएँ, जूस और त्रुटि कोड। CVM स्रोत लिखने या डीबग करने के समय उपयोग करें…
deploy
convex-dev
Convex नेटवर्क पर एक एक्टर (स्मार्ट कॉन्ट्रैक्ट) तैनात करें। जब उपयोगकर्ता निर्यातित फ़ंक्शनों के साथ एक नया ऑन-चेन एक्टर बनाना चाहे तब इसका उपयोग करें।
ecosystem
convex-dev
Convex पारिस्थितिकी तंत्र में अभिविन्यास — कौन सी चीज़ किस रिपॉज़िटरी में है, स्पेक्स और दस्तावेज़ कहाँ हैं, और कौन से क्लाइंट लाइब्रेरी मौजूद हैं। जब आपको संदर्भ की आवश्यकता हो तो उपयोग करें…