Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 180 additions & 1 deletion docs/docs/api/appkit/Function.getLakebaseOrmConfig.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions docs/docs/api/appkit/Interface.LakebasePoolConfig.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 29 additions & 3 deletions packages/lakebase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@ const users = await prisma.user.findMany();

```typescript
import { DataSource } from "typeorm";
import { createLakebasePool } from "@databricks/lakebase";

const pool = createLakebasePool();
import { getLakebaseOrmConfig } from "@databricks/lakebase";

const dataSource = new DataSource({
type: "postgres",
Expand All @@ -242,6 +240,34 @@ const sequelize = new Sequelize({
});
```

`getLakebaseOrmConfig()` returns the pool and client settings (connection lifetime, pool size, timeouts, SSL) where each ORM reads them:

- **TypeORM:** pool size, connect timeout and application name go under TypeORM's own `poolSize`, `connectTimeoutMS` and `applicationName`, so values you set after the spread still win. The rest (connection lifetime, idle timeout, statement and query timeouts) goes under `extra`, which TypeORM merges into the `pg.Pool` options.
- **Sequelize:** `dialectOptions` (passed to each `pg.Client`, including SSL), `pool` and `hooks`. Sequelize's pool has no lifetime option, so connections are recycled by age through `pool.validate` and an `afterConnect` hook.

The result carries keys for both ORMs, and each ignores the other's: Sequelize ignores `poolSize`, `connectTimeoutMS`, `applicationName` and `extra`, and TypeORM ignores `dialectOptions`, `pool` and `hooks`.

If you set `extra`, `pool`, `dialectOptions` or `hooks` yourself, merge with the returned values instead of replacing them, or those settings are lost. Replacing `hooks` makes connection lifetimes count from a connection's first reuse instead of when it opened, and logs a warning if you passed a `logger` (nothing is logged without one).

```typescript
const ormConfig = getLakebaseOrmConfig();

// TypeORM
const dataSource = new DataSource({
type: "postgres",
...ormConfig,
extra: { ...ormConfig.extra, allowExitOnIdle: true },
});

// Sequelize
const sequelize = new Sequelize({
dialect: "postgres",
...ormConfig,
pool: { ...ormConfig.pool, min: 2 },
hooks: { ...ormConfig.hooks, beforeConnect: async () => {} },
});
```

## OpenTelemetry Integration

The driver automatically uses OpenTelemetry's global registry when available. If your application initializes OpenTelemetry providers, the driver will automatically instrument queries and metrics with no additional configuration needed.
Expand Down
4 changes: 3 additions & 1 deletion packages/lakebase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
"@opentelemetry/api": "1.9.0"
},
"devDependencies": {
"@types/pg": "8.16.0"
"@types/pg": "8.16.0",
"sequelize": "6.37.7",
"typeorm": "0.3.28"
},
"publishConfig": {
"exports": {
Expand Down
Loading