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

Insert dictionary #533

Open
jly36963 opened this issue Dec 20, 2020 · 0 comments
Open

Insert dictionary #533

jly36963 opened this issue Dec 20, 2020 · 0 comments

Comments

@jly36963
Copy link

I wish their was a built-in way to insert dictionaries.

This is what I wish existed

from pypika import Query, Table

users = Table('users')

Query.into(users).insert_dict({
    'first_name': 'John',
    'last_name': 'Doe',
})

This is what I'm currently doing:

@classmethod
def insert_dict(self, table, d): return (
    self
    .into(table)
    .columns(*d.keys())
    .insert(*d.values())
)

Query.insert_dict = insert_dict

Query.insert_dict(users, {
    'first_name': 'John',
    'last_name': 'Doe',
})
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