Overview
TheEngine is the main entry point for ChameleonDB. It loads the schema from the Schema Vault, manages database connections, and provides access to query and mutation APIs.
Initialization
NewEngine()
Creates a new engine instance with automatic schema loading from the vault.- Loads schema from
.chameleon/state/schema.merged.cham(or configured path) - Verifies vault integrity before loading
- Returns error if vault is not initialized or integrity check fails
- Ready to use immediately after creation
Connection Management
Connect()
Establishes a connection to the PostgreSQL database.context.Context
required
Context for the connection operation
ConnectorConfig
required
Database connection configuration
string
default:"localhost"
PostgreSQL server hostname
int
default:"5432"
PostgreSQL server port
string
required
Database name
string
required
Database user
string
Database password
int32
default:"10"
Maximum number of connections in the pool
int32
default:"2"
Minimum number of connections in the pool
time.Duration
default:"5m"
Maximum time a connection can be idle
Close()
Closes the database connection pool.Ping()
Verifies the database connection is alive.IsConnected()
Returns true if the engine is connected to a database.Configuration
ParseConnectionString()
Parses a PostgreSQL connection URL into aConnectorConfig.
postgresql://user:password@host:port/dbnamepostgres://user:password@host:port/dbname
DefaultConfig()
Returns sensible default configuration values.Schema Access
GetSchema()
Returns the currently loaded schema.Version()
Returns the ChameleonDB engine version.Debug Mode
WithDebug()
Enables debug output for all operations.DebugLevel
No debug output (default)
DebugLevel
Show generated SQL queries
DebugLevel
Show SQL + execution time + row counts
DebugLevel
Show SQL + EXPLAIN output (future)
Error Handling
Common Errors
error
The Schema Vault hasn’t been initialized. Run
chameleon init first.error
Schema vault has been tampered with. Run
chameleon verify to investigate.error
Attempted to query/mutate without calling
Connect() first.Complete Example
See Also
- Query Builder - Build and execute queries
- Mutations - Insert, update, and delete data
- Error Handling - Handle errors gracefully