Skip to content

Commit

Permalink
Merge pull request #40 from RossRogers/master
Browse files Browse the repository at this point in the history
Add simple example usage in README and in example directory
  • Loading branch information
weiznich committed Mar 25, 2024
2 parents cf39b5b + ce20a52 commit 2636528
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ jobs:

- uses: taiki-e/install-action@cargo-hack
- name: Build crate
run: cargo hack --feature-powerset build
run: cargo hack --feature-powerset check --all-targets
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 2636528

Please sign in to comment.