ip.sql.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { mysqlTable, int, primaryKey, varchar } from "drizzle-orm/mysql-core"
  2. import { timestamps } from "../drizzle/types"
  3. export const IpTable = mysqlTable(
  4. "ip",
  5. {
  6. ip: varchar("ip", { length: 45 }).notNull(),
  7. ...timestamps,
  8. usage: int("usage"),
  9. },
  10. (table) => [primaryKey({ columns: [table.ip] })],
  11. )
  12. export const IpRateLimitTable = mysqlTable(
  13. "ip_rate_limit",
  14. {
  15. ip: varchar("ip", { length: 45 }).notNull(),
  16. interval: varchar("interval", { length: 10 }).notNull(),
  17. count: int("count").notNull(),
  18. },
  19. (table) => [primaryKey({ columns: [table.ip, table.interval] })],
  20. )
  21. export const KeyRateLimitTable = mysqlTable(
  22. "key_rate_limit",
  23. {
  24. key: varchar("key", { length: 255 }).notNull(),
  25. interval: varchar("interval", { length: 40 }).notNull(),
  26. count: int("count").notNull(),
  27. },
  28. (table) => [primaryKey({ columns: [table.key, table.interval] })],
  29. )
  30. export const ModelRateLimitTable = mysqlTable(
  31. "model_rate_limit",
  32. {
  33. key: varchar("key", { length: 255 }).notNull(),
  34. interval: varchar("interval", { length: 40 }).notNull(),
  35. count: int("count").notNull(),
  36. },
  37. (table) => [primaryKey({ columns: [table.key, table.interval] })],
  38. )