On 20 Aug 2009, at 00:49, Gary Yngve wrote:

> Instead of doing something like:
> 100.times{|i| Thing.create(:name=>i}
>
> I want to do something like:
> Thing.create_many((0...100).map{|i| {:name=>i})
>
> DataObjects's create accepts an array of resources, but  
> unfortunately does each one as a separate create.
> Three reasons may be:
> - resources not all being of the same model (table)
> - error / validation concerns
> - size limitations of the INSERT statement
>
> It seems relatively simple to do something like this, so I'm  
> surprised it hasn't been done before.
> Has it been done, or is there a gotcha I'm waiting to discover?

Well, the reason is actually very simple... Most RDBMS don't provide a  
mass insert option and it's certainly not standardized with SQL.

For MySQL there is the multiple tuples for VALUES method, for  
PostgreSQL there is the COPY FROM which loads data from CSV. For most  
RBDMS the best approach would be to use prepared statement, this is a  
good option that works for almost all databases.

Bottom line probably is that there is more in the database world than  
just MySQL ;).

-- 
Regards,

Dirkjan

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to