Skip to content

Commit

Permalink
revert name -> text rename
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusmarminge committed Sep 14, 2023
1 parent 1155b8c commit 4429566
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 31 deletions.
4 changes: 2 additions & 2 deletions cli/template/extras/prisma/schema/base.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ datasource db {

model Post {
id Int @id @default(autoincrement())
text String
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([text])
@@index([name])
}
4 changes: 2 additions & 2 deletions cli/template/extras/prisma/schema/with-auth.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ datasource db {

model Post {
id Int @id @default(autoincrement())
text String
name String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdBy User @relation(fields: [createdById], references: [id])
createdById String
@@index([text])
@@index([name])
}

// Necessary for Next auth
Expand Down
10 changes: 5 additions & 5 deletions cli/template/extras/src/app/_components/create-post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ import { api } from "~/trpc/react";

export function CreatePost() {
const router = useRouter();
const [text, setText] = useState("");
const [name, setName] = useState("");

const createPost = api.post.create.useMutation({
onSuccess: () => {
router.refresh();
setText("");
setName("");
},
});

return (
<form
onSubmit={(e) => {
e.preventDefault();
createPost.mutate({ text });
createPost.mutate({ name });
}}
className="flex flex-col gap-2"
>
<input
type="text"
placeholder="Title"
value={text}
onChange={(e) => setText(e.target.value)}
value={name}
onChange={(e) => setName(e.target.value)}
className="w-full rounded-full px-4 py-2 text-black"
/>
<button
Expand Down
2 changes: 1 addition & 1 deletion cli/template/extras/src/app/page/with-auth-trpc-tw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async function CrudShowcase() {
return (
<div className="w-full max-w-xs">
{latestPost ? (
<p className="truncate">Your most recent post: {latestPost.text}</p>
<p className="truncate">Your most recent post: {latestPost.name}</p>
) : (
<p>You have no posts yet.</p>
)}
Expand Down
21 changes: 20 additions & 1 deletion cli/template/extras/src/app/page/with-auth-trpc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,27 @@ export default async function Home() {
</div>
</div>

<CreatePost />
<CrudShowcase />
</div>
</main>
);
}

async function CrudShowcase() {
const session = await getServerAuthSession();
if (!session?.user) return null;

const latestPost = await api.post.getLatest.query();

return (
<div>
{latestPost ? (
<p>Your most recent post: {latestPost.name}</p>
) : (
<p>You have no posts yet.</p>
)}

<CreatePost />
</div>
);
}
18 changes: 17 additions & 1 deletion cli/template/extras/src/app/page/with-trpc-tw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,23 @@ export default async function Home() {
</div>
</div>

<CreatePost />
<CrudShowcase />
</main>
);
}

async function CrudShowcase() {
const latestPost = await api.post.getLatest.query();

return (
<div className="w-full max-w-xs">
{latestPost ? (
<p className="truncate">Your most recent post: {latestPost.name}</p>
) : (
<p>You have no posts yet.</p>
)}

<CreatePost />
</div>
);
}
18 changes: 17 additions & 1 deletion cli/template/extras/src/app/page/with-trpc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,24 @@ export default async function Home() {
</p>
</div>

<CreatePost />
<CrudShowcase />
</div>
</main>
);
}

async function CrudShowcase() {
const latestPost = await api.post.getLatest.query();

return (
<div className="w-full max-w-xs">
{latestPost ? (
<p className="truncate">Your most recent post: {latestPost.name}</p>
) : (
<p>You have no posts yet.</p>
)}

<CreatePost />
</div>
);
}
6 changes: 3 additions & 3 deletions cli/template/extras/src/server/api/routers/post/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";

let post = {
id: 1,
text: "Hello World",
name: "Hello World",
};

export const postRouter = createTRPCRouter({
Expand All @@ -17,12 +17,12 @@ export const postRouter = createTRPCRouter({
}),

create: publicProcedure
.input(z.object({ text: z.string().min(1) }))
.input(z.object({ name: z.string().min(1) }))
.mutation(async ({ input }) => {
// simulate a slow db call
await new Promise((resolve) => setTimeout(resolve, 1000));

post = { id: post.id + 1, text: input.text };
post = { id: post.id + 1, name: input.name };
return post;
}),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export const postRouter = createTRPCRouter({
}),

create: protectedProcedure
.input(z.object({ text: z.string().min(1) }))
.input(z.object({ name: z.string().min(1) }))
.mutation(async ({ ctx, input }) => {
// simulate a slow db call
await new Promise((resolve) => setTimeout(resolve, 1000));

await ctx.db.insert(posts).values({
text: input.text,
name: input.name,
createdById: ctx.session.user.id,
});
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export const postRouter = createTRPCRouter({
}),

create: protectedProcedure
.input(z.object({ text: z.string().min(1) }))
.input(z.object({ name: z.string().min(1) }))
.mutation(async ({ ctx, input }) => {
// simulate a slow db call
await new Promise((resolve) => setTimeout(resolve, 1000));

return ctx.db.post.create({
data: {
text: input.text,
name: input.name,
createdBy: { connect: { id: ctx.session.user.id } },
},
});
Expand Down
6 changes: 3 additions & 3 deletions cli/template/extras/src/server/api/routers/post/with-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {

let post = {
id: 1,
text: "Hello World",
name: "Hello World",
};

export const postRouter = createTRPCRouter({
Expand All @@ -21,12 +21,12 @@ export const postRouter = createTRPCRouter({
}),

create: protectedProcedure
.input(z.object({ text: z.string().min(1) }))
.input(z.object({ name: z.string().min(1) }))
.mutation(async ({ input }) => {
// simulate a slow db call
await new Promise((resolve) => setTimeout(resolve, 1000));

post = { id: post.id + 1, text: input.text };
post = { id: post.id + 1, name: input.name };
return post;
}),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export const postRouter = createTRPCRouter({
}),

create: publicProcedure
.input(z.object({ text: z.string().min(1) }))
.input(z.object({ name: z.string().min(1) }))
.mutation(async ({ ctx, input }) => {
// simulate a slow db call
await new Promise((resolve) => setTimeout(resolve, 1000));

await ctx.db.insert(posts).values({
text: input.text,
name: input.name,
});
}),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export const postRouter = createTRPCRouter({
}),

create: publicProcedure
.input(z.object({ text: z.string().min(1) }))
.input(z.object({ name: z.string().min(1) }))
.mutation(async ({ ctx, input }) => {
// simulate a slow db call
await new Promise((resolve) => setTimeout(resolve, 1000));

return ctx.db.post.create({
data: {
text: input.text,
name: input.name,
},
});
}),
Expand Down
4 changes: 2 additions & 2 deletions cli/template/extras/src/server/db/drizzle-schema-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const posts = mysqlTable(
"post",
{
id: bigint("id", { mode: "number" }).primaryKey().autoincrement(),
text: varchar("name", { length: 256 }),
name: varchar("name", { length: 256 }),
createdById: varchar("createdById", { length: 255 }).notNull(),
createdAt: timestamp("created_at")
.default(sql`CURRENT_TIMESTAMP`)
Expand All @@ -32,7 +32,7 @@ export const posts = mysqlTable(
},
(example) => ({
createdByIdIdx: index("createdById_idx").on(example.createdById),
textIndex: index("text_idx").on(example.text),
nameIndex: index("name_idx").on(example.name),
})
);

Expand Down
4 changes: 2 additions & 2 deletions cli/template/extras/src/server/db/drizzle-schema-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export const posts = mysqlTable(
"post",
{
id: bigint("id", { mode: "number" }).primaryKey().autoincrement(),
text: varchar("name", { length: 256 }),
name: varchar("name", { length: 256 }),
createdAt: timestamp("created_at")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: timestamp("updatedAt").onUpdateNow(),
},
(example) => ({
textIndex: index("text_idx").on(example.text),
nameIndex: index("text_idx").on(example.name),
})
);

0 comments on commit 4429566

Please sign in to comment.