Catman..._store(3pm)
π¦ Catmandu::Fix::lookup_in_store β the Catman..._store(3pm) page, bestie edition
okay so welcome to the manual page for Catmandu::Fix::lookup_in_store, from the User Contributed Perl Documentation β¨ (yes it's a 3pm page, yes we're thriving).
What does it do? It changes the value of a HASH key or ARRAY index by looking up its value in a store. That's it. That's the whole gig. π
β¨ SYNOPSIS β¨
# Lookup in an SQLLite database
lookup_in_store(foo.bar, DBI, data_source: "dbi:SQLite:path/data.sqlite")
# Lookup in a MongoDB database
lookup_in_store(foo.bar, MongoDB, database_name: lookups, bag: mydata)
# Lookup in a MongoDB database, using the default bag and a default value when nothing found
lookup_in_store(foo.bar, MongoDB, database_name: lookups, default: 'default value')
# Lookup in a MongoDB database, using the default bag and delete the foo.bar field when nothing found
lookup_in_store(foo.bar, MongoDB, database_name: lookups, delete: 1)
# 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: lookups
lookup_in_store(foo.bar, mydbi)
lookup_in_store(foo.bar, mymongo, bag: mydata)
lookup_in_store(foo.bar, mymongo, default: 'default value')
lookup_in_store(foo.bar, mymongo, delete: 1)
likeβ¦ the named-store version is giving main character energy for real, that last block is the one you want π«Ά
π DESCRIPTION π
lookup_in_store(PATH,STORE[,store_param: store_val, ...][,bag: bag_name][,delete:1][,default:value])
so here's the tea π β you use the lookup_in_store fix to match a field in a record to the "_id" field in a Catmandu::Store of choice.
say your Catmandu::Store is holding these records:
---
_id: water
fr: l'eau
de: wasser
en: water
nl: water
---
_id: tree
fr: arbre
de: baum
en: tree
nl: boom
and your data has these fields:
---
_id: 001
tag: tree
---
_id: 002
tag: water
then this fix right here will look up a tag in the Catmandu::Store and swap it out for the database value:
lookup_in_store(tag, DBI, data_source: "dbi:SQLite:path/data.sqlite")
and boom π₯ the resulting data will contain:
---
_id: 001
tag:
_id: tree
fr: arbre
de: baum
en: tree
nl: boom
---
_id: 002
tag:
_id: water
fr: l'eau
de: wasser
en: water
nl: water
not the tag field going from a lil string to a whole entire nested hash. glow up, honestly β¨π
π DATABASE CONNECTIONS π
okay important one, listen up bestie π
for every call to a lookup_in_store, a new database connection is created. that's a lot. it is much more efficient to use named stores in a catmandu.yml file π
this file needs to contain all the connection parameters to the database. e.g.
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 /tmp/path convert ...
so yeah β one connection per call = π, named stores = ππΈ
π SEE ALSO π
Catmandu::FixCatmandu::StoreCatmandu::Fix::add_to_store
no cap, the whole point of this page is: look stuff up in a store, and please use named stores so you're not opening a fresh connection every single time π
and that's the page!! this was perl v5.40.1 realness, dated 2026-01-24, delivered with love ππ§ββοΈ periodt.
π¦ where this page comes from
- ubuntu resolute: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatmandu-perl 1.2025-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms