Skip to content
This repository was archived by the owner on Apr 26, 2023. It is now read-only.

Sqlite flat mapper

Pablo Conesa edited this page May 12, 2016 · 9 revisions




SqliteFlatMapper

It is a class which main responsibility is to persist/retrieve "sets" or any homogeneous collection of objects in an optimal manner.

Objects to store

In general any big list/collection with homogeneous content is a good candidate to be used with the flat mapper. SetOfParticles, SetOfClasses, SetOfVolumes, and any class that inherits form Set ( at pyworkflow.object.py) is a good candidate to be persisted with the flat mapper.

Any other big, homogeneous list, even if it doesn't extends Set, will work for the flat mapper.

Example

Let's start with an example and follow the complete process. Let's take SetOfParticles which is basically a list of Particle objects.

Each of the particles in the set has the same 13 attributes:

  • id
  • enabled
  • _index
  • _filename
  • label
  • comment
  • _samplingRate
  • _acquisition._magnification
  • ....

For the sake of simplicity we will take into account only those attributes mentioned above, ignoring the rest.

Therefore, let's assume we have in our code something like this:

persistSetOfParticles(mySetOfLegoParticles)

def persistSetOfParticles(setOfParticles):

   pass

Persisting process

Mapper creation

First thing to use the flat mapper is to instantiate it.

persistSetOfParticles(mySetOfLegoParticles)

def persistSetOfParticles(setOfParticles):

   flatMapper = SqliteFlatMapper('legoparticles.sqlite', globals())
Clone this wiki locally