feat: ditch triplit, move to postgresql + drizzle orm
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { nanoid } from "nanoid";
|
||||
import { Providers } from "~/types/model";
|
||||
import { db } from "~~/server/lib/db";
|
||||
import { providers as providersSchema } from "~~/drizzle/schema";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
await protectRoute(event);
|
||||
const userId = event.context.user!.id as string;
|
||||
|
||||
const providers = await db.query.providers.findMany({
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
with: {
|
||||
models: true,
|
||||
},
|
||||
});
|
||||
|
||||
Providers.forEach(async p => {
|
||||
if (!providers.find(provider => provider.type === p)) {
|
||||
const [created] = await db.insert(providersSchema).values({
|
||||
id: nanoid(),
|
||||
userId,
|
||||
type: p,
|
||||
name: p,
|
||||
enabled: false,
|
||||
config: {},
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
}).returning() as typeof providers;
|
||||
if (created) {
|
||||
created.models = [];
|
||||
providers.push(created);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return providers;
|
||||
})
|
||||
Reference in New Issue
Block a user