I don't know how to use `index.getObjectByRef`

Everything I pass in returns nil.

For example: index.getObjectByRef('index', 'page', 'index') in my space, which I would think would get me my index page, returns nil. I think I know the difference between the page argument and the ref argument; in this case they look pretty similar since what I'm grabbing is a page vs. a link or whatnot. But every variation I've tried has returned nil and I can't find a working space lua example.

But my real use case is I'm trying build a haircut tracker, something that can answer, "How long has it been since I've had a haircut?" I want to solve this by adding a [[Haircut]] link in my daily journal, then creating a command I can run that counts the days since the last haircut link.

I could also do it by adding a page attribute, or something in the frontmatter, but adding the link is pretty seamless since I'm writing about my day already -- no need to drop into programmer-mode.

I'm pretty sure I know how to query for the link, but I want to turn the page of the link object into a real page. Once I have that I can check when the page was created and start doing fun date math to count the days.

Why don't you:

${query[[from o = index.objects("link") where o.destination == "haircut" order by o.page desc limit 1 select o.page]]}

Assuming you Journal page has the date in it, you only need extract the data from your journal pagename.

For me it returns a table?

${index.getObjectByRef("index", "page", "index")}

Gives me

That said, a query in lines of what @Mike is likely what you want to do. getObjectByRef is more of an internal API to the the quickest possible lookup of an object where you already know exactly on what page it appeared, the tag and ref, which is a rare occurence.

Okay, PEBKAC! In my main space, it returns nil. In my work space, it returns a table! That is a deeply weird thing that I'll shelve and figure out later. Seems like my main space is having issues with page names, or something? Every reasonable example I tried in my work space was just fine. Cool beans, I'm good.

As for parsing the date out of the title, I'd rather rely on a data attribute than a naming scheme, if possible -- my preference is for structured data, if it's available. But thanks for the suggestion!

Did some investigating, figured out that my personal space was running 2.5.2 and my work space was running 2.8.1. Updated my personal space to latest and the world makes sense again, I'm getting a table when looking for my index page by ref.

Thanks again, all!