Skip to content

Commit

Permalink
Add simple example usage in README and in example directory
Browse files Browse the repository at this point in the history
  • Loading branch information
RossRogers committed Mar 24, 2024
1 parent cf39b5b commit 1de3574
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,17 @@ to [diesel](https://diesel.rs/), the safe, extensible ORM and query builder for

This crate also serves as an example of how to extend diesel with database specific features
outside of diesel itself as third party crate.


## Example Usage

```rust

use diesel_full_text_search::*;

let search = "bar";

let query = Foo::table.filter(to_tsvector(Foo::description).matches(to_tsquery(search)));
```

For complete examples, see [/examples](./examples).
24 changes: 24 additions & 0 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
extern crate diesel;
use diesel::*;

extern crate diesel_full_text_search;
use diesel_full_text_search::*;

type DB = diesel::pg::Pg;

diesel::table! {
foo (id) {
id -> Int4,
description -> Text,
}
}

fn main() {
let search = "bar";

let query = foo::table.filter(to_tsvector(foo::description).matches(to_tsquery(search)));

let sql = debug_query::<DB, _>(&query).to_string();

println!("The sql code for `query` is:\n {sql}\n");
}

0 comments on commit 1de3574

Please sign in to comment.