Skip to content

Commit

Permalink
Refactor database connection to use connection pool and update error …
Browse files Browse the repository at this point in the history
…message for missing inputs
  • Loading branch information
PieterDePauw committed Nov 13, 2024
1 parent a13dfa0 commit 52cf324
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
8 changes: 5 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94576,8 +94576,10 @@ function generateEmbeddings(_a) {
return main_awaiter(this, arguments, void 0, function* ({ databaseUrl, openaiApiKey, docsRootPath }) {
// Initialize OpenAI client
const openaiClient = createOpenAI({ apiKey: openaiApiKey, compatibility: "strict" });
const client = createClient({ connectionString: databaseUrl });
const db = drizzle(client);
// const client = createClient({ connectionString: databaseUrl })
// const db = drizzle(client)
const pool = createPool({ connectionString: databaseUrl, max: 1, ssl: { rejectUnauthorized: false } });
const db = drizzle(pool);
const refreshVersion = esm_v4();
const refreshDate = new Date();
const ignoredFiles = ["pages/404.mdx"];
Expand Down Expand Up @@ -94657,7 +94659,7 @@ function run() {
const docsRootPath = core.getInput("docs-root-path") || "docs/";
// Check if the inputs are provided
if (!databaseUrl || !openaiApiKey) {
throw new Error("DATABASE_URL and OPENAI_API_KEY must be provided.");
throw new Error("The inputs 'database-url' and 'openai-api-key' must be provided.");
}
// Generate embeddings
yield generateEmbeddings({ databaseUrl: databaseUrl, openaiApiKey: openaiApiKey, docsRootPath: docsRootPath });
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable object-shorthand */
import * as core from "@actions/core"
import { eq, ne } from "drizzle-orm"
import { createClient } from "@vercel/postgres"
import { createPool } from "@vercel/postgres"
import { drizzle } from "drizzle-orm/vercel-postgres"
import { createOpenAI } from "@ai-sdk/openai"
import { embed } from "ai"
Expand Down Expand Up @@ -35,8 +35,18 @@ async function generateEmbeddings({ databaseUrl, openaiApiKey, docsRootPath }: {
// Initialize OpenAI client
const openaiClient = createOpenAI({ apiKey: openaiApiKey, compatibility: "strict" })

const client = createClient({ connectionString: databaseUrl })
const db = drizzle(client)
// const client = createClient({ connectionString: databaseUrl })
// const db = drizzle(client)

// Create a connection pool to the database
const pool = createPool({
connectionString: databaseUrl,
ssl: { rejectUnauthorized: false },
max: 1,
})

// Create a Drizzle instance
const db = drizzle(pool)

const refreshVersion = uuidv4()
const refreshDate = new Date()
Expand Down

0 comments on commit 52cf324

Please sign in to comment.