Connection Module
The Connection module provides database connection management with Mongoose-like API, connection caching, and automatic database creation.
What is it?
The Connection module is the foundation of arango-typed. It manages connections to ArangoDB servers, caches connections for performance, and provides helper functions to access database instances and managers.
Why do you need it?
- Connection Management: Establishes and manages database connections efficiently
- Performance: Caches connections to avoid reconnecting on every operation
- Auto-creation: Automatically creates databases if they don't exist (configurable)
- Helper Functions: Provides convenient access to database, graph manager, vector search, and other services
How it works
The Connection module uses a connection cache keyed by url|database|username. When you call connect() with the same parameters, it reuses the cached connection after a lightweight health check. This eliminates connection overhead in applications with multiple modules.
Exports
Connection- Connection class (internal use)connect()- Main connection functiongetConnection()- Get current connection instancegetDatabase()- Get arangojs Database instancegetGraphManager()- Get GraphManager instancegetVectorSearch()- Get VectorSearch instancegetTransactionManager()- Get TransactionManager instancegetSearchManager()- Get SearchManager instancegetGeoQuery()- Get GeoQuery instancegetBulkOperations()- Get BulkOperations instanceDatabase- Re-exported from arangojsArangoClient- Alias for DatabaseConnectionOptions- TypeScript type for connection options
Function Signatures
connect(url: string, options?: ConnectionOptions): Promise<void>connect(options: ConnectionOptions): Promise<void>getConnection(): Connection- Get current connection instancegetDatabase(): Database- Get arangojs Database instancegetGraphManager(): GraphManager- Get GraphManager instancegetVectorSearch(): VectorSearch- Get VectorSearch instancegetTransactionManager(): TransactionManager- Get TransactionManager instancegetSearchManager(): SearchManager- Get SearchManager instancegetGeoQuery(): GeoQuery- Get GeoQuery instancegetBulkOperations(): BulkOperations- Get BulkOperations instance
TypeScript Types
interface ConnectionOptions {
url: string | string[];
database?: string;
databaseName?: string; // Alternative to database
username?: string;
password?: string;
auth?: { username: string; password: string };
agent?: any; // HTTP agent
arangoVersion?: number;
autoCreateDatabase?: boolean; // Default: true
}
📖 For usage examples and best practices: See Connection Guide for detailed connection management documentation, examples, and best practices.