String case sensitive in LiteDB query
See original GitHub issueI have questioned at stackoverflow https://stackoverflow.com/q/44184505/1011174 1 mouth ago
In various environment, the user name is case insensitive. We query admin
equal to ADMIN
. I have searched LiteDB
called CompareTo
to compare two objects that I can’t find a point to make string compared as case insensitive.
The code in QueryEquals.cs
internal override IEnumerable<IndexNode> ExecuteIndex(IndexService indexer, CollectionIndex index)
{
var node = indexer.Find(index, _value, false, Query.Ascending);
if (node == null) yield break;
yield return node;
if (index.Unique == false)
{
// navigate using next[0] do next node - if equals, returns
while (!node.Next[0].IsEmpty && ((node = indexer.GetNode(node.Next[0])).Key.CompareTo(_value) == 0))
{
if (node.IsHeadTail(index)) yield break;
yield return node;
}
}
}
The propositional we can case insensitive
using (var db = new LiteRepository("lite.db"))
{
db.Insert(new User { Name = "John" });
var user = db.Query<User>()
.Where(x => x.Name == "JOHN")
.FirstOrDefault(); // proposal return John
var fail = db.Query<User>()
.Where(x => string.Equals(x.Name, "JOHN", StringComparison.OrdinalIgnoreCase))
.FirstOrDefault(); // throw exception
}
Another consideration, it is a possible to execute lambda expression in LiteDB without conversion by visitor?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
String case sensitive in LiteDB query
I have searched LiteDB called CompareTo to compare two objects that I can't find a point to make string compared as case insensitive....
Read more >Collections - LiteDB :: A .NET embedded NoSQL database
Collection names are case insensitive; Collection names starting with _ are reserved for internal storage use; Collection names starting with $ are reserved...
Read more >Api
The following structure defines the SQL query syntax in LiteDB. Keyworks and function names are case-insensitive. [ EXPLAIN ] SELECT [, ] [...
Read more >How to Make SQLite's LIKE Operator Case-Sensitive
By default, the SQLite LIKE operator is case-insensitive for ASCII characters. This means it will match uppercase and lowercase characters, ...
Read more >Connection String - LiteDB :: A .NET embedded NoSQL ...
LiteDatabase can be initialized using a string connection, with key1=value1; key2=value2; ... syntax. ... Keys and values are case-insensitive.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Done in v4 beta! Now you can write expression functions in index definition.
col.EnsureIndex(x => x.Name, false, "LOWER($.Name)")
After you can search using lower case.
Hi @trichling, after read this I’m thiking in create “index function transformation” that can by applied on index before store. Some basics function could be “lower”, “upper”, “toInt”, “trim” that can be easy to implement. Using this kind of definition on index (not on field) I can apply for all documents, including exist documents.
I will think better and write a propose about this.