SailsJS /水线 - 我如何使用模型和关联一个“字符串”指数? [英] SailsJS / Waterline - How do I use a 'string' index in models and associations?

查看:503
本文介绍了SailsJS /水线 - 我如何使用模型和关联一个“字符串”指数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新手的问题在这里。

根据 https://github.com/balderdashy/waterline#indexing 不能使用一个字符串数据类型作为水线指数由于与不区分大小写的问题:

According to https://github.com/balderdashy/waterline#indexing you cannot use a 'string' datatype as an index in Waterline due to issues with case insensitivity:

目前与添加索引到的字符串字段的问题。由于水线执行其在不区分大小写的方式查询,我们无法使用索引上的字符串属性。有一些变通办法正在讨论但没有什么是迄今为止实现的。这将在不久的将来完全支持对字符串的索引进行更新。

There is currently an issue with adding indexes to string fields. Because Waterline performs its queries in a case insensitive manner, we are unable to use the index on a string attribute. There are some workarounds being discussed but nothing is implemented so far. This will be updated in the near future to fully support indexes on strings.

我关心的问题是:性能;使用字符串'键关联是不可能的。

The problems I'm concerned with are: performance; associations using 'string' keys aren't possible.

我的问题是:


  1. 如果说这样做,它是否在字符串其实指数?如果是这样,那么什么是基于索引:a)原始字符串是; b)该字符串的小写; c)该字符串的大写?

  2. 如果它确实对字符串不会索引所有的,因为是隐含的,如果你可以假设,'不能用'的意思是'不制造',那么这是否意味着水线/数据库后端做了非索引记录由-Record检索和比较?似乎是非常低效的,如果是的话。

  3. 是'串'和'文字'的数据类型都受影响,或我可以使用文本,在这种情况下,问题#2需要回答为文本数据类型了。

  4. 如果你真的不能使用字符串,我应该怎么用,而不是外键?一个整数ID和一个连接表绑定的字符串值另一个表? (似乎浪费,但对于可行的像一个关键字列表)。

  5. 如果,当,将这个'问题'是固定的?

  6. 什么和/或在哪里的解决方法正在讨论'?

  7. 有没有更好的ORM我应该看或只使用本地SQL方法(仅供参考,我使用PostgreSQL)。

我希望回答这里是:
字符串可以被索引,但反对字符串数据类型查询使用小写字母来执行(或大写字母,但让我知道)。因此,我可以有一个字符串键,只要情况下是正确的。

My hoped for answer here is: 'string' can be indexed but queries against 'string' datatypes are performed using lowercase (or uppercase, but let me know which). As such, I can have a 'string' key so long as the case is correct.

另外,我认为'串'和'文字'在水线有效的代名词,该数据库的本地上下文至少要有外面。

Also, I assume 'string' and 'text' are effectively synonymous in Waterline, at least outside of the database's native context.

在此先感谢这里的任何帮助。

Thanks in advance for any help here.

推荐答案

二点使这里:


  1. 你指的是真正的意思至于为什么唯一属性不(目前)的解释的说明字符串属性正常工作。

  1. The note you're referring to is really meant as an explanation for why the unique property doesn't (currently) work properly for string attributes.

这主要适用于MongoDB的。

It applies mostly to MongoDB.

当您创建帆两款车型之间的关联,主键总是引用;水线的当前版本不支持指定一个外键字段。当帆在你的Postgres数据库中创建一个表,它会自动添加一个 PRIMARY KEY 指数模型的主键( ID 默认情况下,或任何属性,你的的PrimaryKey 属性提名,如果你设置 autoPk 为模型)。发生这种情况的任何列类型。你提到的问题是指的自定义索引的字符串类型。所以,当你想使用字符串列在Postgres的按键,包括协会正常工作了。

When you create associations between two models in Sails, primary keys are always referenced; the current version of Waterline doesn't support specifying a foreign key field. When Sails creates a table in your Postgres database, it will automatically add a PRIMARY KEY index to the model's primary key (id by default, or whichever attribute you nominate with the primaryKey property if you set autoPk to false for the model). This happens for any column type. The issue you referenced refers to custom indexes on string types. So, everything should work as you expect using string columns as keys in Postgres, including associations.

这篇关于SailsJS /水线 - 我如何使用模型和关联一个“字符串”指数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆