Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,39 @@ You should format the `selector` property this way:
```

This makes selectors more convenient to write declaratively, while still
maintaining the ability to express selectors with full fidelity. For more
documentation on pouchdb-find selectors, please check out the docs
maintaining the ability to express selectors with full fidelity. Note that
embedded strings in selectors (e.g. 'Mario' in the example above) are not
always parsed correctly. In these cases it is better to express the selector
as an object or JSON string, as shown in the example below

For more documentation on pouchdb-find selectors, please check out the docs
[here](https://github.com/nolanlawson/pouchdb-find#dbfindrequest--callback).

You can also express selectors as objects or JSON strings, which must
conform to the semantics described in the pouchdb-find documentation. JSON
strings can be used as selector attribute values. Javascript objects can be
defined as component properties and passed as a value to the selector.

Example of object used as a selector:

```html
<app-pouchdb-query
db-name="cats"
selector="{{mySelector}}
...
</app-pouchdb-query>
```

```javascript
Polymer({
...
properties: {
mySelector: {
type: Object,
value: { $and: [ { _id: { $gte: "rec1" } }, { _id: { $lt: "rec3" } } ] }
},
...
```

##&lt;app-pouchdb-sync&gt;

Expand Down
40 changes: 38 additions & 2 deletions app-pouchdb-query.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,39 @@
```

This makes selectors more convenient to write declaratively, while still
maintaining the ability to express selectors with full fidelity. For more
documentation on pouchdb-find selectors, please check out the docs
maintaining the ability to express selectors with full fidelity. Note that
embedded strings in selectors (e.g. 'Mario' in the example above) are not
always parsed correctly. In these cases it is better to express the selector
as an object or JSON string, as shown in the example below

For more documentation on pouchdb-find selectors, please check out the docs
[here](https://github.com/nolanlawson/pouchdb-find#dbfindrequest--callback).

You can also express selectors as objects or JSON strings, which must
conform to the semantics described in the pouchdb-find documentation. JSON
strings can be used as selector attribute values. Javascript objects can be
defined as component properties and passed as a value to the selector.

Example of object used as a selector:

```html
<app-pouchdb-query
db-name="cats"
selector="{{mySelector}}
...
</app-pouchdb-query>
```

```javascript
Polymer({
...
properties: {
mySelector: {
type: Object,
value: { $and: [ { _id: { $gte: "rec1" } }, { _id: { $lt: "rec3" } } ] }
},
...
```
-->
<script>
(function() {
Expand Down Expand Up @@ -202,6 +232,12 @@
},

__computeParsedSelector: function(selector) {
if ((typeof selector) !== "string")
return selector;
try {
return JSON.parse(selector);
} catch(e) {}

var dimensions = selector.split(/\s*[,]\s*/);
var parsedSelector = {};

Expand Down