Skip to content

Commit c060976

Browse files
committed
Update CHANGELOG
1 parent 06be59f commit c060976

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed

CHANGELOG.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,168 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 0.3.0 - UNRELEASED
9+
10+
### Added
11+
12+
- Queries from the database are now zero-copy and no allocation beyond a shared read buffer
13+
for the TCP stream ( in other words, no per-query allocation ).
14+
15+
- [[#129]] Add support for [SQLite](https://sqlite.org/index.html). Generated code should be very close to normal use of the C API.
16+
17+
* Adds `Sqlite`, `SqliteConnection`, `SqlitePool`, and other supporting types
18+
19+
- [[#97]] [[#134]] Add support for user-defined types. [[@Freax13]]
20+
21+
* Rust-only domain types or transparent wrappers around SQL types. These may be used _transparently_ inplace of
22+
the SQL type.
23+
24+
```rust
25+
#[derive(sqlx::Type)]
26+
#[repr(transparent)]
27+
struct Meters(i32);
28+
```
29+
30+
* Enumerations may be defined in Rust and can match SQL by integer discriminant or variant name.
31+
32+
```rust
33+
#[derive(sqlx::Type)]
34+
#[repr(i32)] // Expects a INT in SQL
35+
enum Color { Red = 1, Green = 2, Blue = 3 }
36+
```
37+
38+
```rust
39+
#[derive(sqlx::Type)]
40+
#[sqlx(postgres(oid = 25))] // Postgres requires the OID
41+
#[sqlx(rename_all = "lowercase")] // similar to serde rename_all
42+
enum Color { Red, Green, Blue } // expects 'red', 'green', or 'blue'
43+
```
44+
45+
* **Postgres** further supports user-defined composite types.
46+
47+
```rust
48+
#[derive(sqlx::Type)]
49+
#[sqlx(postgres(oid = ?))] // Postgres requires the OID
50+
struct InterfaceType {
51+
name: String,
52+
supplier_id: i32,
53+
price: f64
54+
}
55+
```
56+
57+
- [[#98]] [[#131]] Add support for asynchronous notifications in Postgres (`LISTEN` / `NOTIFY`). [[@thedodd]]
58+
59+
* Supports automatic reconnection on connection failure.
60+
61+
* `PgListener` implements `Executor` and may be used to execute queries. Be careful however as if the
62+
intent is to handle and process messages rapidly you don't want to be tying up the connection
63+
for too long. Messages received during queries are buffered and will be delivered on the next call
64+
to `recv()`.
65+
66+
```rust
67+
let mut listener = PgListener::new(DATABASE_URL).await?;
68+
69+
listener.listen("topic").await?;
70+
71+
loop {
72+
let message = listener.recv().await?;
73+
74+
println!("payload = {}", message.payload);
75+
}
76+
```
77+
78+
### Changed
79+
80+
- `Query` (and `QueryAs`; returned from `query()`, `query_as()`, `query!()`, and `query_as!()`) now will accept both `&mut Connection` or
81+
`&Pool` where as in 0.2.x they required `&mut &Pool`.
82+
83+
- `Executor` now takes any value that implements `Execute` as a query. `Execute` is implemented for `Query` and `QueryAs` to mean
84+
exactly what they've meant so far, a prepared SQL query. However, `Execute` is also implemented for just `&str` which now performs
85+
a raw or unprepared SQL query. You can further use this to fetch `Row`s from the database though it is not as efficient as the
86+
prepared API (notably Postgres and MySQL send data back in TEXT mode as opposed to in BINARY mode).
87+
88+
```rust
89+
// Set the time zone parameter
90+
conn.execute("SET TIME ZONE LOCAL;").await
91+
92+
// Demonstrate two queries at once with the raw API
93+
let mut cursor = conn.fetch("SELECT 1; SELECT 2");
94+
let row = cursor.next().await?.unwrap();
95+
let value: i32 = row.get(0); // 1
96+
let row = cursor.next().await?.unwrap();
97+
let value: i32 = row.get(0); // 2
98+
```
99+
100+
- `sqlx::Row` now has a lifetime (`'c`) tied to the database connection. In effect, this means that you cannot store `Row`s or collect
101+
them into a collection. `Query` (returned from `sqlx::query()`) has `map()` which takes a function to map from the `Row` to
102+
another type to make this transition easier.
103+
104+
In 0.2.x
105+
106+
```rust
107+
let rows = sqlx::query("SELECT 1")
108+
.fetch_all(&mut conn).await?;
109+
```
110+
111+
In 0.3.x
112+
113+
```rust
114+
let values: Vec<i32> = sqlx::query("SELECT 1")
115+
.map(|row: PgRow| row.get(0))
116+
.fetch_all(&mut conn).await?;
117+
```
118+
119+
To assist with the above, `sqlx::query_as()` now supports querying directly into tuples (up to 9 elements).
120+
121+
```rust
122+
let values: Vec<(i32, bool)> = sqlx::query("SELECT 1, false")
123+
.fetch_all(&mut conn).await?;
124+
```
125+
126+
- `HasSqlType<T>: Database` is now `T: Type<Database>` to mirror `Encode` and `Decode`
127+
128+
- `Query::fetch` (returned from `query()`) now returns a new `Cursor` type. `Cursor` is a custom `Stream` type where the
129+
item type borrows into the stream (which itself borrows from connection). This means that using `query().fetch()` you can now
130+
stream directly from the database with **zero-copy** and **zero-allocation**.
131+
132+
### Removed
133+
134+
- `Query` (returned from `query()`) no longer has `fetch_one`, `fetch_optional`, or `fetch_all`. You _must_ map the row using `map()` and then
135+
you will have a `query::Map` value that has the former methods available.
136+
137+
```rust
138+
let values: Vec<i32> = sqlx::query("SELECT 1")
139+
.map(|row: PgRow| row.get(0))
140+
.fetch_all(&mut conn).await?;
141+
```
142+
143+
### Fixed
144+
145+
- [[#62]] [[#130]] [[#135]] Remove explicit set of `IntervalStyle`. Allow usage of SQLx for CockroachDB and potentially PgBouncer. [[@bmisiak]]
146+
147+
- [[#108]] Allow nullable and borrowed values to be used as arguments in `query!` and `query_as!`. For example, where the column would
148+
resolve to `String` in Rust (TEXT, VARCHAR, etc.), you may now use `Option<String>`, `Option<&str>`, or `&str` instead. [[@abonander]]
149+
150+
- [[#108]] Make unknown type errors far more informative. As an example, trying to `SELECT` a `DATE` column will now try and tell you about the
151+
`chrono` feature. [[@abonander]]
152+
153+
```
154+
optional feature `chrono` required for type DATE of column #1 ("now")
155+
```
156+
157+
[#62]: https://github.com/launchbadge/sqlx/issues/62
158+
[#130]: https://github.com/launchbadge/sqlx/issues/130
159+
160+
[#98]: https://github.com/launchbadge/sqlx/pull/98
161+
[#97]: https://github.com/launchbadge/sqlx/pull/97
162+
[#134]: https://github.com/launchbadge/sqlx/pull/134
163+
[#129]: https://github.com/launchbadge/sqlx/pull/129
164+
[#131]: https://github.com/launchbadge/sqlx/pull/131
165+
[#135]: https://github.com/launchbadge/sqlx/pull/135
166+
[#108]: https://github.com/launchbadge/sqlx/pull/108
167+
168+
[@bmisiak]: https://github.com/bmisiak
169+
8170
## 0.2.6 - 2020-03-10
9171

10172
### Added

0 commit comments

Comments
 (0)