You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'use strict';letObjection=require('objection');classKVextendsObjection.Model{// Table name is the only required property.statictableName='kv';staticgetjsonAttributes(){return['json'];}}module.exports=KV;
src/lib/store.js:
'use strict';letVerificationCodeModel=require('./src/models/verification_code.js');letVerifications=module.exports;Verifications.get=asyncfunction(id){letdata=awaitVerificationCodeModel.query().findById(id);if(!data){returnnull;}//@ts-ignoreletresult=data.json;/** type import('auth3000').Verification */returnresult;};/** * @param {string} id * @param {import('auth3000').Verification} value */Verifications.set=asyncfunction(id,json){//@ts-ignoreletupdated=awaitVerificationCodeModel.query().insert({ id, json }).onConflict().merge();};
test.js:
#!/usr/bin/env node
'use strict';require('dotenv').config();require('./setup.js');// load the ORMletStore=require('./src/lib/kv.js');letVCModel=require('./src/models/kv.js');asyncfunctionmain(){letr0=awaitStore.get('foo');if(r0){console.log("Warn: previous test did not delete 'foo':",r0);}letrnd=Math.random().toString().replace('0.','');awaitStore.set('foo',{banana: 'gram',[rnd]: true,rnd: rnd});letr2=awaitStore.get('foo');if(!r2[rnd]||r2.rnd!==rnd){thrownewError('did not save arbitrary JSON correctly');}letnum=awaitVCModel.query().deleteById('foo');if(1!==num){if(num>1){thrownewError('deleted',num,'values... oops');}else{thrownewError("didn't delete anything");}}}main().then(function(){console.log('PASS');process.exit(0);}).catch(function(err){console.error(err.stack);console.error('FAIL');process.exit(1);});
Need to put this somewhere as an example.
db/migrations/<yyyy><mm><dd><hh><mm><ss>_kv.js
:src/models/kv.js
:src/lib/store.js
:test.js
:setup.js
:The text was updated successfully, but these errors were encountered: