@@ -84,6 +84,7 @@ class Postgres {
8484 ALTER TABLE items ADD COLUMN IF NOT EXISTS floatid BIGINT;
8585 ALTER TABLE items ADD COLUMN IF NOT EXISTS price INTEGER;
8686 ALTER TABLE items ADD COLUMN IF NOT EXISTS listed_price INTEGER;
87+ ALTER TABLE items ADD COLUMN IF NOT EXISTS keychains JSONB;
8788 ALTER TABLE history ADD COLUMN IF NOT EXISTS price INTEGER;
8889
8990 -- Float ID is defined as the first asset id we've seen for an item
@@ -249,6 +250,35 @@ class Postgres {
249250 }
250251 }
251252
253+ const keychains = item . keychains . length > 0 ? item . keychains . map ( ( s ) => {
254+ const res = { s : s . slot , i : s . sticker_id } ;
255+ if ( s . wear ) {
256+ res . w = s . wear ;
257+ }
258+ if ( s . scale ) {
259+ res . sc = s . scale ;
260+ }
261+ if ( s . rotation ) {
262+ res . r = s . rotation ;
263+ }
264+ if ( s . tint_id ) {
265+ res . t = s . tint_id ;
266+ }
267+ if ( s . offset_x ) {
268+ res . x = s . offset_x ;
269+ }
270+ if ( s . offset_y ) {
271+ res . y = s . offset_y ;
272+ }
273+ if ( s . offset_z ) {
274+ res . z = s . offset_z ;
275+ }
276+ if ( s . pattern ) {
277+ res . p = s . pattern ;
278+ }
279+ return res ;
280+ } ) : null ;
281+
252282 const ms = item . s !== '0' ? item . s : item . m ;
253283 const isStattrak = item . killeatervalue !== null ;
254284 const isSouvenir = item . quality === 12 ;
@@ -266,7 +296,7 @@ class Postgres {
266296 }
267297
268298 values . push ( [ ms , item . a , item . d , item . paintseed , item . paintwear , item . defindex , item . paintindex , isStattrak ,
269- isSouvenir , props , JSON . stringify ( stickers ) , item . rarity , price ] ) ;
299+ isSouvenir , props , JSON . stringify ( stickers ) , JSON . stringify ( keychains ) , item . rarity , price ] ) ;
270300 }
271301
272302 if ( values . length === 0 ) {
@@ -286,13 +316,13 @@ class Postgres {
286316 const values = [ ] ;
287317 let i = 1 ;
288318
289- // Builds binding pattern such as ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11::jsonb, now(), $12 , NULL, $13 )
319+ // Builds binding pattern such as ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11::jsonb, $12::jsonb, now(), $13 , NULL, $14 )
290320 for ( let c = 0 ; c < itemCount ; c ++ ) {
291- values . push ( `($${ i ++ } , $${ i ++ } , $${ i ++ } , $${ i ++ } , $${ i ++ } , $${ i ++ } , $${ i ++ } , $${ i ++ } , $${ i ++ } , $${ i ++ } , $${ i ++ } ::jsonb, now(), $${ i ++ } , NULL, $${ i ++ } )` ) ;
321+ values . push ( `($${ i ++ } , $${ i ++ } , $${ i ++ } , $${ i ++ } , $${ i ++ } , $${ i ++ } , $${ i ++ } , $${ i ++ } , $${ i ++ } , $${ i ++ } , $${ i ++ } ::jsonb, $ ${ i ++ } ::jsonb, now(), $${ i ++ } , NULL, $${ i ++ } )` ) ;
292322 }
293323
294- return `INSERT INTO items (ms, a, d, paintseed, paintwear, defindex, paintindex, stattrak, souvenir, props, stickers, updated, rarity, floatid, price)
295- VALUES ${ values . join ( ', ' ) } ON CONFLICT(defindex, paintindex, paintwear, paintseed) DO UPDATE SET ms=excluded.ms, a=excluded.a, d=excluded.d, stickers=excluded.stickers, updated=now()` ;
324+ return `INSERT INTO items (ms, a, d, paintseed, paintwear, defindex, paintindex, stattrak, souvenir, props, stickers, keychains, updated, rarity, floatid, price)
325+ VALUES ${ values . join ( ', ' ) } ON CONFLICT(defindex, paintindex, paintwear, paintseed) DO UPDATE SET ms=excluded.ms, a=excluded.a, d=excluded.d, stickers=excluded.stickers, keychains=excluded.keychains, updated=now()` ;
296326 }
297327
298328 updateItemPrice ( assetId , price ) {
@@ -359,6 +389,22 @@ class Postgres {
359389 }
360390 } ) ;
361391
392+ item . keychains = item . keychains || [ ] ;
393+ item . keychains = item . keychains . map ( ( s ) => {
394+ return {
395+ sticker_id : s . i ,
396+ slot : s . s ,
397+ wear : s . w ,
398+ scale : s . sc ,
399+ rotation : s . r ,
400+ tint_id : s . t ,
401+ offset_x : s . x ,
402+ offset_y : s . y ,
403+ offset_z : s . z ,
404+ pattern : s . p ,
405+ }
406+ } ) ;
407+
362408 item = Object . assign ( Postgres . extractProperties ( item . props ) , item ) ;
363409
364410 const buf = Buffer . alloc ( 4 ) ;
0 commit comments