This change will attempt to load an .env file from CARGO_MANIFEST_DIR, if it exists.
For backwards compatibility, if the .env file does not exist, we will fall back to default dotenv behaviour.
Resolves#267
Before, the query would be formatted equivalent to the input string:
```
[2020-04-18T23:47:32Z DEBUG sqlx_core::postgres::executor] SELECT id, queue, ..., elapsed: 2.320µs
SELECT id, queue, payload, status, priority, created_at, updated_at
FROM jobs
WHERE status = $1
ORDER BY priority ASC, created_at ASC
```
After, the query is formatted cleanly and consistently:
```
[2020-04-19T00:30:18Z DEBUG sqlx_core::postgres::executor] SELECT id, queue, ..., elapsed: 2.280µs
SELECT
id,
queue,
payload,
status,
priority,
created_at,
updated_at
FROM
jobs
WHERE
status = $1
ORDER BY
priority ASC,
created_at ASC
```
This uses the `sqlformat` crate, which was ported from the
Javascript `sql-formatter-plus` library specifically for this purpose.
Since the implementation of Encode and Decode for both mysql and
postgres on serde's Value and RawValue were practically the same they
were moved to the generic json module.
Prints each query performed at DEBUG level,
along with a timing of how long the query took
to execute.
Slow queries will be printed at WARN level.
Currently the slow query threshold is
hardcoded to 1 second.
* Adds tables for storing articles, tags, favorites, and comments.
* Implements all remaining web APIs (articles, tags, profiles, etc)
* Refactors `Provide` traits into
* `ProvideAuthn` is used to store/retrieve user info
* `ProvideData` is used to retrieve application data
* ` Provide` traits are now implemented on Connections instead of Pools
* Introduces `Db` trait that encapsulates DB connections
* Cleans up endpoint functions
**General**
* Moves `examples/postgres/realworld` to `examples/realworld`
* The app is now architected to support multiple DBs
* Adds feature flags for `sqlite` and `postgres` to allow user to choose
which backend to use
*NOTE* Currently it is not possible to compile with `postgres` and `sqlite`
enabled as we are using the `query!` and `query_as!` macros and they
seem to get unhappy.
* Adds CLI flags for picking the DB backend to use at runtime
* Adds schema file and implementation for SQLite for `/api/user` routes
* Adds stub routes and trait for articles and Articles entity
**Changes**
* We now use i32 instead of i64 as the user_id to get around some quirks
w/ the SQLite driver.
* Reimplements existing route handlers w/ an error handling shim so we can use
Try inside the biz logic
* *FIX* Adds a `user` key to the register user body to conform w/ realworld's
API specs
APIs were functionally tested using realworld's API test script
(https://github.com/gothinkster/realworld/tree/master/api#authentication)
I encountered a use case while converting a project
from Diesel to sqlx, where I had a custom Postgres enum
which included a snake case field name:
```rust
pub enum JobStatus {
NotRun,
Finished,
Failed,
}
```
Which translates to:
```sql
CREATE TYPE job_status AS ENUM ('not_run', 'finished', 'failed');
```
This is likely to be a semi-common use case,
so this commit adds snake case support for enums
via the `#[sqlx(rename_all = "snake_case")]` attribute.