Closed pbrink231 closed 6 years ago
You can create rule for your table, like this:
CREATE RULE shops_on_duplicate_ignore AS ON INSERT TO shops WHERE EXISTS ( SELECT 1 FROM shops WHERE shopify_domain=NEW.shopify_domain ) DO INSTEAD NOTHING;
and use simple INSERT
I ended up creating a custom strategy which took me down a whole road. The documentation needs to be updated since the strategy now returns a formula instead of a value. Also can show this example since you cant find one anywhere. Its strange because my node module is different than the code here?
My version: "@shopify/shopify-express": "^1.0.0-alpha.7"
This is the strategy that ended up working:
class SequelizeStrategy {
async getShop({ shop }) {
console.log('check domain', shop)
let foundShop = await db.Shop.find({
where: {
shopify_domain: shop
}
})
.catch(err => {
console.log('get shop error', err)
})
return done(null, {accessToken: foundShop.access_token});
}
async storeShop({ shop, accessToken }, done) {
let storedShop = await db.Shop.find({
where: {
shopify_domain: shop
}
})
.then(foundShop => {
if (foundShop) {
foundShop.access_token = accessToken
foundShop.save()
return foundShop;
} else {
return db.Shop.create({ shopify_domain: shop, access_token: accessToken })
}
})
.catch(err => {
console.log('store shop error happened', err);
return done(err);
})
console.log('stored shop', {accessToken})
return done(null, accessToken);
}
}
@pbrink231 yes, npm package 1.0.0-alpha.7 is currently 15 commits behind the master branch.
ok understand. Thank you.
I have setup knex config to work with postgres:
But the query when a new store is connecting is failing because
INSERT OR IGNORE
is not compatible withpostgres
: