Skip to content

Upgrading sqlx 0.2 to 0.3

Breaking0.2.6 → 0.3.5Breaking5New15Changed4Fixed15Other1

BreakingUpgrade verdict

5 breaking changes.

  • Rows returned from a query can no longer be saved or gathered into a list, because they now borrow from the database connection. Convert each row to your own type as you read it.
  • The trait used to describe SQL types has been renamed and restructured; code implementing or bounding on the old trait must change.
  • The Postgres type info helper for building a type from an OID is gone; use the name-based constructor instead.
  • If you used query() and then fetched rows directly, you now need to convert each row with map() before fetching.
Top 3 of 5 that need code or config changes
Breaking5
sqlx::Row gains a lifetime tied to the connection, so Rows can no longer be stored or collected; use Query::map() instead.
sqlx::RowQuerysqlx::query()map()
HasSqlType<T>: Database is replaced by T: Type<Database> to mirror Encode and Decode.
HasSqlTypeTypeEncodeDecodeDatabase
Removes PgTypeInfo::with_oid and replaces it with PgTypeInfo::with_name.
PgTypeInfo::with_oidPgTypeInfo::with_name
Removes fetch_one, fetch_optional, and fetch_all from Query; callers must map() rows first to get a query::Map with those methods.
Queryquery()fetch_onefetch_optionalfetch_allmap()query::Map
Query::fetch now returns a new Cursor type that streams items borrowing into the stream, enabling zero-copy, zero-allocation streaming.
Query::fetchquery()Cursor