Skip to main content

Overview

The NTQQDatabaseApi provides direct access to NTQQ’s encrypted SQLite databases, allowing you to read message history, user data, and other information stored locally by the QQ client.
Critical Requirements:
  • Requires node:sqlite (Node.js 22.5.0+)
  • Needs database passphrase (auto-captured by NapCat on login)
  • Databases are encrypted with SQLCipher format
  • Read-only recommended to avoid data corruption

Architecture

Implemented in packages/napcat-core/apis/database.ts:19, the API handles:
  • Database decryption using captured passphrase
  • SQLite connection management
  • Query execution and result parsing
  • Automatic cleanup and caching

Database Passphrase

NapCat automatically captures the database encryption key when QQ logs in. Check availability:

Database Locations

NT Database Directory

QQ databases are stored in the user’s profile:

Cache Directory

Decrypted databases are cached for performance:

Common Databases

Main NTQQ databases:
  • nt_msg.db - Message history and chat data
  • nt_data.db - User and group information
  • nt_group_data.db - Group member data
  • global-config.db - Client configuration
  • config.db - Additional settings

Simple Queries

Quick Query (Auto-Close)

For one-off queries, use the convenience methods:

Query Single Row

Execute Non-Query SQL

Modifying databases can corrupt your QQ data. Always backup before using execute() for writes.

Advanced Database Access

Manual Connection Management

For multiple queries, keep the connection open:

DatabaseHandle Methods

The DatabaseHandle class (from napcat-database package) provides:

Working with Already-Decrypted Databases

If you have a decrypted .db file:

Database Scanning

Read Single Database Schema

Get table structure and statistics:

Scan All Databases

Get info for all databases in nt_db directory:

TableInfo Structure

Decrypting Databases

Decrypt for External Use

Create a decrypted copy without reading schema:

Default Output Location

If you don’t specify output path:

Practical Examples

Get Recent Messages

Search Message Content

Get Group Member List

Export Chat History

Named Parameters

You can use named parameters instead of positional:

Error Handling

Platform Requirements

Node.js Version

Requires Node.js 22.5.0+ for node:sqlite support:

Best Practices

  1. Always use read-only mode when possible:
  2. Close connections to free resources:
  3. Use query() for simple cases to auto-close:
  4. Check passphrase availability before querying:
  5. Use parameterized queries to prevent SQL injection:

Limitations

  • Passphrase required: Cannot decrypt without login-captured key
  • Node.js 22.5+: Older versions don’t have node:sqlite
  • No real-time updates: Changes in QQ app won’t reflect immediately
  • Schema changes: Table structure may vary between QQ versions
  • Performance: Large queries on nt_msg.db can be slow