-
Notifications
You must be signed in to change notification settings - Fork 617
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
return the ids from a bulk insert [postgres only] #104
Conversation
@robmathews, thanks for the PR. I didn't know PostgreSQL had such a cool feature! This has me thinking of how to get this to work with MySQL and SQLite. |
SQLite is easy, as you can be certain that there are no parallelism For MySQL you can append ";SELECT LAST_INSERT_ID()" to the end of the SET @countTotal = (SELECT COUNT(*) FROM nGrams); For other versions, this would work: enter a transaction. Now, you wont be able to see any rows from any other
Easy enough, actually. |
lol, ignore that random paste in the middle of the answer ;) On Thu, Jul 4, 2013 at 11:17 AM, Robert Mathews <
|
poke |
👍 to get this merged in |
- rename a few variables (obj => model, val => parent) for example - set the foreign key on a sub-collection when the parent is imported - tests for importing 3 levels of objects - remove extra recursion in add_objects - new model for testing 3 levels of objects: chapter
+1 |
You can try using this fork in the meantime: It efficiently bulk loads multiple levels of objects, ie, not just the top On Fri, Sep 6, 2013 at 4:57 AM, Richard Huang notifications@github.comwrote:
|
@robmathews already used your fork, works perfect, thanks for your contrib |
@robmathews @zdennis pointed me to this PR. Looks pretty sweet. Couple questions: Where does your code handle the multilevel import? Or is there an example I can mimic somewhere? And why did GoodMeasuresLLC@6364198#diff-8b155a870c20b622968f2d2480ea2379R63 change to |
of course it does multi level. really, the kids these days.... Typos courtesy of my iPhone
|
goodmeasures and me are the same organization. that is, i wrote it and had john @ goodmeasures finish debugging it. so i would tend to trust the goodmeasures version more. Typos courtesy of my iPhone
|
For an example, there is this test: https://github.com/GoodMeasuresLLC/activerecord-import/blob/master/test/import_test.rb#L350 Thats a multi-level test |
@robmathews Sorry for the confusion on the multilevel import. I was curious how you implemented that feature and missed the commit that added the nested capability. I see it now. Nifty tricks you do there. @johnnaegle Thanks for the link. That's exactly what I needed. To any future searchers: As far as I'm not exactly sure how that module is included in the tl;dr: |
@robmathews I just ran into this error The relevant backtrace
What is that proxy thing? Can you help me here? 😄 |
try the goodmeasures llc fork On Mon, Feb 17, 2014 at 3:11 AM, Bruno Azisaka notifications@github.comwrote:
|
@robmathews That's what I did. The fork is not working.
|
If someone can get this PR merge-able and add a test for postgres I'll merge this in. |
Ok Bruno. I'm on vacation this week, so I can't take a look at it until On Mon, Feb 17, 2014 at 9:59 AM, Zach Dennis notifications@github.comwrote:
|
@robmathews I tried using your fork https://github.com/GoodMeasuresLLC/activerecord-import but |
done - thanks On Wed, Apr 9, 2014 at 7:39 AM, bogdan notifications@github.com wrote:
|
|
||
models = args.first # the import argument parsing is too tangled for me ... I only want to prove the concept of saving recursively | ||
result = import_helper(models, options) | ||
# now, for all the dirty associations, collect them into a new set of models, then recurse. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RE #146, This is where autosave associations also get imported.
@zdennis I have just one question. Problem i think is that you're using the column_names of that model to collect the his attributes, but this doesn't contain also the virtual ones. I am not sure if this could be fixed, but will really be nice if we could validate also this attributes. |
This is an excellent PR, will this be merged? |
@alainmeier, it will become much more likely if it's become merge-able and stays green. |
I've rebased the commits onto the latest master and got the tests working under mysql, postgresql and sqlite3. The branch is here: https://github.com/GoodMeasuresLLC/activerecord-import/tree/set_ids_in_bulk_import. I will open a PR from that branch when I think it is ready, but some early feedback would be helpful. |
See #178 |
Why don't you close? it seems to be resolved for me. |
Thanks for following up @koheisg, closing now. |
A common request is to return the ids from the newly created object. This patch does that. It's postgres only, but at least it doesn't break for non-postgres databases - it just doesn't set the id.
The api is unchanged. Instead, for every model that was saved, it sets the :id and marks the record clean, so that you can keep using it if you want.
Seems like one could pretty easily do a BFS on the changed associations and bulk-import the next level down in the tree in one sql statement as well .. at least for postgres.
Let me know if this is any use to you; works fine for us, and that's all I need.