ruricolist / cl-yesql

Common Lisp library for using SQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add collected keys to the function's &KEY in lambda list

phoe opened this issue · comments

-- name: insert-new-player @execute
-- Inserts a new player into the database.
INSERT INTO player (player_name, email, passhash)
  VALUES(:player_name, :email, :passhash);

Currently, this function has a signature (insert-new-player &rest args).
It should be possible to collect the list of used keys though (I can bet $5 you already do this internally) and insert them into the function's argument list, and therefore turn the function signature into a more appropriate (insert-new-player :player-name :email :passhash).

This issue is actually deeper than just that.

Currently, CL-YESQL has no way of naming positional arguments and generating meaningful lambda lists, despite having all the required information in form of how many arguments there are, in which order they appear in the query, and what is their name (in case of keyword arguments).

Additionally, keyword arguments are not treated as optional in CL-YESQL, despite their usual function in Common Lisp as being "modifiers".

I will be thinking on how to solve this. One thing that I can think of is replacing ? with ?foo where foo will be the argument name in the function's lambda list. If no name is supplied, it may default to argN where N is the number of the argument in the query.

CL-Yesql itself actually does save argument information (and documentation, as in #6). The problem is with the way imports are (currently) handled: functions are not bound directly, but through an indirection, to make sure redefinitions are picked up.

There may be a better way to handle this; I need to think about it.

I don't think why you couldn't depend on ASDF for that macro if you already depend on ASDF for system definition. The trick is to inject at a proper place, so it comes directly before your DEFUNs - it only checks the CARs of its subforms and does not have a full codewalker.

This is supported now in the dev branch.