Instantly share code, notes, and snippets.
Created Nov 18, 2020
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const includeTags = (ids) => `exists ( | |
select * | |
from jobtag jt | |
where jt.job_id = job.id | |
and shop_tag_id in (${ids}) | |
group by job_id | |
having count(*) >= ${ids.length} | |
)`; | |
const excludeTags = (ids) => `not exists( | |
select * | |
from jobtag jt | |
where jt.job_id = job.id | |
and shop_tag_id in (${ids}) | |
)`; | |
const includeTaxes = (ids) => `exists(select * | |
from jobtax jt | |
where jt.job_id = job.id | |
and jt.shop_tax_id in (${ids}) | |
group by job_id | |
having count(*) >= ${ids.length} | |
)`; | |
const excludeTaxes = (ids) => `not exists(select * | |
from jobtax jt | |
where jt.job_id = job.id | |
and jt.shop_tax_id in (${ids}) | |
)`; | |
const include_tags = [4646]; | |
const exclude_tags = [4648]; | |
const include_taxes = [3029, 3030]; | |
const exclude_taxes = [3028]; | |
Logger.Info( | |
await GbOrm.job.findAll({ | |
attributes: ['id'], | |
limit: 100, | |
where: { | |
includeTags: literal(includeTags(include_tags)), | |
excludeTags: literal(excludeTags(exclude_tags)), | |
includeTaxes: literal(includeTaxes(include_taxes)), | |
excludeTaxes: literal(excludeTaxes(exclude_taxes)), | |
shop_id: 1013, | |
}, | |
}), | |
true, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment