A safe, extensible ORM and Query Builder for Rust
Go to file
Sean Griffin ccad1510c1 Reform types inferred by infer_schema! on SQLite (#277)
`infer_schema!` is woefully undertested. Really our tests for it at the
moment are "we use it for our test suite so the cases our suite covers
work". However, even though I defined `tinyint` == `Bool`, I wanted to
make sure that `TINYINT(1)` was treated as bool as well, as I wasn't
certain how SQLite handles limit/precision/scale.

The answer is that it doesn't, and it's way looser about allowed type
names than I had thought. The process listed at
https://www.sqlite.org/datatype3.html is a literal description, and any
possible string is a valid type.

This adds tests for every example given on that page, plus a few extras.
We create a table with as many of these fields as possible, and do a
trivial roundtrip to make sure that it *actually* infers something we
can deserialize from, and that we're not doing anything dumb.

The new logic for type inference matches pretty closely to how SQLite
handles things with a few exceptions:

- "boolean" or types containing "tiny" and "int" are treated as bool
- smallint and bigint are separated from int
- float is separated from double
- varchar is separated from text
- We do not accept random unrecognized type names as numeric

Unresolved Questions
--------------------

This actually starts to make me a bit more nervous about our semantics
with SQLite. If you're just using Diesel, everything is fine. However,
you can definitely insert values that would fail to deserialize with so
little constraints on the backend. I'm starting to wonder if we should
truly embrace SQLite's definitions and map exactly to that, allowing
only the following types:

- BigInt
- VarChar (yes, it's the ANSI text type but we treat VarChar as the
  "default" string type)
- Binary
- Double

We're omitting numeric, as there's no observable difference in SQLite
between the real affinity and the numeric affinity.

This would have several *major* implications. Aside from not being able
to use basic things like an `i32`, it would also mean that there is no
boolean type, and no dates/times/datetimes. Functions for those do exist
on the SQLite side though, so some of the interactions might get super
janky.

That said, Diesel's goal is not to abstract away the backend. These are
the semantics of the backend chosen, and maybe we should go whole hog
and embrace them.

I'm still unsure. In the meantime, with our current semantics, this
should improve the reliability of `infer_schema!`
2016-04-17 14:42:11 -06:00
.cargo Point diesel_codegen back at git, use local override for dev 2015-12-06 08:24:05 -06:00
bin Properly set DATABASE_URL for SQLite benchmarks 2016-04-17 11:10:41 -06:00
diesel Allow migrations to be embedded in the resulting binary 2016-04-16 13:51:12 -06:00
diesel_cli Release v0.6.1 2016-04-16 09:01:25 -06:00
diesel_codegen Reform types inferred by infer_schema! on SQLite (#277) 2016-04-17 14:42:11 -06:00
diesel_compile_tests Change bind collection to be a 2-pass process (#266) 2016-04-16 09:18:00 -06:00
diesel_tests Reform types inferred by infer_schema! on SQLite (#277) 2016-04-17 14:42:11 -06:00
migrations Reform types inferred by infer_schema! on SQLite (#277) 2016-04-17 14:42:11 -06:00
.example.env Remove DATABASE_URL_FOR_SCHEMA from .example.env 2015-12-19 13:31:39 -07:00
.gitignore add Cargo.lock for diesel_cli 2016-03-19 13:08:23 +01:00
.travis.yml Fix travis build (again) 2016-04-12 12:20:21 -06:00
CHANGELOG.md Reform types inferred by infer_schema! on SQLite (#277) 2016-04-17 14:42:11 -06:00
code_of_conduct.md Bump code of conduct to CC 1.4 2016-02-02 20:00:21 -07:00
LICENSE-APACHE Relicense under dual MIT/Apache-2.0 2016-01-11 09:46:33 -07:00
LICENSE-MIT Relicense under dual MIT/Apache-2.0 2016-01-11 09:46:33 -07:00
README.md Newline before link in README 2016-02-11 10:07:12 -07:00

A safe, extensible ORM and Query Builder for Rust

Build Status Gitter

Documentation

Homepage

Diesel gets rid of the boilerplate for database interaction and eliminates runtime errors, without sacrificing performance. It takes full advantage of Rust's type system to create a low overhead query builder that "feels like Rust".

Getting Started

You can find an extensive Getting Started tutorial at http://diesel.rs/guides/getting-started. Guides on more specific features will be coming soon.

Code of conduct

Anyone who interacts with Diesel in any space including but not limited to this GitHub repository is expected to follow our code of conduct

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted 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.