2019-12-28 01:31:01 +00:00
< h1 align = "center" > SQLx< / h1 >
< div align = "center" >
< strong >
🧰 The Rust SQL Toolkit
< / strong >
< / div >
< br / >
< div align = "center" >
2020-03-28 00:42:23 +00:00
<!-- Github Actions -->
2023-02-20 07:11:06 +00:00
< a href = "https://github.com/launchbadge/sqlx/actions/workflows/sqlx.yml?query=branch%3Amain" >
< img src = "https://img.shields.io/github/actions/workflow/status/launchbadge/sqlx/sqlx.yml?branch=main&style=flat-square"
alt="actions status" />
< / a >
2019-12-30 10:29:56 +00:00
<!-- Version -->
2019-12-28 01:31:01 +00:00
< a href = "https://crates.io/crates/sqlx" >
< img src = "https://img.shields.io/crates/v/sqlx.svg?style=flat-square"
alt="Crates.io version" />
< / a >
2020-01-12 18:22:12 +00:00
<!-- Discord -->
2020-01-12 22:02:52 +00:00
< a href = "https://discord.gg/uuruzJ7" >
< img src = "https://img.shields.io/discord/665528275556106240?style=flat-square" alt = "chat" / >
< / a >
2019-12-30 10:29:56 +00:00
<!-- Docs -->
2019-12-28 01:31:01 +00:00
< a href = "https://docs.rs/sqlx" >
< img src = "https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square"
alt="docs.rs docs" />
< / a >
2020-03-28 00:42:23 +00:00
<!-- Downloads -->
< a href = "https://crates.io/crates/sqlx" >
< img src = "https://img.shields.io/crates/d/sqlx.svg?style=flat-square"
alt="Download" />
< / a >
< / div >
< div align = "center" >
< h4 >
< a href = "#install" >
Install
< / a >
< span > | < / span >
< a href = "#usage" >
Usage
< / a >
< span > | < / span >
< a href = "https://docs.rs/sqlx" >
Docs
< / a >
< / h4 >
2019-12-28 01:31:01 +00:00
< / div >
2019-12-28 09:37:02 +00:00
< br / >
2019-12-28 01:31:01 +00:00
< div align = "center" >
2021-05-30 22:52:25 +00:00
< small > Built with ❤️ by < a href = "https://launchbadge.com" > The LaunchBadge team< / a > < / small >
2019-12-28 01:31:01 +00:00
< / div >
< br / >
2021-07-14 21:29:42 +00:00
< div align = "center" >
< h5 > Have a question? Be sure to < a href = "FAQ.md" > check the FAQ first!< / a > < / h5 >
< / div >
< br / >
2020-07-14 13:33:36 +00:00
SQLx is an async, pure Rust< sub > †< / sub > SQL crate featuring compile-time checked queries without a DSL.
2019-12-28 01:31:01 +00:00
2020-10-20 10:29:24 +00:00
- **Truly Asynchronous** . Built from the ground-up using async/await for maximum concurrency.
2019-12-28 01:31:01 +00:00
2021-05-30 22:52:25 +00:00
- **Compile-time checked queries** (if you want). See [SQLx is not an ORM ](#sqlx-is-not-an-orm ).
2019-12-28 09:37:02 +00:00
2023-10-04 22:55:04 +00:00
- **Database Agnostic** . Support for [PostgreSQL], [MySQL], [SQLite].
- [MSSQL] was supported prior to version 0.7, but has been removed pending a full rewrite of the driver as part of our [SQLx Pro initiative].
2020-03-28 00:42:23 +00:00
2020-10-20 10:29:24 +00:00
- **Pure Rust** . The Postgres and MySQL/MariaDB drivers are written in pure Rust using **zero** unsafe< sub > ††</ sub > code.
2020-07-14 13:33:36 +00:00
2021-05-30 22:52:25 +00:00
- **Runtime Agnostic** . Works on different runtimes ([`async-std`] / [`tokio`] / [`actix`]) and TLS backends ([`native-tls`], [`rustls`]).
2020-01-15 09:27:19 +00:00
2021-05-30 22:52:25 +00:00
< small > < small >
2020-03-28 00:42:23 +00:00
2021-05-30 22:52:25 +00:00
† The SQLite driver uses the libsqlite3 C library as SQLite is an embedded database (the only way
we could be pure Rust for SQLite is by porting _all_ of SQLite to Rust).
†† SQLx uses `#![forbid(unsafe_code)]` unless the `sqlite` feature is enabled. As the SQLite driver interacts
with C, those interactions are `unsafe` .
< / small > < / small >
2020-03-28 00:42:23 +00:00
2020-10-20 10:29:24 +00:00
[postgresql]: http://postgresql.org/
[sqlite]: https://sqlite.org/
[mysql]: https://www.mysql.com/
[mssql]: https://www.microsoft.com/en-us/sql-server
2023-10-04 22:55:04 +00:00
[SQLx Pro initiative]: https://github.com/launchbadge/sqlx/discussions/1616
2020-03-28 00:42:23 +00:00
---
2020-10-20 10:29:24 +00:00
- Cross-platform. Being native Rust, SQLx will compile anywhere Rust is supported.
2020-03-28 00:42:23 +00:00
2020-10-20 10:29:24 +00:00
- Built-in connection pooling with `sqlx::Pool` .
2020-07-14 13:33:36 +00:00
2023-05-04 19:59:35 +00:00
- Row streaming. Data is read asynchronously from the database and decoded on demand.
2020-07-14 13:33:36 +00:00
2020-10-20 10:29:24 +00:00
- Automatic statement preparation and caching. When using the high-level query API (`sqlx::query`), statements are
2023-05-04 19:59:35 +00:00
prepared and cached per connection.
2020-07-14 13:33:36 +00:00
2020-10-20 10:29:24 +00:00
- Simple (unprepared) query execution including fetching results into the same `Row` types used by
2023-05-04 19:59:35 +00:00
the high-level API. Supports batch execution and returns results from all statements.
2020-07-14 13:33:36 +00:00
2020-10-20 10:29:24 +00:00
- Transport Layer Security (TLS) where supported ([MySQL] and [PostgreSQL]).
2020-07-14 13:33:36 +00:00
2020-10-20 10:29:24 +00:00
- Asynchronous notifications using `LISTEN` and `NOTIFY` for [PostgreSQL].
2020-07-14 13:33:36 +00:00
2020-10-20 10:29:24 +00:00
- Nested transactions with support for save points.
2020-03-28 00:42:23 +00:00
2022-06-17 22:31:25 +00:00
- `Any` database driver for changing the database driver at runtime. An `AnyPool` connects to the driver indicated by the URL scheme.
2020-07-27 09:11:46 +00:00
2020-01-15 09:27:19 +00:00
## Install
2023-05-04 19:59:35 +00:00
SQLx is compatible with the [`async-std`], [`tokio`], and [`actix`] runtimes; and, the [`native-tls`] and [`rustls`] TLS backends. When adding the dependency, you must choose a runtime feature that is `runtime` + `tls` .
2020-03-28 00:42:23 +00:00
[`async-std`]: https://github.com/async-rs/async-std
[`tokio`]: https://github.com/tokio-rs/tokio
2020-10-20 10:29:24 +00:00
[`actix`]: https://github.com/actix/actix-net
2021-05-30 22:52:25 +00:00
[`native-tls`]: https://crates.io/crates/native-tls
[`rustls`]: https://crates.io/crates/rustls
2020-03-28 00:42:23 +00:00
2020-01-15 09:27:19 +00:00
```toml
# Cargo.toml
[dependencies]
2023-02-02 00:47:29 +00:00
# PICK ONE OF THE FOLLOWING:
# tokio (no TLS)
2023-03-16 22:15:58 +00:00
sqlx = { version = "0.7", features = [ "runtime-tokio" ] }
2023-02-02 00:47:29 +00:00
# tokio + native-tls
2023-07-08 19:42:50 +00:00
sqlx = { version = "0.7", features = [ "runtime-tokio", "tls-native-tls" ] }
2020-11-12 15:42:31 +00:00
# tokio + rustls
2023-03-16 22:15:58 +00:00
sqlx = { version = "0.7", features = [ "runtime-tokio", "tls-rustls" ] }
2023-02-02 00:47:29 +00:00
# async-std (no TLS)
2023-03-16 22:15:58 +00:00
sqlx = { version = "0.7", features = [ "runtime-async-std" ] }
2020-11-12 15:42:31 +00:00
# async-std + native-tls
2023-07-08 19:42:50 +00:00
sqlx = { version = "0.7", features = [ "runtime-async-std", "tls-native-tls" ] }
2023-02-02 00:47:29 +00:00
# async-std + rustls
2023-03-16 22:15:58 +00:00
sqlx = { version = "0.7", features = [ "runtime-async-std", "tls-rustls" ] }
2020-01-15 09:27:19 +00:00
```
#### Cargo Feature Flags
2023-05-04 19:59:35 +00:00
For backward-compatibility reasons, the runtime and TLS features can either be chosen together as a single feature,
2023-02-02 00:47:29 +00:00
or separately.
2023-05-04 19:59:35 +00:00
For forward compatibility, you should use the separate runtime and TLS features as the combination features may
2023-02-02 00:47:29 +00:00
be removed in the future.
- `runtime-async-std` : Use the `async-std` runtime without enabling a TLS backend.
2023-03-16 22:15:58 +00:00
- `runtime-async-std-native-tls` : Use the `async-std` runtime and `native-tls` TLS backend (SOFT-DEPRECATED).
2020-07-14 13:33:36 +00:00
2023-03-16 22:15:58 +00:00
- `runtime-async-std-rustls` : Use the `async-std` runtime and `rustls` TLS backend (SOFT-DEPRECATED).
2020-10-20 10:21:01 +00:00
2023-02-02 00:47:29 +00:00
- `runtime-tokio` : Use the `tokio` runtime without enabling a TLS backend.
2023-03-16 22:15:58 +00:00
- `runtime-tokio-native-tls` : Use the `tokio` runtime and `native-tls` TLS backend (SOFT-DEPRECATED).
2020-07-14 13:33:36 +00:00
2023-03-16 22:15:58 +00:00
- `runtime-tokio-rustls` : Use the `tokio` runtime and `rustls` TLS backend (SOFT-DEPRECATED).
2020-07-14 13:33:36 +00:00
2023-02-02 00:47:29 +00:00
- Actix-web is fully compatible with Tokio and so a separate runtime feature is no longer needed.
2023-07-08 19:42:50 +00:00
- `tls-native-tls` : Use the `native-tls` TLS backend (OpenSSL on *nix, SChannel on Windows, Secure Transport on macOS).
2023-02-02 00:47:29 +00:00
2023-05-04 19:59:35 +00:00
- `tls-rustls` : Use the `rustls` TLS backend (cross-platform backend, only supports TLS 1.2 and 1.3).
2023-02-02 00:47:29 +00:00
2020-10-20 10:21:01 +00:00
- `postgres` : Add support for the Postgres database server.
2020-07-27 09:11:46 +00:00
2020-12-22 11:27:08 +00:00
- `mysql` : Add support for the MySQL/MariaDB database server.
2020-10-20 10:29:24 +00:00
- `mssql` : Add support for the MSSQL database server.
2020-07-14 13:33:36 +00:00
2020-10-20 10:29:24 +00:00
- `sqlite` : Add support for the self-contained [SQLite ](https://sqlite.org/ ) database engine.
2020-07-27 09:11:46 +00:00
2020-10-20 10:29:24 +00:00
- `any` : Add support for the `Any` database driver, which can proxy to a database driver at runtime.
2020-10-14 13:53:20 +00:00
2023-05-04 19:59:35 +00:00
- `macros` : Add support for the `query*!` macros, which allows compile-time checked queries.
2020-07-14 13:33:36 +00:00
2020-10-20 10:29:24 +00:00
- `migrate` : Add support for the migration management and `migrate!` macro, which allow compile-time embedded migrations.
2020-07-14 13:33:36 +00:00
2020-10-20 10:29:24 +00:00
- `uuid` : Add support for UUID (in Postgres).
2020-07-14 13:33:36 +00:00
2020-10-20 10:29:24 +00:00
- `chrono` : Add support for date and time types from `chrono` .
2020-07-14 13:33:36 +00:00
2021-02-19 05:17:40 +00:00
- `time` : Add support for date and time types from `time` crate (alternative to `chrono` , which is preferred by `query!` macro, if both enabled)
2020-07-30 03:57:18 +00:00
2020-11-21 21:58:48 +00:00
- `bstr` : Add support for `bstr::BString` .
2020-10-20 10:29:24 +00:00
- `bigdecimal` : Add support for `NUMERIC` using the `bigdecimal` crate.
2020-07-14 13:33:36 +00:00
2023-07-14 19:30:11 +00:00
- `rust_decimal` : Add support for `NUMERIC` using the `rust_decimal` crate.
2020-02-29 19:38:48 +00:00
2020-10-20 10:29:24 +00:00
- `ipnetwork` : Add support for `INET` and `CIDR` (in postgres) using the `ipnetwork` crate.
- `json` : Add support for `JSON` and `JSONB` (in postgres) using the `serde_json` crate.
2023-03-16 22:15:58 +00:00
- Offline mode is now always enabled. See [sqlx-cli/README.md][readme-offline].
2021-11-10 01:35:37 +00:00
[readme-offline]: sqlx-cli/README.md#enable-building-in-offline-mode-with-query
2021-05-30 22:52:25 +00:00
## SQLx is not an ORM!
SQLx supports **compile-time checked queries** . It does not, however, do this by providing a Rust
API or DSL (domain-specific language) for building queries. Instead, it provides macros that take
2023-05-04 19:59:35 +00:00
regular SQL as input and ensure that it is valid for your database. The way this works is that
2021-05-30 22:52:25 +00:00
SQLx connects to your development DB at compile time to have the database itself verify (and return
some info on) your SQL queries. This has some potentially surprising implications:
- Since SQLx never has to parse the SQL string itself, any syntax that the development DB accepts
can be used (including things added by database extensions)
- Due to the different amount of information databases let you retrieve about queries, the extent of
SQL verification you get from the query macros depends on the database
2021-12-27 22:09:20 +00:00
**If you are looking for an (asynchronous) ORM,** you can check out [`ormx`] or [`SeaORM`], which is built on top
2021-05-30 22:52:25 +00:00
of SQLx.
[`ormx`]: https://crates.io/crates/ormx
2021-12-27 22:09:20 +00:00
[`SeaORM`]: https://github.com/SeaQL/sea-orm
2020-03-28 00:42:23 +00:00
## Usage
2019-12-28 09:37:02 +00:00
2021-11-10 01:55:55 +00:00
See the `examples/` folder for more in-depth usage.
2020-03-28 00:42:23 +00:00
### Quickstart
2020-10-22 19:14:41 +00:00
2020-03-28 00:42:23 +00:00
```rust
2020-07-27 09:11:46 +00:00
use sqlx::postgres::PgPoolOptions;
// use sqlx::mysql::MySqlPoolOptions;
2020-03-28 00:42:23 +00:00
// etc.
2020-12-19 05:29:38 +00:00
#[async_std::main]
// or #[tokio::main]
2021-11-10 01:24:09 +00:00
// or #[actix_web::main]
2020-03-28 00:42:23 +00:00
async fn main() -> Result< (), sqlx::Error> {
// Create a connection pool
2020-12-19 05:29:38 +00:00
// for MySQL, use MySqlPoolOptions::new()
// for SQLite, use SqlitePoolOptions::new()
// etc.
2020-07-14 13:33:36 +00:00
let pool = PgPoolOptions::new()
2020-07-12 11:42:48 +00:00
.max_connections(5)
2020-10-22 12:43:23 +00:00
.connect("postgres://postgres:password@localhost/test").await?;
2020-07-14 13:33:36 +00:00
2021-09-20 23:35:27 +00:00
// Make a simple query to return the given parameter (use a question mark `?` instead of `$1` for MySQL)
2020-03-28 00:42:23 +00:00
let row: (i64,) = sqlx::query_as("SELECT $1")
.bind(150_i64)
.fetch_one(&pool).await?;
2020-07-14 13:33:36 +00:00
2020-03-28 00:42:23 +00:00
assert_eq!(row.0, 150);
Ok(())
}
```
2020-01-15 09:27:19 +00:00
2020-03-28 00:42:23 +00:00
### Connecting
2020-07-14 13:33:36 +00:00
A single connection can be established using any of the database connection types and calling `connect()` .
2020-01-15 09:27:19 +00:00
```rust
2020-07-27 09:11:46 +00:00
use sqlx::Connection;
2020-03-28 00:42:23 +00:00
let conn = SqliteConnection::connect("sqlite::memory:").await?;
2020-01-15 09:27:19 +00:00
```
2023-05-04 19:59:35 +00:00
Generally, you will want to instead create a connection pool (`sqlx::Pool`) for the application to
2020-03-28 00:42:23 +00:00
regulate how many server-side connections it's using.
```rust
2020-07-27 09:11:46 +00:00
let pool = MySqlPool::connect("mysql://user:pass@host/database").await?;
2020-07-14 13:33:36 +00:00
```
2020-03-28 00:42:23 +00:00
### Querying
2020-01-15 09:27:19 +00:00
2020-03-28 00:42:23 +00:00
In SQL, queries can be separated into prepared (parameterized) or unprepared (simple). Prepared queries have their
query plan _cached_ , use a binary mode of communication (lower bandwidth and faster decoding), and utilize parameters
2023-05-04 19:59:35 +00:00
to avoid SQL injection. Unprepared queries are simple and intended only for use where a prepared statement
2020-07-14 13:33:36 +00:00
will not work, such as various database commands (e.g., `PRAGMA` or `SET` or `BEGIN` ).
2020-03-28 00:42:23 +00:00
2023-05-04 19:59:35 +00:00
SQLx supports all operations with both types of queries. In SQLx, a `&str` is treated as an unprepared query,
2020-03-28 00:42:23 +00:00
and a `Query` or `QueryAs` struct is treated as a prepared query.
2019-12-28 09:37:02 +00:00
```rust
2020-03-28 00:42:23 +00:00
// low-level, Executor trait
conn.execute("BEGIN").await?; // unprepared, simple query
conn.execute(sqlx::query("DELETE FROM table")).await?; // prepared, cached query
```
2023-05-04 19:59:35 +00:00
We should prefer to use the high-level `query` interface whenever possible. To make this easier, there are finalizers
2020-03-28 00:42:23 +00:00
on the type to avoid the need to wrap with an executor.
```rust
sqlx::query("DELETE FROM table").execute(& mut conn).await?;
sqlx::query("DELETE FROM table").execute(&pool).await?;
```
2020-07-14 13:33:36 +00:00
The `execute` query finalizer returns the number of affected rows, if any, and drops all received results.
2021-01-23 16:18:00 +00:00
In addition, there are `fetch` , `fetch_one` , `fetch_optional` , and `fetch_all` to receive results.
2020-03-28 00:42:23 +00:00
The `Query` type returned from `sqlx::query` will return `Row<'conn>` from the database. Column values can be accessed
2020-07-14 13:33:36 +00:00
by ordinal or by name with `row.get()` . As the `Row` retains an immutable borrow on the connection, only one
2020-03-28 00:42:23 +00:00
`Row` may exist at a time.
The `fetch` query finalizer returns a stream-like type that iterates through the rows in the result sets.
```rust
2020-07-27 09:11:46 +00:00
// provides `try_next`
use futures::TryStreamExt;
let mut rows = sqlx::query("SELECT * FROM users WHERE email = ?")
2020-03-28 00:42:23 +00:00
.bind(email)
2020-05-28 16:48:08 +00:00
.fetch(& mut conn);
2020-03-28 00:42:23 +00:00
2020-07-27 09:11:46 +00:00
while let Some(row) = rows.try_next().await? {
2020-07-14 13:33:36 +00:00
// map the row into a user-defined domain type
2020-07-27 09:11:46 +00:00
let email: & str = row.try_get("email")?;
2020-03-28 00:42:23 +00:00
}
```
2023-05-04 19:59:35 +00:00
To assist with mapping the row into a domain type, one of two idioms may be used:
2020-03-28 00:42:23 +00:00
```rust
let mut stream = sqlx::query("SELECT * FROM users")
.map(|row: PgRow| {
// map the row into a user-defined domain type
})
.fetch(& mut conn);
```
```rust
2020-04-13 19:15:12 +00:00
#[derive(sqlx::FromRow)]
2020-03-28 00:42:23 +00:00
struct User { name: String, id: i64 }
let mut stream = sqlx::query_as::< _ , User > ("SELECT * FROM users WHERE email = ? OR name = ?")
.bind(user_email)
.bind(user_name)
.fetch(& mut conn);
2019-12-28 09:37:02 +00:00
```
2020-07-14 13:33:36 +00:00
Instead of a stream of results, we can use `fetch_one` or `fetch_optional` to request one required or optional result
2020-03-28 00:42:23 +00:00
from the database.
### Compile-time verification
2020-01-15 09:27:19 +00:00
2020-07-14 13:33:36 +00:00
We can use the macro, `sqlx::query!` to achieve compile-time syntactic and semantic verification of the SQL, with
2020-03-28 00:42:23 +00:00
an output to an anonymous record type where each SQL column is a Rust field (using raw identifiers where needed).
2019-12-28 09:37:02 +00:00
```rust
let countries = sqlx::query!(
2020-03-28 00:42:23 +00:00
"
2020-07-14 13:33:36 +00:00
SELECT country, COUNT(*) as count
FROM users
GROUP BY country
2020-03-28 00:42:23 +00:00
WHERE organization = ?
2020-07-14 13:33:36 +00:00
",
2019-12-28 09:37:02 +00:00
organization
)
2020-04-11 11:17:36 +00:00
.fetch_all(& pool) // -> Vec< { country: String, count: i64 }>
2019-12-28 09:37:02 +00:00
.await?;
2020-03-28 00:42:23 +00:00
// countries[0].country
// countries[0].count
2019-12-28 09:37:02 +00:00
```
2020-03-28 00:42:23 +00:00
Differences from `query()` :
2020-07-14 13:33:36 +00:00
2020-10-20 10:29:24 +00:00
- The input (or bind) parameters must be given all at once (and they are compile-time validated to be
the right number and the right type).
2020-07-14 13:33:36 +00:00
2020-10-20 10:29:24 +00:00
- The output type is an anonymous record. In the above example the type would be similar to:
2020-07-14 13:33:36 +00:00
2020-03-28 00:42:23 +00:00
```rust
{ country: String, count: i64 }
2020-07-14 13:33:36 +00:00
```
2020-10-20 10:29:24 +00:00
- The `DATABASE_URL` environment variable must be set at build time to a database which it can prepare
queries against; the database does not have to contain any data but must be the same
kind (MySQL, Postgres, etc.) and have the same schema as the database you will be connecting to at runtime.
2020-07-14 13:33:36 +00:00
2022-07-28 21:33:44 +00:00
For convenience, you can use [a `.env` file][dotenv]< sup > 1</ sup > to set DATABASE_URL so that you don't have to pass it every time:
2020-07-14 13:33:36 +00:00
2020-10-20 10:29:24 +00:00
```
DATABASE_URL=mysql://localhost/my_database
```
2020-03-28 00:42:23 +00:00
2021-11-10 01:16:00 +00:00
[dotenv]: https://github.com/dotenv-rs/dotenv#examples
2020-07-14 13:33:36 +00:00
The biggest downside to `query!()` is that the output type cannot be named (due to Rust not
2021-05-30 22:52:25 +00:00
officially supporting anonymous records). To address that, there is a `query_as!()` macro that is
mostly identical except that you can name the output type.
2020-03-28 00:42:23 +00:00
```rust
// no traits are needed
struct Country { country: String, count: i64 }
let countries = sqlx::query_as!(Country,
"
2020-07-14 13:33:36 +00:00
SELECT country, COUNT(*) as count
FROM users
GROUP BY country
2020-03-28 00:42:23 +00:00
WHERE organization = ?
2020-07-14 13:33:36 +00:00
",
2020-03-28 00:42:23 +00:00
organization
)
2020-10-29 20:46:05 +00:00
.fetch_all(& pool) // -> Vec< Country >
2020-03-28 00:42:23 +00:00
.await?;
2020-01-30 11:34:09 +00:00
2020-03-28 00:42:23 +00:00
// countries[0].country
// countries[0].count
```
2019-12-28 09:41:07 +00:00
2021-05-30 22:52:25 +00:00
To avoid the need of having a development database around to compile the project even when no
modifications (to the database-accessing parts of the code) are done, you can enable "offline mode"
to cache the results of the SQL query analysis using the `sqlx` command-line tool. See
[sqlx-cli/README.md ](./sqlx-cli/README.md#enable-building-in-offline-mode-with-query ).
2023-05-04 19:59:35 +00:00
Compile-time verified queries do quite a bit of work at compile time. Incremental actions like
2022-02-16 04:14:41 +00:00
`cargo check` and `cargo build` can be significantly faster when using an optimized build by
putting the following in your `Cargo.toml` (More information in the
[Profiles section ](https://doc.rust-lang.org/cargo/reference/profiles.html ) of The Cargo Book)
```toml
[profile.dev.package.sqlx-macros]
opt-level = 3
```
2022-07-28 21:33:44 +00:00
< sup > 1</ sup > The `dotenv` crate itself appears abandoned as of [December 2021 ](https://github.com/dotenv-rs/dotenv/issues/74 )
so we now use the `dotenvy` crate instead. The file format is the same.
2019-12-28 01:31:01 +00:00
## Safety
2019-08-07 05:47:32 +00:00
2020-07-14 13:33:36 +00:00
This crate uses `#![forbid(unsafe_code)]` to ensure everything is implemented in 100% Safe Rust.
2020-03-28 00:42:23 +00:00
2020-07-14 13:33:36 +00:00
If the `sqlite` feature is enabled, this is downgraded to `#![deny(unsafe_code)]` with `#![allow(unsafe_code)]` on the
2020-03-30 23:39:59 +00:00
`sqlx::sqlite` module. There are several places where we interact with the C SQLite API. We try to document each call for the invariants we're assuming. We absolutely welcome auditing of, and feedback on, our unsafe code usage.
2019-06-09 16:38:10 +00:00
2019-06-06 13:02:55 +00:00
## License
Licensed under either of
2020-10-20 10:29:24 +00:00
- Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
2019-06-06 13:02:55 +00:00
at your option.
## Contribution
2023-05-04 19:59:35 +00:00
Unless you explicitly state otherwise, any Contribution intentionally submitted
2019-06-06 13:02:55 +00:00
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.