Skip to content

Alternative query building suggestion #375

Open

Description

@jtheisen

Hi folks, this isn't a bug report but something the authors of node-sql may find useful.

I spent the last couple of weeks researching ways to get a good query syntax in TypeScript working - before I found this library.

I now have a proof of concept and a readme explaining what I found. In particular, there's a way to write queries like this:

processQuery(query(() => {
    const orderNoWithInvoiceCount = query(() => {
        const i = from(invoices);
        groupBy(i.orderNo);
        return { orderNo: i.orderNo, numberOfInvoices: count() }
    })
    const { orderNo, numberOfInvoices } = from(orderNoWithInvoiceCount)
    const latestInvoice = outerApply(query(() => {
        const i2 = from(invoices)
        where(i2.orderNo.eq(orderNo))
        orderByDesc(i2.createdAt)
        fetchOnly(1)
        return i2
    }))

    return { orderNo, numberOfInvoices, latestInvoice };
}))

So this ticket really is just an ad for a sort of blog post, but I the information is interesting for anyone involved with SQL query builders.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions