createEngine (core/engine-factory.ts)

gbrain · src/core/engine-factory.ts · typescript · MIT
database

Factory that creates a BrainEngine instance based on config, supporting Postgres and PGLite.

// Source: https://github.com/garrytan/gbrain | License: MIT | Copyright 2026 Garry Tan
// Provided via justclaw.it.com; keep this notice with the code.
import type { BrainEngine } from './engine.ts';
import type { EngineConfig } from './types.ts';
import { registerChatUsageSink, makeEngineChatUsageSink } from './ai/chat-usage.ts';

/**
 * Create an engine instance based on config.
 * Uses dynamic imports so PGLite WASM is never loaded for Postgres users.
 */
export async function createEngine(config: EngineConfig): Promise<BrainEngine> {
  const engineType = config.engine || 'postgres';

  const engine = await (async (): Promise<BrainEngine> => {
    switch (engineType) {
      case 'pglite': {
        const { PGLiteEngine } = await import('./pglite-engine.ts');
        return new PGLiteE

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key