question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Single object lookup by unique key

See original GitHub issue

It would be useful if we could lookup single objects by their unique fields other than the primary key.

user_by_email(email: "an@example.org") { id email }

For composed unique fields it could be something along the lines of

order_by_user_id_and_invoice_id(user_id: 1, invoice_id: 1) { id email }

I presume we could automatically get this functionality based on the unique indexes in postgresql. It is a bit nicer than with the where clause when we know there will only be a single item.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:60
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

20reactions
gsnunescommented, Oct 22, 2020

Would be nice if we had a query_by_uk exactly like query_by_pk but base on the unique keys, this way we don’t need to use the search queries that return an array.

14reactions
joanrodriguezcommented, Mar 9, 2021

This would greatly help

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get objects with unique values for specific keys from ...
What I tried is to itterate through array, but this way I can get only unique object within one key. I can't figure...
Read more >
Keyed collections - JavaScript - MDN Web Docs
Use objects when there is logic that operates on individual elements. WeakMap object. A WeakMap is a collection of key/value pairs whose keys...
Read more >
Query | GORM - GORM
Retrieving a single object ; // Get the first record ordered by primary key db.First(&user) // SELECT * FROM users ORDER BY id...
Read more >
Object that maps unique keys to values - MATLAB - MathWorks
A Map object is a data structure that allows you to retrieve values using a corresponding key.
Read more >
object - SAP AppGyver Documentation
Lookup. Returns the value associated with the given key in the given object. ... Given a list of objects, returns a single object...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found