https://github.com/solidsnack/rust-postgres-named-parameters
https://github.com/solidsnack/rust-postgres-named-parameters
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/solidsnack/rust-postgres-named-parameters
- Owner: solidsnack
- Created: 2017-04-08T21:26:51.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-11T06:08:00.000Z (about 9 years ago)
- Last Synced: 2025-12-25T13:45:54.653Z (6 months ago)
- Language: Rust
- Size: 26.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Named Parameters For `postgres` Queries
This crate provides for named parameters for [`postgres`] queries.
[`postgres`]: https://docs.rs/postgres
```rust
#[macro_use]
extern crate postgres_named_parameters;
use chrono::Duration;
use chrono::prelude::UTC;
let now = UTC.now();
let q = query!("SELECT * FROM log WHERE t BETWEEN {lo} AND {hi}",
lo = now - Duration.minutes(6),
hi = now - Duration.minutes(1));
conn.execute(q.text(), q.parameters());
```
## Parameters & Idenitifers
* Use `{...}` for parameters:
```sql
SELECT * FROM log WHERE t BETWEEN {lo} AND {hi}
```
* Use `{&...}` for variables that will be treated as identifiers, which is to
say, as the names of columns, types or tables:
```sql
INSERT INTO {¤t_partition} VALUES (now(), {tag}, {location})
```