Login

Tag "insert"

Snippet List

Bulk Insert Manager

This is a small manager that just adds a "bulk_insert" function. This is very basic, I'm basically throwing it up here because it's simple and works for my current needs. Feedback on improvements (which I know would be a ton) are very welcome. Some known "gotchas": 1. This doesn't handle relationships. If, however, you want to do one-to-one or foreignkeys you'll have to use the actual table column name ('whatever_id' typically) 2. When using this I typically make a bulk_insert call every 500 iterations or so Some improvements that I think could be good: 1. Possibly just find the fields from the first object in the objs array and leave the fields argument as optional 2. Create a bulk_insert_from_file function and use LOAD DATA INFILE for mysql and whatever else supports it

  • manager
  • bulk
  • insert
  • bulk-insert
Read More

Restructuredtext directive for photolouge

Directive for inserting images using photolouge in django. Usage: Just make a .py with this code and import it in some apps models.py Or make a custom formatter with django-template-utils.

  • image
  • insert
  • rst
  • directive
  • photolouge
Read More

Bulk Insert - updated 5/9/2008

This Update adds requested support for self referential fields. This is useful if you need to compute and store potentially hundreds or thousands of objects and relationships quickly. To perform the inserts it will hit the database 1 plus N/100 times per affected table and where N is the number of rows to be inserted. It will use INSERT or LOAD DATA INFILE on MySQL. Run this on your test database first and make sure all of your field defaults and null values are set appropriately as you could attempt to insert a NULL where it isn't allowed and end up with a partial insert. This code is reasonably well tested and has been used for database pre-loading and operations on live sites. My test suite, however, is focused on my own use cases. Any input, i.e. failures, for creating more tests would be appreciated. Lots of Details in the Doc String. Currently only MySQL, however there is some crude skeleton code to support other databases.

  • mysql
  • bulk
  • insert
  • load-data
Read More

3 snippets posted so far.