Skip to content

Commit

Permalink
Merge pull request #2032 from antman1p/patch-3
Browse files Browse the repository at this point in the history
chore: add conditionals for supabase to agent directory
  • Loading branch information
monilpat authored Jan 11, 2025
2 parents c7779eb + 6a9cbe3 commit 2152393
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"exec": "node --enable-source-maps --loader ts-node/esm src/index.ts"
},
"dependencies": {
"@elizaos/adapter-supabase": "workspace:*",
"@elizaos/adapter-postgres": "workspace:*",
"@elizaos/adapter-redis": "workspace:*",
"@elizaos/adapter-sqlite": "workspace:*",
Expand Down
39 changes: 32 additions & 7 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PGLiteDatabaseAdapter } from "@elizaos/adapter-pglite";
import { PostgresDatabaseAdapter } from "@elizaos/adapter-postgres";
import { RedisClient } from "@elizaos/adapter-redis";
import { SqliteDatabaseAdapter } from "@elizaos/adapter-sqlite";
import { SupabaseDatabaseAdapter } from "@elizaos/adapter-supabase";
import { AutoClientInterface } from "@elizaos/client-auto";
import { DiscordClientInterface } from "@elizaos/client-discord";
import { FarcasterAgentClient } from "@elizaos/client-farcaster";
Expand Down Expand Up @@ -456,7 +457,24 @@ export function getTokenForProvider(
}

function initializeDatabase(dataDir: string) {
if (process.env.POSTGRES_URL) {
if (process.env.SUPABASE_URL && process.env.SUPABASE_ANON_KEY) {
elizaLogger.info("Initializing Supabase connection...");
const db = new SupabaseDatabaseAdapter(
process.env.SUPABASE_URL,
process.env.SUPABASE_ANON_KEY
);

// Test the connection
db.init()
.then(() => {
elizaLogger.success("Successfully connected to Supabase database");
})
.catch((error) => {
elizaLogger.error("Failed to connect to Supabase:", error);
});

return db;
} else if (process.env.POSTGRES_URL) {
elizaLogger.info("Initializing PostgreSQL connection...");
const db = new PostgresDatabaseAdapter({
connectionString: process.env.POSTGRES_URL,
Expand All @@ -466,9 +484,7 @@ function initializeDatabase(dataDir: string) {
// Test the connection
db.init()
.then(() => {
elizaLogger.success(
"Successfully connected to PostgreSQL database"
);
elizaLogger.success("Successfully connected to PostgreSQL database");
})
.catch((error) => {
elizaLogger.error("Failed to connect to PostgreSQL:", error);
Expand All @@ -483,10 +499,19 @@ function initializeDatabase(dataDir: string) {
});
return db;
} else {
const filePath =
process.env.SQLITE_FILE ?? path.resolve(dataDir, "db.sqlite");
// ":memory:";
const filePath = process.env.SQLITE_FILE ?? path.resolve(dataDir, "db.sqlite");
elizaLogger.info(`Initializing SQLite database at ${filePath}...`);
const db = new SqliteDatabaseAdapter(new Database(filePath));

// Test the connection
db.init()
.then(() => {
elizaLogger.success("Successfully connected to SQLite database");
})
.catch((error) => {
elizaLogger.error("Failed to connect to SQLite:", error);
});

return db;
}
}
Expand Down

0 comments on commit 2152393

Please sign in to comment.