kysely icon indicating copy to clipboard operation
kysely copied to clipboard

Should these methods also have a `$` prefix?

Open igalklebanov opened this issue 2 years ago • 0 comments

As we're gearing up for v1, a refactor following #260 introduced renames to some utility methods that do not map to sql keywords/clauses, and added a $ prefix to their names.

Going through the codebase, there seem to be some more methods we could treat similarily.

Let's list them and discuss:

.toOperationNode() -> .$toOperationNode(). This one is mostly used internally, but is exposed in top-level APIs of many builders. We kind of want our consumers to be discouraged from using it directly in most cases. It might even be a good candidate for _ prefix instead since it's pretty "private".

.ref(...) -> .$ref(...). This one exists in a few places but doesn't map to anything sql. Usually used inside a sql statement, and distinguishing it could help with readability.

.withPlugin(...) -> .$withPlugin(...). A utility method that can be used anywhere in the chain, and thus needs to be distinguished from sql methods. It can be confused for sql's with clause.

.withSchema(...) -> .$withSchema(...). A utility method that prepends a schema name to all references of a follow-up query chain. It can be confused for sql's with clause.

Escape hatch methods that don't map to sql, but accept things that do and can be used in between sql methods.

.modifyFront(...) -> .$modifyFront(...). .modifyEnd(...) -> .$modifyEnd(...).

Recently introduced "clearX" methods are utility methods that omit clauses from the underlying syntax tree. They can be confused for variants of the sql clauses they omit.

.clearWhere() -> .$clearWhere(). .clearSelect() -> .$clearSelect(). .clearLimit() -> .$clearLimit(). .clearOffset() -> .$clearOffset(). .clearOrderBy() -> .$clearOrderBy().

RawBuilder & sql template tag methods are called in between things that map to sql or accept sql things as arguments and thus also need to be distinguished:

.value(...) -> .$value(...). This one can be confused for sql insert's values clause. .table(...) -> .$table(...). .id(...) -> .$id(...). .literal(...) -> .$literal(...). .raw(...) -> .$raw(...). .join(...) -> .$join(...). This one especially, since it can be confused for a sql join clause.

If you find other candidates, please do share!

WDYT?

igalklebanov avatar Jan 06 '23 10:01 igalklebanov