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

Add DuckDB Connection #46

Merged
merged 6 commits into from
Aug 27, 2024
Merged

Add DuckDB Connection #46

merged 6 commits into from
Aug 27, 2024

Conversation

caleb-mabry
Copy link
Contributor

Purpose

This PR is meant to add support for the DuckDB connection.
https://duckdb.org/docs/api/nodejs/overview.html

Using Just a Query

    const connection = new DuckDBConnection('md:my_shared_db', {
        'motherduck_token': 'YOUR_TOKEN_HERE'
    })
    const response = await connection.query({query: 'select * from movies limit 5'})
    console.log('The data:', response.data)
    console.log('The error:', response.error.message)

Using Parameters

    const connection = new DuckDBConnection('md:my_shared_db', {
        'motherduck_token': 'YOUR_TOKEN_HERE'
    })
    const response = await connection.query({query: 'SELECT ?::INTEGER AS fortytwo', parameters: [52]})
    console.log('The data:', response.data)
    console.log('The error:', response.error.message)

Tasks

  • [ ]

Verify

Before

After

Copy link
Member

@Brayden Brayden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of comments, overall this is looking great! Excited to have DuckDB support 🫡

duckDB: duckDB.Database | undefined

constructor(
path: string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently in other connections we have the constructor just take an object instead of multiple parameters. This allows any connection to have a predictable pattern. I'd say we should probably lean in that direction here as well unless we have a good reason not to and then I'd remain open-minded.

return {
data: result,
error: null,
query: query.query,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This response is intended to be the absolute raw query so users can debug what was executed against their database, so change to:

const rawSQL = constructRawQuery(query)
// ...

return {
    data: result,
    error: null,
    query: rawSQL
}

return {
data: null,
error: error,
query: query.query,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@caleb-mabry caleb-mabry merged commit 1e43c05 into main Aug 27, 2024
1 check failed
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

Successfully merging this pull request may close these issues.

2 participants