@@ -84,6 +84,7 @@ class Postgres {
84
84
ALTER TABLE items ADD COLUMN IF NOT EXISTS floatid BIGINT;
85
85
ALTER TABLE items ADD COLUMN IF NOT EXISTS price INTEGER;
86
86
ALTER TABLE items ADD COLUMN IF NOT EXISTS listed_price INTEGER;
87
+ ALTER TABLE items ADD COLUMN IF NOT EXISTS keychains JSONB;
87
88
ALTER TABLE history ADD COLUMN IF NOT EXISTS price INTEGER;
88
89
89
90
-- Float ID is defined as the first asset id we've seen for an item
@@ -249,6 +250,35 @@ class Postgres {
249
250
}
250
251
}
251
252
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
+
252
282
const ms = item . s !== '0' ? item . s : item . m ;
253
283
const isStattrak = item . killeatervalue !== null ;
254
284
const isSouvenir = item . quality === 12 ;
@@ -266,7 +296,7 @@ class Postgres {
266
296
}
267
297
268
298
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 ] ) ;
270
300
}
271
301
272
302
if ( values . length === 0 ) {
@@ -286,13 +316,13 @@ class Postgres {
286
316
const values = [ ] ;
287
317
let i = 1 ;
288
318
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 )
290
320
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 ++ } )` ) ;
292
322
}
293
323
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()` ;
296
326
}
297
327
298
328
updateItemPrice ( assetId , price ) {
@@ -359,6 +389,22 @@ class Postgres {
359
389
}
360
390
} ) ;
361
391
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
+
362
408
item = Object . assign ( Postgres . extractProperties ( item . props ) , item ) ;
363
409
364
410
const buf = Buffer . alloc ( 4 ) ;
0 commit comments