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 function
  • getConnection() - Get current connection instance
  • getDatabase() - Get arangojs Database instance
  • getGraphManager() - Get GraphManager instance
  • getVectorSearch() - Get VectorSearch instance
  • getTransactionManager() - Get TransactionManager instance
  • getSearchManager() - Get SearchManager instance
  • getGeoQuery() - Get GeoQuery instance
  • getBulkOperations() - Get BulkOperations instance
  • Database - Re-exported from arangojs
  • ArangoClient - Alias for Database
  • ConnectionOptions - TypeScript type for connection options

Function Signatures

  • connect(url: string, options?: ConnectionOptions): Promise<void>
  • connect(options: ConnectionOptions): Promise<void>
  • getConnection(): Connection - Get current connection instance
  • getDatabase(): Database - Get arangojs Database instance
  • getGraphManager(): GraphManager - Get GraphManager instance
  • getVectorSearch(): VectorSearch - Get VectorSearch instance
  • getTransactionManager(): TransactionManager - Get TransactionManager instance
  • getSearchManager(): SearchManager - Get SearchManager instance
  • getGeoQuery(): GeoQuery - Get GeoQuery instance
  • getBulkOperations(): 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.