|
7 | 7 |
|
8 | 8 | ## Usage
|
9 | 9 |
|
10 |
| -TODO |
| 10 | +Generally, you want to instantiate a `Postgrest` struct, optionally switch |
| 11 | +schema with `.schema()`, call `.from()` (or `.rpc()` for stored procedures), do |
| 12 | +some filtering and stuff, and then call `.execute()`. |
| 13 | + |
| 14 | +Simple example: |
| 15 | + |
| 16 | +```rust |
| 17 | +use postgrest::Postgrest; |
| 18 | + |
| 19 | +let client = Postgrest::new("https://your-postgrest-endpoint"); |
| 20 | +let resp = client |
| 21 | + .from("your_table") |
| 22 | + .select("*") |
| 23 | + .execute() |
| 24 | + .await?; |
| 25 | +let body = resp |
| 26 | + .text() |
| 27 | + .await?; |
| 28 | +``` |
| 29 | + |
| 30 | +Using filters: |
| 31 | + |
| 32 | +```rust |
| 33 | +let resp = client |
| 34 | + .from("your_table") |
| 35 | + .eq("country", "Germany") |
| 36 | + .gte("id", "20") |
| 37 | + .select("*") |
| 38 | + .execute() |
| 39 | + .await?; |
| 40 | +``` |
| 41 | + |
| 42 | +Updating a table: |
| 43 | + |
| 44 | +```rust |
| 45 | +let resp = client |
| 46 | + .from("your_table") |
| 47 | + .eq("username", "soedirgo") |
| 48 | + .update("{\"organization\": \"supabase\"}") |
| 49 | + .execute() |
| 50 | + .await?; |
| 51 | +``` |
| 52 | + |
| 53 | +Executing stored procedures: |
| 54 | + |
| 55 | +```rust |
| 56 | +let resp = client |
| 57 | + .rpc("add", "{\"a\": 1, \"b\": 2}") |
| 58 | + .execute() |
| 59 | + .await?; |
| 60 | +``` |
| 61 | + |
| 62 | +_Not enough filters_: |
| 63 | + |
| 64 | +```rust |
| 65 | +let resp = client |
| 66 | + .from("countries") |
| 67 | + .eq("name", "New Zealand") |
| 68 | + .gt("id", "20") |
| 69 | + .lt("id", "20") |
| 70 | + .gte("id", "20") |
| 71 | + .lte("id", "20") |
| 72 | + .like("name", "%United%") |
| 73 | + .ilike("name", "%United%") |
| 74 | + .is("name", "null") |
| 75 | + .in_("name", vec!["China", "France"]) |
| 76 | + .neq("name", "China") |
| 77 | + .fts("phrase", "The Fat Cats", Some("english")) |
| 78 | + .plfts("phrase", "The Fat Cats", None) |
| 79 | + .phfts("phrase", "The Fat Cats", Some("english")) |
| 80 | + .wfts("phrase", "The Fat Cats", None) |
| 81 | + .cs("countries", "(10,20)") |
| 82 | + .cd("countries", "(10,20)") |
| 83 | + .ov("population_range", (100, 500)) |
| 84 | + .sl("population_range", (100, 500)) |
| 85 | + .sr("population_range", (100, 500)) |
| 86 | + .nxl("population_range", (100, 500)) |
| 87 | + .nxr("population_range", (100, 500)) |
| 88 | + .adj("population_range", (100, 500)) |
| 89 | + .select("*") |
| 90 | + .execute() |
| 91 | + .await?; |
| 92 | +``` |
| 93 | + |
| 94 | +More examples incoming! |
| 95 | + |
| 96 | +## Limitations |
| 97 | + |
| 98 | +This library doesn't show the full extent of PostgREST, and definitely doesn't |
| 99 | +replace the need to learn PostgREST. Some known limitations are: |
| 100 | + |
| 101 | +- Doesn't support `not`, `and`, and `or` in filtering |
| 102 | +- Many inputs are unsanitized (multi-column select, insert/update body, etc.) |
| 103 | +- Counting (with HEAD verb) |
| 104 | +- Resource embedding (embedded filters, etc.) |
| 105 | + |
| 106 | +That said, if there are any features you want in, feel free to create an issue! |
11 | 107 |
|
12 | 108 | ## Contributing
|
13 | 109 |
|
14 |
| -- Fork the repo on GitHub |
15 |
| -- Clone the project to your own machine |
16 |
| -- Commit changes to your own branch |
17 |
| -- Push your work back up to your fork |
18 |
| -- Submit a Pull request so that we can review your changes and merge |
| 110 | +- Fork the repo on GitHub |
| 111 | +- Clone the project to your own machine |
| 112 | +- Commit changes to your own branch |
| 113 | +- Push your work back up to your fork |
| 114 | +- Submit a Pull request so that we can review your changes and merge |
19 | 115 |
|
20 | 116 | Unless you explicitly state otherwise, any contribution intentionally submitted
|
21 | 117 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
|
22 |
| -dual licensed as above, without any additional terms or conditions. |
| 118 | +dual licensed as below, without any additional terms or conditions. |
23 | 119 |
|
24 | 120 | ## License
|
25 | 121 |
|
26 | 122 | Licensed under either of
|
27 | 123 |
|
28 |
| -* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or |
29 |
| - http://www.apache.org/licenses/LICENSE-2.0) |
30 |
| -* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) |
| 124 | +- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or |
| 125 | + http://www.apache.org/licenses/LICENSE-2.0) |
| 126 | +- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) |
31 | 127 |
|
32 | 128 | at your option.
|
0 commit comments