Commit Graph

484 Commits

Author SHA1 Message Date
Georg Semmler
f445bc1cbf
Merge pull request #2827 from weiznich/prepared_statements_for_certain_insert_variants
Various insert improvments
2021-08-12 09:12:41 +00:00
Jiří Sejkora
e81c58763d
Fix typo in code sample in 2.0 changelog
The real name of the type is `EmbeddedMigrations`.
2021-08-07 05:49:13 +02:00
Georg Semmler
d5f60ad952
Various insert improvments
* Cache insert statments from queries, as those are safe to cache if the
  query itself is safe to cache
* Add a way to directly insert from a statically sized array
* Decouple default values from insert expressions and allow to generate
  insertable implementations that do not use the default values.
   + This unblocks real batch inserts on sqlite
   + This allows cache the prepared statements for insert from statically sized arrays as we know the size at compile time here
* Update the benchmarks to use the statically compile time variant.
  Other implementations also use prepared statements here, so this is
just fair
2021-07-27 13:27:40 +02:00
Georg Semmler
ed2fc1477d
Readd missing changlog entry 2021-06-23 08:51:06 +02:00
Georg Semmler
2b03ce3d31
Generate SQL type definitions for unknown types
This commit adds support for generating SQL type definitions for unknown
types to `diesel print-schema`. The basic idea is to generate the
corresponding marker type to always end up with an existing schema.
Especially this does not generate any code that is required for
serializing/deserializing rust values.
2021-06-22 11:16:20 +02:00
Filip Gospodinov
878de33f83 Add support for no argument functions for Sqlite
Closes #2790
2021-05-25 16:42:09 +02:00
Georg Semmler
cfb9506715
Interacting with the database requires a mutable connection
This commit changes all connection implementations to take `&mut self`
on all methods that interact with the database.
This unblocks the following features:

* Returnig a cursor/iterator from a `RunQueryDsl` method
* Removing some unsafe code and interior mutability inside the current
  connection implementations
* Possibly the first step of a async `Connection` variant to workaround
  the `Future` not `Send` issues there.
2021-05-18 10:08:48 +02:00
hi-rustin
78295d4009 Add changelog 2021-04-27 22:08:51 +08:00
Pavan Kumar Sunkara
4dfb934603
Merge pull request #2738 from hi-rustin/rustin-patch-SQLITE
Added support for SQLite's `IS` and `IS NOT`
2021-04-21 19:07:25 +01:00
hi-rustin
11f4369ca5 Added support for SQLite's IS and IS NOT 2021-04-21 17:13:30 +08:00
Lukas Markeffsky
a1adbcb60f more tests, improve docs, update changelog 2021-04-19 14:33:32 +02:00
Georg Semmler
125072fa85
Apply suggestions from code review 2021-04-15 16:51:29 +00:00
Georg Semmler
bfcf3d58ee
Cleanup catch_unwind handling
This fixes the handling of panics in custom SQLite functions
by having a `catch_unwind` before ffi the boundary and by correctly
setting the required `UnwindSafe` trait bounds in a similar way as it is
done by rusqlite.
2021-03-31 11:46:37 +02:00
Alexander 'z33ky' Hirsch
4307a11dd3
Expose sqlite's sqlite3_create_collation() 2021-03-29 11:11:14 +02:00
Georg Semmler
3653a5e992
Merge branch 'master' into rewrite/migrations 2021-03-22 09:30:27 +00:00
Georg Semmler
8f6e792caa
Update CHANGELOG.md
Co-authored-by: Henry Boisdequin <boisdequinhenry19@gmail.com>
2021-03-22 09:29:46 +00:00
Georg Semmler
a4fd10e9ee
Update CHANGELOG.md
Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
2021-03-21 10:34:40 +00:00
Georg Semmler
757842994c
Merge pull request #2676 from weiznich/bug/fix_potential_use_after_free
Bug/fix potential use after free
2021-03-19 08:18:06 +00:00
Georg Semmler
cc823ba4ef
Add a changelog entry 2021-03-18 15:22:13 +01:00
Georg Semmler
be80e62d99
Merge the updated changelog into master 2021-03-12 10:58:47 +01:00
Henry Boisdequin
238fe0bfa5 add changelog entry 2021-02-23 09:38:55 +05:30
Andrew Safigan
1c84f9fc69 docs: 📝 update the CHANGELOG 2021-02-11 12:22:16 -05:00
Georg Semmler
c48f40638c
Fix #1641
We enforce now that the order clause matches the corresponding
distinct_on clause. I've choosen to gate setting a distinct on clause on
having a corresponding order clause.
2021-01-28 15:51:46 +01:00
Georg Semmler
9635290484
Merge pull request #2599 from Ten0/faillible_queryable_stillgeneric
Faillible Queryable
2021-01-27 10:31:44 +00:00
Thomas BESSOU
7a79581439 Fix changelog after d2af2263
d2af2263c7 had to roll back the impl of `AsExpression<Nullable<sql_types::Bool>>` for `E: AsExpression<sql_types::Bool>`, to allow for more type inference, but forgot to remove the corresponding line in the changelog.
2021-01-26 14:42:17 +01:00
Thomas BESSOU
9275b9ae41 Add corresponding doc to the changelog 2021-01-26 14:38:40 +01:00
Grégory OBANOS
6c6fcc0003 Add changelog entry for combination queries 2020-12-03 15:04:57 +01:00
Georg Semmler
0493edb44a
Add a changelog entry 2020-11-27 09:39:40 +01:00
Iban Eguia
ce0dd4a4c6
Added a note in the changelog about the new minimum supported chrono version 2020-11-19 20:23:05 +01:00
Thomas Eizinger
cc8f0b7350
Support #[diesel(serialize_as)] on fields of Insertable structs
Similar to how `#[diesel(deserialize_as)]` can be used for `Queryable`
structs to customize which type is being constructed, we add support
for doing the same thing for `Insertable` structs.

The conversion happens using the std trait `Into` which takes ownership
during conversion. As such, as soon as any field within an `Insertable`
struct has a `#[diesel(serialize_as)]` attribute, we no longer generate
an implementation of `Insertable` for borrowed versions of this struct.

Fields annotated with `#[diesel(serialize_as)]` are also incompatible
with `#[diesel(embed)]`. Using both on the same field will result in
a compile-error.
2020-11-06 10:59:05 +11:00
Takayuki Maeda
5d1f6a3903 update CHANGELOG.md 2020-10-31 23:26:19 +09:00
Georg Semmler
ee00374f79
Merge pull request #2538 from film42/gt/sql_func_docs
Add docs to sql_function macro for functions without arguments
2020-10-14 10:06:42 +00:00
Garrett Thornburg
098554df84 Add docs for sql function without arguments
Add v1.4 upgrade comment to the CHANGELOG nodes
2020-10-13 23:02:12 -07:00
matthew-dowdell
8b9de9ed40 drop less useful line from changelog 2020-10-12 09:50:40 +01:00
matthew-dowdell
c09e562b60 Add additional PgTextExpressionMethods
- Adds support for PostgreSQL's `SIMILAR TO` and `NOT SIMILAR TO`.
- Adds support for `ESCAPE` to PostgreSQL's `ILIKE`, `NOT ILIKE`, `SIMILAR TO` and `NOT SIMILAR TO`.
- Adds doc tests for all of the above by repurposing existing tests that function the same.
2020-10-12 08:56:45 +01:00
Georg Semmler
7798cb346f
Fix #1638
Add a `without-deprecated` feature flag that really disables all
deprecated items
2020-10-08 10:21:28 +02:00
Georg Semmler
216f5ace72
Merge pull request #2520 from weiznich/fix/2140
Fix #2140
2020-10-05 15:32:50 +00:00
Georg Semmler
7ff5e6327d
Fix #2140
Include parenthesis around every infix operation provided by one of the
`ExpressionMethod` traits.

It is not possible to include this directly into the `infix_operator!`
macro due several SQL constructs:

* `a LIKE b` can have optional `ESCAPE` clauses (same for `NOT LIKE`,
`ILIKE` eg). Unconditionally putting a parenthesis around `(a LIKE b)`
is no valid SQL
* `a BETWEEN l AND u` is implemented a set of two infix operators,
`BETWEEN` and `AND`, so putting the parenthesis directly into the
operator macro would lead to `x BETWEEN (l AND u)` which is not valid
SQL

Instead I've opted for adding explicit parenthesis in the corresponding
`ExpressionMethod` (and similar traits` implementations. As part of this
change I've changed all the return types there to use some type from
`diesel::dsl`, so that potential users have an easier time to figure out
what types to use if they have to write some where clause or something
like that.

While changing the return types to `diesel::dsl` types I noticed  and
fixed the following issues:

* Not all methods had an equivalent type in `diesel::dsl`, sometimes
because it was missing, sometimes because the postgres specific types
weren't correctly exported there. Both is fixed now
* Some types were not anymore compatible with the actual methods. A
notable example is `dsl::And` and `BoolExpressionMethods::and` where the
later returned a potentially nullable type depending on the input types,
while the first was only valid for not nullable right sides. Fixing that
was a bit more complicated:
    * I've opted for making the return type of `BoolExpressionMethods::and`
      (and `or`) unconditonally nullable. This prevents having an explicit
     `ST` parameter on `dsl::And`
    * This in turn requires that we accept a non nullable expression in
      places where a nullable expression is expected. Technically this
      was already possible, but would require explicitly calling
      `.nullable()` on affected expressions. Given that `.and()` and
      `.or()` are really common, that seemed not to be a good solution.
      As result I've changed the `AsExpression` impl for `T: Expression`
      in such a way that for any `T` with `T::SqlType: SqlType<IsNull =
      is_nullable::NotNull>` there is now an impl
      `AsExpression<Nullable<T::SqlType>>` so that such expressions are
      also accepted in nullable contexts.
2020-10-05 16:42:48 +02:00
κeen
6f9f3eaf31 update changelog 2020-09-24 17:29:34 +09:00
Georg Semmler
9c48670e70
Remove support for the long deprecated time crate 2020-09-08 14:47:02 +02:00
Sean Griffin
f3f2767b4d
Deprecate no_arg_sql_function!
This makes the minor changes to `sql_function!` required to allow 0
argument functions to be defined with this macro. `no_arg_sql_function!`
has been deprecated. Even though we could technically remove it since
this is a major version bump, I still would prefer to deprecate things
when possible, so `no_arg_sql_function!` will live on until 3.0.

There are some changes in behavior here. The most notable is that we
generate a function rather than a unit struct. I had previously
considered having the macro create a unit struct instead of a module if
there were no arguments, but ultimately I think the difference in
behavior is confusing, and requiring folks to put `()` at the end of
calls isn't a huge migration pain.

The biggest thing that `sql_function!` doesn't support is the ability to
add a constraint to the backends allowed. This capability was originally
added for `NOW()`, back when we actually generated that SQL instead of
`CURRENT_TIMESTAMP`. We stopped using it a long time ago, and I doubt
anyone else is using this in the wild. Honestly it was a pretty poorly
thought out feature to begin with, so I'm happy to see it go. If we
decide in the future we want to support this for `sql_function!`, I
think the best way to do it is to allow `where` clauses at the end, and
any bounds that are on `DB` get magically applied to the write
impls/type variable. That behavior feels really implicit and confusing,
so I think we should probably just encourage folks to not use
`sql_function!` if they need lower level control.

One unfortunate side effect of this is that `now` still doesn't get
parenthesis, and we can't have a function and struct with the same name.
If we *really* want to migrate `now` to be consistent, we could
implement all the traits implemented on `now` for `fn() -> now`. This is
a terrible terrible awful hack but could actually work.
2020-08-08 01:18:57 +02:00
Georg Semmler
ee470bb07c
Rewrite our internal type system
(Sorry for the really large diff but this touches nearly all parts of
diesel)

This commit does in two things:
* Refactor our handling of nullable values. Instead of having a marker
trait for non nullable sql types we now indicate if a sql type is
nullable by using a associated type on a new fundamental trait named
SqlType. This allows us to reason if an type is nullable or not in a
much precise way without running in conflicting implementation
issues. This allows us to address #104 in a much more fundamental
way. (The correct way as mentioned there by sgrif).
* Refactor our handling of typed and untyped sql fragments. Instead of
having two separate code paths for `Queryable` (sql types known) and
`QueryableByName` (sql types not known) we now have only one code path
and indicate if a query is typed or untyped as part of the expression
sql type. This is required to address #2150. `Queryable` and
`QueryableByName` now simple . Additionally we separate the static size component of
`FromSqlRow` to allow dynamically sized rows there (but only at the
last position for tuple impls.)

I should probably have implement those changes in different commits
but as both changes basically requiring touching most of our code base
this would have required much more work...

Both changes are theoretically big major breaking changes. For
application code I expect the actual breakage to be minimal, see the
required changes in `diesel_tests` and `diesel_cli` for examples. For
highly generic code I would expect quite a few required changes.

Additionally there are a few small drive by fixes.

Fixes #104
Fixes #2274
Fixes #2161
2020-08-01 08:06:54 +02:00
Georg Semmler
9b76d54e7b
Merge pull request #2290 from weiznich/rebase/1457
Change MySQL's number handling to be more permissive
2020-06-10 11:37:33 +00:00
Georg Semmler
f783850698
Unify changelog entries regarding to MysqlType 2020-06-10 11:26:07 +02:00
Georg Semmler
ddf316e48c
Add release notes for 1.4.5 2020-06-09 13:32:23 +02:00
Georg Semmler
54ffbf3fa2
Add a changelog entry for mysql value change 2020-06-05 23:36:42 +02:00
Georg Semmler
419bc308fc
Verify that we build with MSRV + minimal dependencies
* Lower all dependencies to `-Z minimal-versions` in CI
* Raise the following public dependencies:
    * bigdecimal to 0.0.13 to drop support for old num versions
    * chrono to 0.4.1 because it pulls in a really old num from before
      the rust 1.0 release
    * pq-sys to 0.4.0 because 0.3.x pulls in a old bindgen version
    * mysqlclient-sys to 0.3.0 for the same reason
* Bump this internal dependencies:
    * syn to 1.0.1 because we require at least that version
    * num-* to 0.2.0 to match bigdecimal version
    * bcrypt to 0.2.0 because it would pull in rustc-serialize
      otherwise
    * tempfile to 3.0.0 because otherwise it pulls in winapi 0.0.1!!!
    * bitflags to 1.2.0 because of deprecation warnings regarding to try!
2020-05-29 11:37:15 +02:00
Andy Russell
7b61f53043
open SQLite connection with SQLITE_OPEN_URI 2020-05-20 23:25:26 -04:00
Matthew Kuo
c84de40a11
Merge branch 'master' into feature/2191-sqlite-custom-aggregate 2020-04-25 14:59:33 -05:00
Georg Semmler
4d6a088f33
Merge pull request #2374 from weiznich/non_exhaustive
Use `#[non_exhaustive]` instead of `__NonExhaustive` enum variants
2020-04-23 12:45:23 +00:00