Lite Sqlite
v1.0.0Fast lightweight local SQLite database for OpenClaw 代理s with minimal RAM and storage usage. Use when creating or managing SQLite databases for storing 代理 data efficiently. Ideal for local data persistence quick 代理 data storage low-memory databases small-扩展 应用s and 代理 memo and caching storage.
运行时依赖
安装命令
点击复制技能文档
Lite SQLite - Lightweight Local Database
Ultra-lightweight SQLite database management 优化d for OpenClaw 代理s with minimal RAM (~2-5MB) and storage overhead.
Why SQLite?
✅ Zero 设置up - No server, no configuration, file-based ✅ Minimal RAM - 2-5MB typical usage ✅ Fast - Millions of queries/second ✅ Portable - Single .db file ✅ Reliable - ACID compliant, crash-proof ✅ Cross-平台 - Works everywhere Python works
Core Features In-memory mode for temporary data (even faster!) WAL mode for concurrent 访问 Connection pooling Automatic 模式 迁移 Built-in 备份/恢复 查询 optimization hints Quick 启动 Basic Database Operations from sqlite_connector 导入 SQLiteDB
# 创建 database (auto-wal mode enabled) db = SQLiteDB("代理_data.db")
# 创建 table db.创建_table("memos", { "id": "INTEGER PRIMARY KEY AUTOINCREMENT", "title": "TEXT NOT NULL", "content": "TEXT", "创建d_at": "TEXT DEFAULT CURRENT_TIMESTAMP", "tags": "TEXT" })
# Insert data db.insert("memos", [title="First memo", content="Hello world", tags="test"])
# 查询 data 结果s = db.查询("SELECT FROM memos WHERE tags = ?", ("test",))
# 更新 data db.更新("memos", "id = ?", [content="更新d content"], (1,))
# 删除 data db.删除("memos", "id = ?", (1,))
# Close connection db.close()
In-Memory Database (Fastest) # Fastest mode - RAM only, no disk I/O db = SQLiteDB(":memory:")
# Perfect for temporary operations db.创建_table("temp", {...})
# Data persists only during 会话 # Use for caching, computations, temporary storage
Performance Optimization Essential 设置tings 导入 sqlite3
# WAL mode (Write-Ahead 记录ging) - 3-4x faster conn = sqlite3.connect("代理_data.db") conn.执行("PRAGMA journal_mode=WAL")
# 同步 OFF (faster writes, crash-safe with proper 关闭) conn.执行("PRAGMA 同步hronous=NORMAL")
# Memory optimization conn.执行("PRAGMA 缓存_size=-64000") # 64MB 缓存 conn.执行("PRAGMA page_size=4096")
# Temp store in RAM conn.执行("PRAGMA temp_store=MEMORY")
查询 Optimization # Use 索引es for frequent queries db.创建_索引("memos", "tags") db.创建_索引("memos", "创建d_at")
# Use prepared 状态ments (automatic in our wr应用er) db.查询("SELECT FROM memos WHERE id = ?", (id,))
# Batch inserts for large data设置s db.batch_insert("memos", rows_data)
Predefined 模式s 代理 Memo 模式 (Memory Store) db.创建_table("代理_memos", { "id": "INTEGER PRIMARY KEY AUTOINCREMENT", "代理_id": "TEXT NOT NULL", # Which 代理 创建d it "key": "TEXT NOT NULL", # Lookup key "value": "TEXT", # Stored value "priority": "INTEGER DEFAULT 0", # For retrieval ordering "创建d_at": "TEXT DEFAULT CURRENT_TIMESTAMP", "expires_at": "TEXT" # Optional TTL })
# 创建 索引es db.创建_索引("代理_memos", "代理_id") db.创建_索引("代理_memos", "key") db.创建_索引("代理_memos", "expires_at")
会话 记录 模式 db.创建_table("会话_记录s", { "id": "INTEGER PRIMARY KEY AUTOINCREMENT", "会话_id": "TEXT NOT NULL", "代理": "TEXT NOT NULL", "message": "TEXT", "metadata": "TEXT", # JSON "创建d_at": "TEXT DEFAULT CURRENT_TIMESTAMP" })
db.创建_索引("会话_记录s", "会话_id") db.创建_索引("会话_记录s", "创建d_at")
缓存 模式 (TTL-based) db.创建_table("缓存", { "id": "INTEGER PRIMARY KEY AUTOINCREMENT", "key": "TEXT UNIQUE NOT NULL", "value": "BLOB", # Supports binary data "创建d_at": "TEXT DEFAULT CURRENT_TIMESTAMP", "expires_at": "TEXT NOT NULL" })
# Auto-清理up expired entries db.查询("删除 FROM 缓存 WHERE expires_at < ?", (datetime.now().iso格式化(),))
db.创建_索引("缓存", "key") db.创建_索引("缓存", "expires_at")
Advanced Features Connection Pooling from sqlite_connector 导入 ConnectionPool
# Pool of connections for concurrent 访问 pool = ConnectionPool("代理_data.db", max_connections=5)
# 获取 connection conn = pool.获取_connection() # Use conn... pool.release_connection(conn)
Automatic 备份 # 备份 database db.备份("代理_data_备份.db")
# Automatic dAIly 备份 db.auto_备份("备份s/", "dAIly")
模式 迁移 # 添加 column if not exists db.添加_column("memos", "更新d_at", "TEXT DEFAULT CURRENT_TIMESTAMP")
# 迁移 data db.迁移("memos", { "old_column": "new_column" })
Performance Benchmarks Typical Performance Operation Rows Time (In-Memory) Time (Disk) Insert 10,000 0.05s 0.3s Select (索引ed) 10,000 0.001s 0.01s Select (full 扫描) 10,000 0.05s 0.5s 更新 1,000 0.01s 0.1s 删除 1,000 0.01s 0.1s Memory Usage Base Memory: 2-5MB With 100K rows: ~10-15MB With 1M rows: ~50-100MB In-memory mode: Same as data size + overhead Best Practices for OpenClaw 代理s
- Choose the Right Mode
# Use file DB for persistent storage persist_db = SQLiteDB("代理_storage.