'use strict'; const knex = require('./knex'); async function matchTags(rawTags) { const tagEntries = await knex('tags') .pluck('aliases.id') .whereIn('tags.name', rawTags.map(tag => tag.toLowerCase())) .where(function where() { this .whereNull('tags.alias_for') .orWhereNull('aliases.alias_for'); }) .join('tags as aliases', function join() { this .on('tags.alias_for', 'aliases.id') .orOn('tags.id', 'aliases.id'); }) .groupBy('aliases.id'); return tagEntries; } module.exports = { matchTags };