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

simple insert_dict() builder #725

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

simple insert_dict() builder #725

wants to merge 4 commits into from

Conversation

edvardm
Copy link

@edvardm edvardm commented Apr 18, 2023

Additions

  • add helper insert_dict() for QueryBuilder instances
  • guard to prevent use of columns() while using insert_dict()
  • basic tests

Idea pretty much the same as in issue #533 :

Query().into(self.table_abc).insert_dict({"num": 1, "timestamp": datetime(2023, 4, 18)})

# INSERT INTO "abc" ("num","timestamp") VALUES (1,'2023-04-18T00:00:00')

Given how it's implemented, maybe from_dict() would be more suitable, as into() is already part of context? Multi-value inserts are trickier though, as they seem to vary between engines


Edit:

  • Simple example in README
  • Just use class method Query.into in tests

@edvardm edvardm requested a review from a team as a code owner April 18, 2023 16:19
Copy link
Contributor

@wd60622 wd60622 left a comment

Choose a reason for hiding this comment

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

Able to add this into the README in order to document?

pypika/tests/test_inserts.py Outdated Show resolved Hide resolved
pypika/tests/test_inserts.py Outdated Show resolved Hide resolved
@edvardm edvardm force-pushed the master branch 2 times, most recently from 1761de8 to 9480180 Compare February 26, 2024 14:05
in SQL builders, order of calling individual functions should
not matter. Originally it was allowed to first call columns()
and then insert_dict as long as the two matched, but I'm not even sure
it worked, as we should have used set comparison instead.

It is also better to have symmetric API in
pypika/utils.py Outdated Show resolved Hide resolved
@edvardm
Copy link
Author

edvardm commented Mar 11, 2024

Sorry for the delay, some quite tragic happened at work and forgot about this for some time. Hopefully resolved noted issues

@edvardm edvardm requested a review from wd60622 March 11, 2024 15:18
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.

None yet

2 participants