question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

String case sensitive in LiteDB query

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mbdavidcommented, Aug 28, 2017

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.

0reactions
mbdavidcommented, Aug 9, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found