diff --git a/packages/api/src/lib/getCarsByFuelType.ts b/packages/api/src/lib/getCarsByFuelType.ts index 97bb16e..0a24091 100644 --- a/packages/api/src/lib/getCarsByFuelType.ts +++ b/packages/api/src/lib/getCarsByFuelType.ts @@ -1,9 +1,9 @@ import db from "@/config/db"; import { getLatestMonth } from "@/lib/getLatestMonth"; -import { cars } from "@/schema"; import type { FuelType } from "@/types"; import getTrailingTwelveMonths from "@/utils/getTrailingTwelveMonths"; import { and, asc, between, desc, eq, ilike, or } from "drizzle-orm"; +import { cars } from "../../../schema"; const HYBRID_TYPES = [ "Diesel-Electric", diff --git a/packages/api/src/schema.ts b/packages/api/src/schema.ts deleted file mode 100644 index b715272..0000000 --- a/packages/api/src/schema.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { index, integer, pgTable, text, uuid } from "drizzle-orm/pg-core"; - -export const cars = pgTable( - "cars", - { - id: uuid("id").defaultRandom().primaryKey(), - month: text("month"), - make: text("make"), - importer_type: text("importer_type"), - fuel_type: text("fuel_type"), - vehicle_type: text("vehicle_type"), - number: integer("number"), - }, - (table) => [ - index("month_make_idx").on(table.month, table.make), - index("month_idx").on(table.month), - index("make_idx").on(table.make), - index("fuel_type_idx").on(table.fuel_type), - index("make_fuel_type_idx").on(table.make, table.fuel_type), - index("number_idx").on(table.number), - ], -); - -export const coe = pgTable( - "coe", - { - id: uuid("id").defaultRandom().primaryKey(), - month: text("month"), - bidding_no: integer("bidding_no"), - vehicle_class: text("vehicle_class"), - quota: integer("quota"), - bids_success: integer("bids_success"), - bids_received: integer("bids_received"), - premium: integer("premium"), - }, - (table) => [ - index("month_vehicle_idx").on(table.month, table.vehicle_class), - index("vehicle_class_idx").on(table.vehicle_class), - index("month_bidding_no_idx").on(table.month, table.bidding_no), - index("premium_idx").on(table.premium), - index("bids_idx").on(table.bids_success, table.bids_received), - index("month_bidding_no_vehicle_class_idx").on( - table.month.desc(), - table.bidding_no.desc(), - table.vehicle_class, - ), - ], -); - -export type InsertCar = typeof cars.$inferInsert; -export type SelectCar = typeof cars.$inferSelect; - -export type InsertCOE = typeof coe.$inferInsert; -export type SelectCOE = typeof coe.$inferSelect; diff --git a/packages/api/src/v1/routes/cars.ts b/packages/api/src/v1/routes/cars.ts index c6232d9..ec21a21 100644 --- a/packages/api/src/v1/routes/cars.ts +++ b/packages/api/src/v1/routes/cars.ts @@ -4,13 +4,13 @@ import redis from "@/config/redis"; import { getLatestMonth } from "@/lib/getLatestMonth"; import { getUniqueMonths } from "@/lib/getUniqueMonths"; import { groupMonthsByYear } from "@/lib/groupMonthsByYear"; -import { cars } from "@/schema"; import { CarQuerySchema, MonthsQuerySchema } from "@/schemas"; import type { Make } from "@/types"; import getTrailingTwelveMonths from "@/utils/getTrailingTwelveMonths"; import { zValidator } from "@hono/zod-validator"; import { and, asc, between, desc, eq, ilike } from "drizzle-orm"; import { Hono } from "hono"; +import { cars } from "../../../../schema"; const app = new Hono(); diff --git a/packages/api/src/v1/routes/coe.ts b/packages/api/src/v1/routes/coe.ts index e98173b..d0d2bfa 100644 --- a/packages/api/src/v1/routes/coe.ts +++ b/packages/api/src/v1/routes/coe.ts @@ -4,11 +4,11 @@ import redis from "@/config/redis"; import { getLatestMonth } from "@/lib/getLatestMonth"; import { getUniqueMonths } from "@/lib/getUniqueMonths"; import { groupMonthsByYear } from "@/lib/groupMonthsByYear"; -import { coe } from "@/schema"; import { type COE, COEQuerySchema, MonthsQuerySchema } from "@/schemas"; import { zValidator } from "@hono/zod-validator"; import { and, asc, desc, eq, gte, lte } from "drizzle-orm"; import { Hono } from "hono"; +import { coe } from "../../../schema"; const app = new Hono(); diff --git a/packages/api/src/v1/routes/makes.ts b/packages/api/src/v1/routes/makes.ts index 02df94d..b09483f 100644 --- a/packages/api/src/v1/routes/makes.ts +++ b/packages/api/src/v1/routes/makes.ts @@ -1,11 +1,11 @@ import { CACHE_TTL } from "@/config"; import db from "@/config/db"; import redis from "@/config/redis"; -import { cars } from "@/schema"; import { MakeParamSchema, MakeQuerySchema } from "@/schemas"; import { zValidator } from "@hono/zod-validator"; import { and, asc, desc, eq, ilike } from "drizzle-orm"; import { Hono } from "hono"; +import { cars } from "../../../../schema"; const app = new Hono(); diff --git a/packages/api/src/v1/routes/months.ts b/packages/api/src/v1/routes/months.ts index 48adc45..dee9e4e 100644 --- a/packages/api/src/v1/routes/months.ts +++ b/packages/api/src/v1/routes/months.ts @@ -1,8 +1,8 @@ import { getLatestMonth } from "@/lib/getLatestMonth"; -import { cars, coe } from "@/schema"; import { LatestMonthQuerySchema } from "@/schemas"; import { zValidator } from "@hono/zod-validator"; import { Hono } from "hono"; +import { cars, coe } from "../../../../schema"; const app = new Hono(); diff --git a/packages/schema/package.json b/packages/schema/package.json index 70b15f4..b29cedc 100644 --- a/packages/schema/package.json +++ b/packages/schema/package.json @@ -1,15 +1,16 @@ { - "name": "@sgcarstrends/schema", - "version": "1.0.0-beta.1", - "description": "", - "private": true, - "dependencies": { - "dotenv": "^16.4.7", - "drizzle-orm": "^0.38.2" - }, - "devDependencies": { - "@biomejs/biome": "1.9.4", - "@types/node": "^22.10.2", - "drizzle-kit": "^0.30.1" - } + "name": "@sgcarstrends/schema", + "version": "1.0.0-beta.1", + "description": "", + "main": "src/schema.ts", + "private": true, + "dependencies": { + "dotenv": "^16.4.7", + "drizzle-orm": "^0.38.2" + }, + "devDependencies": { + "@biomejs/biome": "1.9.4", + "@types/node": "^22.10.2", + "drizzle-kit": "^0.30.1" + } }