Skip to content

Insert dictionary #533

@jly36963

Description

@jly36963

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',
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions