mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
fix mongodb templates and add migrate and generate scripts
This commit is contained in:
@@ -29,6 +29,14 @@
|
||||
"db:studio": {
|
||||
"cache": false,
|
||||
"persistent": true
|
||||
},
|
||||
"db:migrate": {
|
||||
"cache": false,
|
||||
"persistent": true
|
||||
},
|
||||
"db:generate": {
|
||||
"cache": false,
|
||||
"persistent": true
|
||||
}
|
||||
{{/unless}}{{/if}}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ export const auth = betterAuth({
|
||||
{{#if (eq database "postgres")}}provider: "postgresql"{{/if}}
|
||||
{{#if (eq database "sqlite")}}provider: "sqlite"{{/if}}
|
||||
{{#if (eq database "mysql")}}provider: "mysql"{{/if}}
|
||||
{{#if (eq database "mongodb")}}provider: "mongodb"{{/if}}
|
||||
}),
|
||||
trustedOrigins: [
|
||||
process.env.CORS_ORIGIN || "",{{#if (includes frontend "native")}}
|
||||
@@ -67,7 +68,7 @@ import { expo } from "@better-auth/expo";
|
||||
import { client } from "../db";
|
||||
|
||||
export const auth = betterAuth({
|
||||
database: mongodbAdapter(client.db()),
|
||||
database: mongodbAdapter(client),
|
||||
trustedOrigins: [
|
||||
process.env.CORS_ORIGIN || "",{{#if (includes frontend "native")}}
|
||||
"my-better-t-app://",{{/if}}
|
||||
@@ -104,4 +105,4 @@ export const auth = betterAuth({
|
||||
plugins: [expo()]
|
||||
{{/if~}}
|
||||
});
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import mongoose from 'mongoose';
|
||||
import mongoose from "mongoose";
|
||||
|
||||
await mongoose.connect(process.env.DATABASE_URL || "");
|
||||
const client = mongoose.connection.getClient();
|
||||
await mongoose.connect(process.env.DATABASE_URL || "").catch((error) => {
|
||||
console.log("Error connecting to database:", error);
|
||||
});
|
||||
|
||||
export { client };
|
||||
const client = mongoose.connection.getClient().db("myDB");
|
||||
|
||||
export { client };
|
||||
|
||||
@@ -23,7 +23,11 @@ export const todoRouter = {
|
||||
}),
|
||||
|
||||
toggle: publicProcedure
|
||||
{{#if (eq database "mongodb")}}
|
||||
.input(z.object({ id: z.string(), completed: z.boolean() }))
|
||||
{{else}}
|
||||
.input(z.object({ id: z.number(), completed: z.boolean() }))
|
||||
{{/if}}
|
||||
.handler(async ({ input }) => {
|
||||
await prisma.todo.update({
|
||||
where: { id: input.id },
|
||||
@@ -33,7 +37,11 @@ export const todoRouter = {
|
||||
}),
|
||||
|
||||
delete: publicProcedure
|
||||
{{#if (eq database "mongodb")}}
|
||||
.input(z.object({ id: z.string() }))
|
||||
{{else}}
|
||||
.input(z.object({ id: z.number() }))
|
||||
{{/if}}
|
||||
.handler(async ({ input }) => {
|
||||
await prisma.todo.delete({
|
||||
where: { id: input.id },
|
||||
@@ -69,7 +77,11 @@ export const todoRouter = router({
|
||||
}),
|
||||
|
||||
toggle: publicProcedure
|
||||
{{#if (eq database "mongodb")}}
|
||||
.input(z.object({ id: z.string(), completed: z.boolean() }))
|
||||
{{else}}
|
||||
.input(z.object({ id: z.number(), completed: z.boolean() }))
|
||||
{{/if}}
|
||||
.mutation(async ({ input }) => {
|
||||
try {
|
||||
return await prisma.todo.update({
|
||||
@@ -85,7 +97,11 @@ export const todoRouter = router({
|
||||
}),
|
||||
|
||||
delete: publicProcedure
|
||||
{{#if (eq database "mongodb")}}
|
||||
.input(z.object({ id: z.string() }))
|
||||
{{else}}
|
||||
.input(z.object({ id: z.number() }))
|
||||
{{/if}}
|
||||
.mutation(async ({ input }) => {
|
||||
try {
|
||||
return await prisma.todo.delete({
|
||||
|
||||
Reference in New Issue
Block a user