Skip to content

Commit e785576

Browse files
authored
Merge pull request #15 from supabase/docs
Update docs
2 parents 81107d4 + 78629ee commit e785576

File tree

4 files changed

+168
-11
lines changed

4 files changed

+168
-11
lines changed

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
name = "postgrest"
33
version = "0.1.0"
44
authors = ["Bobbie Soedirgo <[email protected]>"]
5+
description = "PostgREST client-side library"
6+
homepage = "https://github.com/supabase/postgrest-rs"
7+
repository = "https://github.com/supabase/postgrest-rs"
8+
readme = "README.md"
9+
license = "Apache-2.0 OR MIT"
10+
keywords = ["postgres", "postgrest", "rest", "api"]
11+
categories = ["development-tools"]
512
edition = "2018"
613

714
[dependencies]

LICENSE-MIT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Bobbie Soedirgo
3+
Copyright (c) 2020 Supabase
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 106 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,122 @@
77

88
## Usage
99

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!
11107

12108
## Contributing
13109

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
19115

20116
Unless you explicitly state otherwise, any contribution intentionally submitted
21117
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.
23119

24120
## License
25121

26122
Licensed under either of
27123

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)
31127

32128
at your option.

src/lib.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,57 @@
1+
//! # postgrest-rs
2+
//!
3+
//! [PostgREST](https://postgrest.org) client-side library.
4+
//!
5+
//! This library brings an ORM-like interface to PostgREST.
6+
//!
7+
//! ## Usage
8+
//!
9+
//! Simple example:
10+
//! ```ignore
11+
//! use postgrest::Postgrest;
12+
//!
13+
//! let client = Postgrest::new("https://your-postgrest-endpoint");
14+
//! let resp = client
15+
//! .from("your_table")
16+
//! .select("*")
17+
//! .execute()
18+
//! .await?;
19+
//! let body = resp
20+
//! .text()
21+
//! .await?;
22+
//! ```
23+
//!
24+
//! Using filters:
25+
//! ```ignore
26+
//! let resp = client
27+
//! .from("your_table")
28+
//! .eq("country", "Germany")
29+
//! .gte("id", "20")
30+
//! .select("*")
31+
//! .execute()
32+
//! .await?;
33+
//! ```
34+
//!
35+
//! Updating a table:
36+
//! ```ignore
37+
//! let resp = client
38+
//! .from("your_table")
39+
//! .eq("username", "soedirgo")
40+
//! .update("{\"organization\": \"supabase\"}")
41+
//! .execute()
42+
//! .await?;
43+
//! ```
44+
//!
45+
//! Executing stored procedures:
46+
//! ```ignore
47+
//! let resp = client
48+
//! .rpc("add", "{\"a\": 1, \"b\": 2}")
49+
//! .execute()
50+
//! .await?;
51+
//! ```
52+
//!
53+
//! Check out the [README](https://github.com/supabase/postgrest-rs) for more examples.
54+
155
extern crate reqwest;
256

357
mod builder;

0 commit comments

Comments
 (0)