Skip to content

Commit f4bb729

Browse files
authored
feat(appkit): introduce Lakebase plugin (#126)
* feat(appkit): introduce Lakebase plugin * docs: describe how to connect an AppKit app with Lakebase * chore: regenerate types * chore: use biome-ignore comments * chore: fix docs build * chore: add a note about having the plugin experimental * chore: bring back the "onSetupMessage" * chore: address comments * chore: regenerate docs
1 parent 72044bd commit f4bb729

40 files changed

Lines changed: 914 additions & 502 deletions

apps/dev-playground/server/lakebase-examples-plugin.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Plugin, toPlugin } from "@databricks/appkit";
1+
import { getUsernameWithApiLookup, Plugin, toPlugin } from "@databricks/appkit";
22
import type { IAppRouter } from "shared";
33
import * as drizzleExample from "./lakebase-examples/drizzle-example";
44
import * as rawExample from "./lakebase-examples/raw-driver-example";
@@ -42,12 +42,14 @@ export class LakebaseExamplesPlugin extends Plugin {
4242
}
4343

4444
try {
45+
const user = await getUsernameWithApiLookup();
46+
4547
// Initialize all four examples in parallel
4648
await Promise.all([
47-
rawExample.setup(),
48-
drizzleExample.setup(),
49-
typeormExample.setup(),
50-
sequelizeExample.setup(),
49+
rawExample.setup(user),
50+
drizzleExample.setup(user),
51+
typeormExample.setup(user),
52+
sequelizeExample.setup(user),
5153
]);
5254
} catch (error) {
5355
console.error("Failed to initialize Lakebase examples:", error);

apps/dev-playground/server/lakebase-examples/drizzle-example.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ type NewActivityLog = typeof activityLogs.$inferInsert;
4545
let db: ReturnType<typeof drizzle>;
4646
let pool: Pool;
4747

48-
export async function setup() {
49-
pool = createLakebasePool();
48+
export async function setup(user?: string) {
49+
pool = createLakebasePool({ user });
5050
db = drizzle(pool);
5151

5252
// For production apps, use: npx drizzle-kit push or drizzle-kit generate + migrate

apps/dev-playground/server/lakebase-examples/raw-driver-example.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ interface Product {
2525
created_at: Date;
2626
}
2727

28-
export async function setup() {
28+
export async function setup(user?: string) {
2929
// Create pool with automatic OAuth token refresh
30-
pool = createLakebasePool();
30+
pool = createLakebasePool({ user });
3131

3232
// Create schema and table (idempotent)
3333
await pool.query(`

apps/dev-playground/server/lakebase-examples/sequelize-example.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ class Order
4343

4444
let sequelize: Sequelize;
4545

46-
export async function setup() {
46+
export async function setup(user?: string) {
4747
// @ts-expect-error password property supports a function for Lakehouse OAuth tokens
4848
sequelize = new Sequelize({
4949
dialect: "postgres",
50-
...getLakebaseOrmConfig(),
50+
...getLakebaseOrmConfig({ user }),
5151
logging: false,
5252
});
5353

apps/dev-playground/server/lakebase-examples/typeorm-example.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ class Task {
4343

4444
let dataSource: DataSource;
4545

46-
export async function setup() {
46+
export async function setup(user?: string) {
4747
// Create schema if not exists (TypeORM's synchronize doesn't create schemas)
4848
// See https://github.com/typeorm/typeorm/issues/3192
49-
const pool = createLakebasePool();
49+
const pool = createLakebasePool({ user });
5050
await pool.query("CREATE SCHEMA IF NOT EXISTS typeorm_example");
5151
await pool.end();
5252

5353
dataSource = new DataSource({
5454
type: "postgres",
55-
...getLakebaseOrmConfig(),
55+
...getLakebaseOrmConfig({ user }),
5656
entities: [Task],
5757
synchronize: true,
5858
logging: false,

docs/docs/architecture.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ The backend SDK that provides the plugin architecture and core functionality. It
4747
- Cache management and streaming capabilities
4848
- Type generation for SQL queries
4949

50-
See the [Plugins](./plugins.md) and [API reference](./api/appkit/) documentation for detailed information.
50+
See the [Plugins](./plugins/index.md) and [API reference](./api/appkit/) documentation for detailed information.
5151

5252
### @databricks/appkit-ui
5353

@@ -87,7 +87,7 @@ Integration with Databricks services:
8787

8888
## See also
8989

90-
- [Plugins](./plugins.md): Deep dive into the plugin system
90+
- [Plugins](./plugins/index.md): Deep dive into the plugin system
9191
- [API reference](./api/): Complete API documentation
9292
- [Development](./development/): Explore development workflows
9393
- [Core Principles](./core-principles.md): Learn about AppKit's design philosophy

docs/docs/configuration.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,4 @@ For advanced Databricks Apps configuration (authorization, networking, resource
142142
## See also
143143

144144
- [App management](./app-management.mdx) - Deploying and managing apps
145-
- [Plugins](./plugins.md) - Plugin configuration options
145+
- [Plugins](./plugins/index.md) - Plugin configuration options

docs/docs/development/project-setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,4 @@ Then create `config/queries/` and add your `.sql` files.
232232

233233
- [Local development](./local-development.mdx) - Running the dev server
234234
- [Configuration](../configuration.mdx) - Environment variables
235-
- [Plugins](../plugins.md) - Plugin configuration
235+
- [Plugins](../plugins/index.md) - Plugin configuration

docs/docs/development/type-generation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,5 @@ data?.forEach(row => {
104104

105105
## See also
106106

107-
- [Plugins](../plugins.md) - Analytics plugin configuration
107+
- [Plugins](../plugins/index.md) - Analytics plugin configuration
108108
- [API Reference](/docs/api/appkit-ui) - Complete UI components API documentation

0 commit comments

Comments
 (0)