Catman..._store(3pm)

πŸ“¦
version 1.2025 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

πŸ¦‹ 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::Fix
  • Catmandu::Store
  • Catmandu::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