Emitter class reference¶
This document covers features of the BaseEmitter
class. Currently the system
has two emitter CSVEmitter
and MySQLEmitter
implemented, of which the last is the default emitter.
An emitter provides the export format for the scanned and cleaned datasets. It also provides preambles in
the output files, for example to clean the target table before loading it.
The basic structure for emitting is a combination between manager
and emitter
:
e = Emitter(manager=Model.objects)
print e.preamble(header=[..my header lines to add..])
for l in Model.objects.all():
print e.emit(l) # emit is returning a list of strings!
Note
At this moment data-migrator
is not an active part in schema migrations of any sort. It is purely about
cleaning and transforming data (yet!).
MySQLEmitter¶
-
class
data_migrator.emitters.mysql.
MySQLEmitter
(*args, **kwargs)¶ MySQL emitter to output MySQL specific insert statements
-
base_template
¶ base template to output the object
-
extension
¶ str – file extension for output file of this emitter
-
emit
(l)¶ Output the result set of an object as MYSQL insert statement
-
preamble
(headers)¶ override the preamble method to make it specific for MySQL
-
CSVEmitter¶
BaseEmitter¶
-
class
data_migrator.emitters.base.
BaseEmitter
(extension=None, manager=None)¶ Base for emitters of the data_migrator.
-
manager
¶ BaseManager – reference to the manager that is calling this emitter to export objects from that manager
-
model_class
¶ Model – reference to the model linked to the class
-
extension
¶ str – file extension for output file of this emitter
note:
model_class
andmanager
are linked together-
emit
(o)¶ output the result set of an object.
Parameters: o (Model) – object to transform Returns: generated strings Return type: list
-
filename
()¶ generate filename for this emitter.
generates a filename bases on
BaseEmitter.extension
and eitherfile_name
ortable_name
Returns: filename Return type: str
-
preamble
(headers)¶ generate a premable for the file to emit.
Parameters: headers (list) – additional header to provide outside the emitter (e.g. statistics) Returns: preamble lines Return type: list
-