Skip to content

Commit

Permalink
docs: add README
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed Jan 17, 2025
1 parent 4ff593f commit 73bcd0e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,40 @@ search('year:!=1990,2000', db); // [{name: 'Jane', year: 1985}]
search('year:1980..1987', db); // [{name: 'Jane', year: 1985}]
```

## Usage with BSON

```js
import { search } from 'smart-sqlite3-filter';
import sqLite from 'better-sqlite3';

const db = sqLite(':memory:');

// create data and add some dummy data
const sql = `
CREATE TABLE IF NOT EXISTS bsons (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
year INTEGER NOT NULL,
bson BLOB NOT NULL
);
INSERT INTO bsons (name, year, bson) VALUES
('John', 1990, jsonb('{"name": "John", "year": 1990}')),
('Jane', 1985, jsonb('{"name": "Jane", "year": 1985}')),
('Alice', 2000, jsonb('{"name": "Alice", "year": 2000}')),
('Bob', 1990, jsonb('{"name": "Bob", "year": 1990}'));
`;

db.exec(sql);

search('name:$e,n', db); // 3 hits
search('year:1990,2000 name:$e,n', db); // 2 hits
search('bson.year:1990', db); // 2 hits
search('bson.name:$e', db); // 2 hits
search('bson.name:$e,n', db); // 3 hits
search('bson.year:1990,2000 bson.name:$e,n', db); // 2 hits
```

## License

[MIT](./LICENSE)
Expand Down

0 comments on commit 73bcd0e

Please sign in to comment.