{
  "select_by_ids": {
    "query": "select * from #[resource] where id in :[ids]",
    "returns": ["id", "name", "created_at", "updated_at", "status"],
    "args": {
      "resource": { "enum": ["shows", "songs", "artists"] },
      "ids": { "item_type": "integer" }
    }
  },
  "select_children": {
    "query": "select * from #[resource] where #[foreign_key] in :[f_ids]",
    "returns": ["id", "name", "created_at", "updated_at", "status"],
    "args": {
      "resource": {
        "enumif": {
          "foreign_key": {
            "show_id": ["shows", "songs", "rel_show_song"],
            "song_id": ["songs", "rel_show_song"],
            "artist_id": ["songs", "artists"]
          }
        }
      },
      "foreign_key": { "enum": ["show_id", "song_id", "artist_id"] }
    }
  },
  "select_related_entities": {
    "query": "select r.id as rel_id, r.#[source_fk] as source_id, r.#[target_fk] as target_id, s.name as source_name, t.name as target_name, r.created_at from #[relation_table] r join #[source_table] s on r.#[source_fk] = s.id join #[target_table] t on r.#[target_fk] = t.id",
    "returns": ["rel_id", "source_id", "target_id", "source_name", "target_name", "created_at"],
    "args": {
      "relation_table": {
        "enumif": {
          "source_fk": {
            "show_id": ["rel_show_song"],
            "song_id": ["rel_show_song"],
            "artist_id": ["rel_artist_show"]
          },
          "target_fk": {
            "show_id": ["rel_artist_show"],
            "song_id": ["rel_show_song"],
            "artist_id": ["rel_artist_song"]
          }
        }
      },
      "source_fk": { "enum": ["show_id", "song_id", "artist_id"] },
      "target_fk": { "enum": ["show_id", "song_id", "artist_id"] },
      "source_table": { "enum": ["shows", "songs", "artists"] },
      "target_table": { "enum": ["shows", "songs", "artists"] }
    }
  },
  "select_entities_via_relation": {
    "query": "select distinct t.* from #[target_table] t join #[relation_table] r on t.id = r.#[target_fk] where r.#[source_fk] in :[source_ids]",
    "returns": ["id", "name", "artist_id", "context", "created_at", "updated_at", "status"],
    "args": {
      "target_table": { "enum": ["shows", "songs", "artists"] },
      "relation_table": {
        "enumif": {
          "source_fk": {
            "show_id": ["rel_show_song"],
            "song_id": ["rel_show_song"],
            "artist_id": ["rel_artist_show"]
          },
          "target_fk": {
            "show_id": ["rel_artist_show"],
            "song_id": ["rel_show_song"],
            "artist_id": ["rel_artist_song"]
          }
        }
      },
      "source_fk": { "enum": ["show_id", "song_id", "artist_id"] },
      "target_fk": { "enum": ["show_id", "song_id", "artist_id"] },
      "source_ids": { "item_type": "integer" }
    }
  },
  "select_songs_via_artists": {
    "query": "select g.* from songs g join artists a on g.artist_id = a.id where a.id in :[artist_ids]",
    "returns": ["id", "name", "artist_id", "created_at", "updated_at", "status"]
  }
}
