Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query with limit(5) returns more than 5 elements #50

Closed
ditiem opened this issue Jun 3, 2018 · 3 comments
Closed

query with limit(5) returns more than 5 elements #50

ditiem opened this issue Jun 3, 2018 · 3 comments
Labels

Comments

@ditiem
Copy link

@ditiem ditiem commented Jun 3, 2018

Hello,

I am testing how nanoSQL behaves and I found something that it is not what I am expecting, so I wanted to ask if I am wrong or there is a bug. I have done a codepen:

https://codepen.io/anon/pen/bKEqbM?editors=0010#anon-login

My idea was to check whether an observable was invoked when an inserted element affect the result query (in this case the "second page"):

nSQL().observable( ( ) =>
nSQL("users").query('select').limit( 5 ).offset( 5 ).emit() )
.subscribe( update ) ;

And then I run some simple code that inserts elements in the database.

So I run into these 2 issues:
1- The observable is called every time the database is modified. I can live with it, but then I see no much difference between nSQL().on("change") and .observable.
2- The number of rows (8) is bigger than the limit set (5)

Thank you!

@only-cliches
Copy link
Owner

@only-cliches only-cliches commented Jun 4, 2018

Ah the cache haunts me again!

This was being caused by the query cache not clearing itself properly. I've disabled the query cache outright for now, live as of 1.6.4.

That should fix your problem. 😄

@only-cliches
Copy link
Owner

@only-cliches only-cliches commented Jun 5, 2018

Oh, forgot about your other question...

The observable actually uses .on("change") internally, but there are way more options for debouncing and filtering the output, all the options available:

nSQL().observable( ( ) =>
    nSQL("users").query('select').limit( 5 ).offset( 5 ).emit() 
)
.debounce(1000) // dont trigger more than every second
.distinct() // only trigger if the previous record doesn't match the next record to trigger
.filter(rows => rows.length > 10) // use a filter function to only emit changes based on provided fn.
.map(rows => rows) // mutate the result
.first() // only emit the first change
.skip(10) // skip the first n elements
.take(10) // only get the first n elements
.subscribe( update ) ;

Obviously each function is optional.

@only-cliches
Copy link
Owner

@only-cliches only-cliches commented Jun 8, 2018

Closing this issue since there's been no activity for a few days, feel free to open it back up if you have more questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants