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.

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
BIGINT / INTEGERCVMLong64-bit signed integer
DOUBLECVMDouble64-bit float
VARCHARAStringUnicode string
BOOLEANCVMBooltrue/false
VARBINARY / BLOBABlobBinary data
TIMESTAMPCVMLongMilliseconds since epoch
ANYACellDynamic type

Direct Lattice API

For programmatic access without SQL overhead:

ConvexDB cdb = ConvexDB.create();
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의 다른 스킬

account
convex-dev
Convex 계정을 생성하거나 조회합니다. 사용자가 새 계정을 설정하거나, 계정 세부 정보를 확인하거나, 키를 관리하려 할 때 사용하세요.
account
convex-dev
Convex 계정을 생성하거나 조회합니다. 사용자가 새 계정을 설정하거나, 계정 세부 정보를 확인하거나, 키를 관리하려 할 때 사용하세요.
token
convex-dev
Convex에서 대체 가능한 토큰을 생성하고 관리합니다. 사용자가 새 토큰을 만들거나, 토큰 잔액을 확인하거나, 토큰 공급량을 관리하려 할 때 사용하세요.
build-convex
convex-dev
Convex 프로젝트를 소스에서 빌드합니다. 기여자가 Convex를 컴파일, 테스트 또는 패키징하려 할 때 사용합니다.
convex-db
convex-dev
Convex DB(래티스 기반 SQL 데이터베이스)를 사용하세요. 사용자가 쿼리 작성, JDBC 또는 PostgreSQL 클라이언트를 통한 연결, 테이블 생성, 데이터 삽입/조회 등을 도와야 할 때 사용합니다.
convex-lisp
convex-dev
Convex Lisp 언어 참조 — CVM 규칙, 라이브러리 코드 호출, 액터 정의, juice 및 오류 코드. CVM 소스를 작성하거나 디버깅할 때 사용합니다…
deploy
convex-dev
액터(스마트 계약)를 Convex 네트워크에 배포합니다. 사용자가 내보낸 함수를 가진 새로운 온체인 액터를 생성하려 할 때 사용하세요.
ecosystem
convex-dev
Convex 생태계에서의 방향 안내 — 어떤 리포지토리에 무엇이 있는지, 사양과 문서가 어디에 있는지, 그리고 어떤 클라이언트 라이브러리가 존재하는지. 컨텍스트가 필요할 때 사용하세요…