This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
SQL-SOAR is a lightweight Node.js module that bridges object-oriented programming and relational databases. It provides full SQL control while eliminating repetitive hand-coding through JSON-based SQL expressions. The project supports both MySQL and PostgreSQL databases.
npm test- Run all tests (MySQL + PostgreSQL + shared)npm run test:mysql- Run MySQL-specific tests onlynpm run test:postgresql- Run PostgreSQL-specific tests onlynpm run test:shared- Run shared functionality testsnpm run test:simple- Quick test using PostgreSQL testQuery.jsnpm run test:all- Alias for full test suite
PostgreSQL:
npm run start:postgres- Start PostgreSQL test containernpm run setup:postgres- Initialize schema and sample datanpm run stop:postgres- Stop and remove container
MySQL:
npm run start:mysql- Start MySQL test containernpm run setup:mysql- Initialize schema and sample datanpm run stop:mysql- Stop and remove container
mocha test/postgresql/testQuery.js --timeout 10000mocha test/mysql/*.js --timeout 10000- Manual tests:
node test/manual/mysql/mysqlDataTypeMappingTest.js
Main Entry Point:
lib/soar.js- Primary API interface, exports all main functions (config, query, list, insert, update, del, execute, etc.)
Database Management:
lib/core/DBManager.js- Database connection management and initializationlib/core/DBConnMySQL.js- MySQL-specific connection handlinglib/core/DBConnPostgreSQL.js- PostgreSQL-specific connection handlinglib/core/sqlEngine.js- Core SQL execution engine with database-agnostic query processing
SQL Generation:
lib/sql/sqlComp.js- SQL expression composition (filters, joins, columns)lib/sql/sqlGenMySql.js- MySQL-specific SQL generationlib/sql/sqlGenPostgreSQL.js- PostgreSQL-specific SQL generation
Schema Management:
lib/mysqlSchemaManager.js- MySQL table creation/modificationlib/postgreSchemaManager.js- PostgreSQL table creation/modification
Multi-Database Support:
- Database type detection via explicit
typefield, port 5432 for PostgreSQL, or MySQL default - Database-specific connection classes handle driver differences
- SQL generators abstract database-specific syntax differences
SQL Expression System:
- JSON-based query composition via
soar.sql(table).column().filter().join() - Expressions can be stored as files and reused
- Auto-fill missing schema information from database metadata
Command Execution Flow:
soar.execute()→sqlEngine.execute()- Parse table name for multi-DB routing (
db.tablesyntax) - Auto-fill missing columns/filters using table schema
- Generate database-specific SQL
- Execute with connection pooling
- Transform results if needed
Single Database:
soar.config({
dbConfig: {
type: "postgresql", // or "mysql"
host: "localhost",
database: "myapp",
user: "user",
password: "pass"
}
});Multi-Database:
soar.config([
{ dbConfig: { alias: "main_db", type: "mysql", ... } },
{ dbConfig: { alias: "analytics_db", type: "postgresql", ... } }
]);test/mysql/- MySQL-specific functionality teststest/postgresql/- PostgreSQL-specific functionality teststest/shared/- Database-agnostic teststest/manual/- Manual testing scripts for debuggingtest/sampleData/- Test schemas and data for both databases
- The codebase uses database type detection in
DBManager.js:detectDatabaseType() - SQL generation is abstracted through database-specific generators
- Connection pooling is handled per database type
- Schema operations require database-specific managers
- All operations support both callback-style and connection-passing patterns