Closed simonw closed 4 years ago
Usual problem: what if there's a table called users_single
? You could access single rows from that using users_single_single
- but if there was also a table called users
you would be unable to access single rows from THAT table.
I think I can ignore this edge-case. Redesign your database!
Maybe users_first
instead? Basically the same mechanism as users_list
but it gives you back a single row that's the first item from the query, rather than making you nest through the nodes
field.
So it should take the same arguments as users_list
- but for convenience it should also take arguments for the primary key columns so you can do a direct lookup using them if you know them.
I have a working prototype now (without the primary key options) which looks like this:
{
repos_first(search:"sqlite-utils") {
name
network_count
I'm not sold on the _first
name - here are some other options:
{
repos_single(search:"sqlite-utils") {
name
network_count
{
repos_one(search:"sqlite-utils") {
name
network_count
{
repos_get(search:"sqlite-utils") {
name
network_count
I'm leaning towards repos_get
now.
I want to do something neat with the potential clash between these primary key arguments and the existing search:
etc arguments - which I also need for handing columns that have a _list
prefix and could clash with #27.
Simplest option: add _
suffixes until the argument name no longer clashes with an existing argument.
e.g. for the
users
table you could do this:It would be the table name with
_single
as the suffix.