Skip to content

Commit

Permalink
removed drizzle
Browse files Browse the repository at this point in the history
  • Loading branch information
Smef committed Jun 8, 2024
1 parent bfbd39b commit dacdcdb
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 688 deletions.
12 changes: 0 additions & 12 deletions drizzle.config.ts

This file was deleted.

9 changes: 1 addition & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,10 @@
"lint": "eslint .",
"test": "vitest run",
"test:watch": "vitest watch",
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
"db:studio": "drizzle-kit studio",
"db:dev-push": "drizzle-kit push",
"db:make-migration": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate"
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
},
"dependencies": {
"@nuxt/kit": "^3.11.2",
"better-sqlite3": "^11.0.0",
"drizzle-orm": "^0.31.2",
"lodash-es": "^4.17.21",
"zod": "^3.23.8"
},
Expand All @@ -61,7 +55,6 @@
"@types/node": "^20.12.11",
"autoprefixer": "^10.4.19",
"changelogen": "^0.5.5",
"drizzle-kit": "^0.22.6",
"eslint": "^9.2.0",
"eslint-config-prettier": "^9.1.0",
"nuxt": "^3.11.2",
Expand Down
Binary file removed playground/.data/sqlite.db
Binary file not shown.
13 changes: 0 additions & 13 deletions playground/database/index.ts

This file was deleted.

8 changes: 0 additions & 8 deletions playground/database/migrations/0000_deep_naoko.sql

This file was deleted.

63 changes: 0 additions & 63 deletions playground/database/migrations/meta/0000_snapshot.json

This file was deleted.

13 changes: 0 additions & 13 deletions playground/database/migrations/meta/_journal.json

This file was deleted.

30 changes: 0 additions & 30 deletions playground/database/migrations/run.ts

This file was deleted.

9 changes: 0 additions & 9 deletions playground/database/schema/registrations.ts

This file was deleted.

15 changes: 6 additions & 9 deletions playground/server/api/register-precog/index.post.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { z } from "zod";
import db from "~/database";
import { eq, sql } from "drizzle-orm";
import registrations from "~/database/schema/registrations";
import fakeDatabase from "~/server/utils/fakeDatabase";

const registrationSchema = z.object({
name: z.string().min(2, "Name must be at least 2 characters"),
Expand All @@ -14,12 +12,11 @@ const registrationSchema = z.object({
});

function checkIfEmailExists(email: string) {
const result = db
.select({ count: sql<number>`count(*)` })
.from(registrations)
.where(eq(registrations.email, email))
.get();
return result.count == 0;
const match = fakeDatabase.find((registration) => registration.email === email);
if (match) {
return false;
}
return true;
}

export default definePrecognitionEventHandler(registrationSchema, async (event) => {
Expand Down
5 changes: 2 additions & 3 deletions playground/server/api/registrations/index.get.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import db from "~/database";
import fakeDatabase from "~/server/utils/fakeDatabase";

export default defineEventHandler(async (event) => {
// get the list of registrations from the database
const results = await db.query.registrations.findMany();

return results;
return fakeDatabase;
});
21 changes: 9 additions & 12 deletions playground/server/api/registrations/index.post.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { z } from "zod";
import db from "~/database";
import registrations from "~/database/schema/registrations";
import { eq, sql } from "drizzle-orm";
import fakeDatabase from "~/server/utils/fakeDatabase";

const registrationSchema = z.object({
name: z.string().min(2, "Name must be at least 2 characters"),
Expand All @@ -14,12 +12,11 @@ const registrationSchema = z.object({
});

function checkIfEmailExists(email: string) {
const result = db
.select({ count: sql<number>`count(*)` })
.from(registrations)
.where(eq(registrations.email, email))
.get();
return result.count == 0;
const match = fakeDatabase.find((registration) => registration.email === email);
if (match) {
return false;
}
return true;
}

export default defineEventHandler(async (event) => {
Expand All @@ -33,12 +30,12 @@ export default defineEventHandler(async (event) => {
email: validated.email,
};

const creatredRegistration = db.insert(registrations).values(newRegistration).returning();
const fakeDatabase = getFakeDatabase;

fakeDatabase.push(newRegistration);

// simulate a slow response to show the loading state o the front-end
await sleep(1000);

return creatredRegistration;
});

function sleep(ms: number) {
Expand Down
19 changes: 19 additions & 0 deletions playground/server/utils/fakeDatabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const registrationArray = [
{
id: 1,
name: "David Nahodyl",
email: "[email protected]",
},
{
id: 2,
name: "Peter Parker",
email: "[email protected]",
},
{
id: 3,
name: "Bruce Wayne",
email: "[email protected]",
},
];

export default registrationArray;
Loading

0 comments on commit dacdcdb

Please sign in to comment.