import {MasterTableType, JoinedTablesType} from 'nodejs-express-utils';
import database from '../core/database';
import ContactUs from '../models/ContactUs';
import Person from '../models/Person';

const masterTable: MasterTableType = {
    table: ContactUs,
    tableAlias: 'c',
    columnsAlias: {userUid: 'uid'},
    reqColumns: ['id', 'userUid', 'subject'],

const tables: JoinedTablesType = [
        table: Person,
        tableAlias: 'p',
        joinType: JOIN_TYPES.LEFT_OUTER,
        joinCondition: 'p.uid=c.userUid',

const extraQuery = 'WHERE timestamp=:timestamp';
const params = {timestamp: 1632049210};

const customFields = ['COUNT(P.postId) AS COUNT']

    .executeJoin(masterTable, tables, extraQuery, params, customFields)
    .then((res) => console.log('res', res))
    .catch((err) => console.error('err', err));
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter