简体   繁体   English

HugSQL 查询中的嵌套命名空间键

[英]Nested namespaced keys in HugSQL Query

I have a nested map with namespaced keys like this:我有一个嵌套的 map 具有这样的命名空间键:

{
  :model.person/primary {:model.person/name "John Smith"}
}

Instead of simpliying this into a flat map I'd like to pass it straight through to a HugSQL function.我不想将其简化为平面 map,而是将其直接传递给 HugSQL function。 The docs say HugSQL supports a deep parameter get and namespaced keys but I'm not sure how to combine them.文档说 HugSQL 支持深度参数获取和命名空间键,但我不确定如何组合它们。

(hugsql/def-sqlvec-fns-from-string
  "-- :name get_person :? :1
   -- :doc Get a person
   SELECT * FROM person WHERE name = :value:model.person/primary:model.person/name")

Now if I execute the function it generates with my original map I get this:现在,如果我执行 function 它会用我原来的 map 生成,我会得到这个:

(get_person-sqlvec {:model.person/primary {:model.person/name "John Smith"}})

Execution error (ExceptionInfo) at hugsql.core/validate-parameters! (core.clj:83).
Parameter Mismatch: :model.person/name parameter data not found.

I would imagine the variable naming convention in the SQL is the source of the problem:我想 SQL 中的变量命名约定是问题的根源:

:value:model.person/primary:model.person/name

But I'm not sure what the correct value should be.但我不确定正确的值应该是多少。

First off, the deep parameter get uses .首先,深度参数 get 使用. between keys, not : , so that is part of your problem.键之间,而不是: ,所以这是你的问题的一部分。

However, right now HugSQL only supports one level of qualified keywords -- because there is an inherent ambiguity between .然而,目前 HugSQL 只支持一级限定关键字——因为. for separating deep parameter get keys and the .用于分离深度参数获取键和. that can be part of (qualified) keywords.可以是(限定)关键字的一部分。

You could have where name =:value:model.person/primary.name and then a hash map like {:model.person/primary {:name "John Smith"}} You could have where name =:value:model.person/primary.name and then a hash map like {:model.person/primary {:name "John Smith"}}

Or you could have where name =:value:model.person/name and pass {:model.person/name "John Smith"}或者你可以有where name =:value:model.person/name并通过{:model.person/name "John Smith"}

HugSQL will need a different syntax to support nested qualified keys (to resolve the . ambiguity). HugSQL 将需要不同的语法来支持嵌套的限定键(以解决.歧义)。 I mentioned Selmer's approach to Curtis Summers, HugSQL's maintainer: using .. to indicate the dot that is part of a keyword, so you could have:我提到了 Selmer 对 HugSQL 的维护者 Curtis Summers 的方法:使用..表示作为关键字一部分的点,因此您可以:

where name =:value:model..person/primary.model..person/name

(that's how Selmer indicates nested qualified keys) but there are backward compatibility issues to consider as well as whether that's a good syntax in the first place (I'm a heavy user of Selmer and I don't like that, but I understand why they did it). (这就是 Selmer 表示嵌套限定键的方式)但是首先要考虑向后兼容性问题以及这是否是一个好的语法(我是 Selmer 的重度用户,我不喜欢这样,但我明白为什么他们做到了)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM