I'm looking for a library that could filter javascript collections of objets from a SQL query. No such results on Google :/
For example, this objects collection...
var objects = [{id : 1, name : "o1"},{id : 2, name : "o2"}]
filtered with...
SELECT * FROM objects WHERE id = 1
would return...
[{id : 1, name : "o1"}]
Do you know if such a library already exists ? Or should I devellop it by myself... ? (Uhh --')
Thanks all !
you can use underscore's where function. for example
var listOfPlays = [
{title: "Cymbeline", author: "Shakespeare", year: 1611},
{title: "The Tempest", author: "Shakespeare", year: 1611},
{title: "Sonnets", author: "Shakespeare", year: 1609},
]
_.where(listOfPlays, {author: "Shakespeare", year: 1611});
=> [{title: "Cymbeline", author: "Shakespeare", year: 1611},
{title: "The Tempest", author: "Shakespeare", year: 1611}]
Thanks for all these answers ;) Well, such a library does not seems to exist :/ I bypassed the problem and focused only on the Where clause : I built a class specialized in handling a where clause. This class can even return a SQL Where clause string (used in a further request) or filter a collection or objects.
Thanks for your answers, they all helped me in solving my problem ;)