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

Dynamic sets #356

Merged
merged 8 commits into from
Sep 13, 2023
Merged

Dynamic sets #356

merged 8 commits into from
Sep 13, 2023

Conversation

g105b
Copy link
Member

@g105b g105b commented Aug 15, 2023

This PR closes #355 and #347 - but before it will be merged, it will be tested in a live application.

@g105b
Copy link
Member Author

g105b commented Aug 15, 2023

Well, the database usage works well - inserting 20,000 rows in a single transaction is SO fast compared to doing each insert individually!

@g105b
Copy link
Member Author

g105b commented Aug 18, 2023

I need to introduce a new dynamic set type: "or" sets.

Example:

select
    id,
    artistId,
    title,
    type
from
    Product
where
(
    (title = 'Product A' and artistId = 'Artist 1') or
    (title = 'Product B' and artistId = 'Artist 1') or
    (title = 'Product C' and artistId = 'Artist 2')
)

This example is similar to where ... in but allows for multi-field matching.

@g105b
Copy link
Member Author

g105b commented Aug 18, 2023

Potential bug. I don't know for sure whether it's the responsibility of the dynamic sets to fix, but here's what I've found.

In my application, I'm using array_diff on a list of data and existing data from the database, so I can get an array full of only the new records that need inserting.

Because array_diff preserves keys, the data I end up passing to the __dynamicValueSet has keys that aren't sequential, which seems to mess things up. I can fix it by passing array_values($myData), but should the dynamic value setting normalise this on my behalf?

@g105b
Copy link
Member Author

g105b commented Aug 18, 2023

Something else to chew over...

insert into Product (
  id,
  artistId,
  title
)
values ( :__dynamicValueSet )

The contents of dynamicValueSet is dynamic (well, durr). In my application, I'm building it up within a loop, and the ID is the last thing I set, meaning that the columns are no longer in the same order as how they're written in the SQL.

The SQL's column order needs to match the order of the indices in the associative arrays, otherwise bad things will happen.

I'm not sure how to solve this. Is there another insert syntax to use where each field can be set individually, or is it an OK problem to have>

@g105b g105b merged commit ceac0a6 into master Sep 13, 2023
12 of 15 checks passed
@g105b g105b deleted the dynamic-sets branch September 13, 2023 13:45
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.

Dynamic insert multiple
1 participant