Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative query building suggestion #375

Open
jtheisen opened this issue Sep 4, 2017 · 0 comments
Open

Alternative query building suggestion #375

jtheisen opened this issue Sep 4, 2017 · 0 comments

Comments

@jtheisen
Copy link

jtheisen commented Sep 4, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant