(input: z.infer<typeof apiCreateLibsql>)
| 17 | export type Libsql = typeof libsql.$inferSelect; |
| 18 | |
| 19 | export const createLibsql = async (input: z.infer<typeof apiCreateLibsql>) => { |
| 20 | const appName = buildAppName("libsql", input.appName); |
| 21 | |
| 22 | const valid = await validUniqueServerAppName(input.appName); |
| 23 | if (!valid) { |
| 24 | throw new TRPCError({ |
| 25 | code: "CONFLICT", |
| 26 | message: "Service with this 'AppName' already exists", |
| 27 | }); |
| 28 | } |
| 29 | |
| 30 | const newLibsql = await db |
| 31 | .insert(libsql) |
| 32 | .values({ |
| 33 | ...input, |
| 34 | databasePassword: input.databasePassword |
| 35 | ? input.databasePassword |
| 36 | : generatePassword(), |
| 37 | appName, |
| 38 | }) |
| 39 | .returning() |
| 40 | .then((value) => value[0]); |
| 41 | |
| 42 | if (!newLibsql) { |
| 43 | throw new TRPCError({ |
| 44 | code: "BAD_REQUEST", |
| 45 | message: "Error input: Inserting libsql database", |
| 46 | }); |
| 47 | } |
| 48 | |
| 49 | return newLibsql; |
| 50 | }; |
| 51 | |
| 52 | // https://github.com/drizzle-team/drizzle-orm/discussions/1483#discussioncomment-7523881 |
| 53 | export const findLibsqlById = async (libsqlId: string) => { |
no test coverage detected