Advertisement
sandervspl

Untitled

Nov 21st, 2023
1,134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { sql } from 'drizzle-orm';
  2. import { text, integer, sqliteTable, unique, index } from 'drizzle-orm/sqlite-core';
  3. import { createInsertSchema } from 'drizzle-zod';
  4.  
  5. export const items = sqliteTable(
  6.   'items',
  7.   {
  8.     id: text('id').notNull().primaryKey(),
  9.     shortid: integer('shortid').notNull(),
  10.     name: text('name').notNull(),
  11.     sellPrice: integer('SellPrice').notNull(),
  12.     stackCount: integer('StackCount').notNull(),
  13.     classId: integer('ClassID').notNull(),
  14.     subclassId: integer('SubClassID').notNull(),
  15.     rarity: integer('Rarity').notNull(),
  16.     minLevel: integer('MinLevel').notNull(),
  17.     link: text('Link').notNull(),
  18.     olink: text('OLink').notNull(),
  19.     timestamp: text('ts').default(sql`CURRENT_TIMESTAMP`),
  20.   },
  21.   (table) => ({
  22.     shortidunq: unique('shortidunq').on(table.shortid),
  23.     nameidx: index('nameidx').on(table.name),
  24.     rarityidx: index('rarityidx').on(table.rarity),
  25.     sellpriceidx: index('sellpriceidx').on(table.sellPrice),
  26.   }),
  27. );
  28.  
  29. export const insertItemsSchema = createInsertSchema(items);
  30.  
  31. export const scanmeta = sqliteTable(
  32.   'scanmeta',
  33.   {
  34.     id: integer('id').primaryKey({ autoIncrement: true }),
  35.     realm: text('realm').notNull(),
  36.     faction: text('faction', { enum: ['Neutral', 'Alliance', 'Horde'] }).notNull(),
  37.     scanner: text('scanner').notNull(),
  38.     timestamp: text('ts').default(sql`CURRENT_TIMESTAMP`),
  39.   },
  40.   (table) => ({
  41.     unique_scan: unique('unique_scan').on(table.timestamp, table.scanner),
  42.   }),
  43. );
  44.  
  45. export const insertScanmetaSchema = createInsertSchema(scanmeta);
  46.  
  47. export const auctions = sqliteTable(
  48.   'auctions',
  49.   {
  50.     scanId: integer('scanId')
  51.       .notNull()
  52.       .references(() => scanmeta.id),
  53.     itemId: text('itemId')
  54.       .notNull()
  55.       .references(() => items.id),
  56.     timestamp: text('ts').default(sql`CURRENT_TIMESTAMP`),
  57.     seller: text('seller').notNull(),
  58.     timeLeft: integer('timeLeft').notNull(),
  59.     itemCount: integer('itemCount').notNull(),
  60.     minBid: integer('minBid').notNull(),
  61.     buyout: integer('buyout').notNull(),
  62.     curBid: integer('curBid').notNull(),
  63.   },
  64.   (table) => ({
  65.     buyoutidx: index('buyoutidx').on(table.buyout),
  66.     itemididx: index('itemididx').on(table.itemId),
  67.   }),
  68. );
  69.  
  70. export const insertAuctionsSchema = createInsertSchema(auctions);
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement