Catmandu::Fix::add_to_store - add matching values to a store as a side effect
# Add the current record to an SQLite database. add_to_store(., DBI, data_source: "dbi:SQLite:path/data.sqlite") # Add the journal field to a MongoDB database. add_to_store(journal, MongoDB, database_name: catalog) # Add all author values to a MongoDB database. add_to_store(authors.*, MongoDB, database_name: catalog, bag: authors) # Or, a much faster option: use a named store in a catmandu.yml file # # store: # mydbi: # package: DBI # options: # data_source: "dbi:SQLite:path/data.sqlite" # mymongo: # package: MongoDB # options: # database_name: catalog add_to_store(., mydbi) add_to_store(journal, mymongo) add_to_store(authors.*, mymongo, bag: authors)
Store a record or parts of a record in a Catmandu::Store. The values at the PATH will be stored as-is in the database but should be hashes. If the value contains an '_id' field, then it will used as record identifier in the database. If not, then a new '_id' field will be generated and added to the database and original field (for later reference).
For instance this YAML input:
--- _id: 001 title: test name: foo --- _id: 002 title: test2 name: bar
with the fix:
add_to_store(., DBI, data_source: "dbi:SQLite:path/data.sqlite")
will create a path/data.sqlite SQLite database with two records. Each records contains the _id from the input file and all the record fields.
--- title: test name: foo --- title: test2 name: bar
will create a path/data.sqlite SQLite database with two records. Each records contains the a generated _id and all the record fields. The current input stream will be updated to contain the generated _id.
Use Catmandu::Fix::lookup_in_store to lookup records in a Catmandu::Store based on an '_id' key.
For every call to a add_to_store a new database connection is created. It is much more effient to used named stores in a catmandu.yml file. This file needs to contain all the connection parameters to the database. E.g.
add_to_store
catmandu.yml
store: mystore: package: MongoDB options: database_name: mydata
The catmandu.yml file should be available in the same directory as where the catmandu command is executed. Or, this directory can be set with the -L option:
catmandu
-L
$ catmandu -L /tmp/path convert ...
Catmandu::Fix , Catmandu::Fix::lookup_in_store
To install Catmandu, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catmandu
CPAN shell
perl -MCPAN -e shell install Catmandu
For more information on module installation, please visit the detailed CPAN module installation guide.