-
-
Notifications
You must be signed in to change notification settings - Fork 67
jiff-sqlx: add integration crate for SQLx #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
{ | ||
"rust-analyzer.linkedProjects": [ | ||
"bench/Cargo.toml", | ||
"examples/sqlx-postgres/Cargo.toml", | ||
"examples/sqlx-sqlite/Cargo.toml", | ||
"Cargo.toml" | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This project is dual-licensed under the Unlicense and MIT licenses. | ||
|
||
You may use this code under the terms of either license. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[package] | ||
name = "jiff-sqlx" | ||
version = "0.0.1" #:version | ||
authors = ["Andrew Gallant <[email protected]>"] | ||
license = "Unlicense OR MIT" | ||
homepage = "https://github.com/BurntSushi/jiff/tree/master/crates/jiff-sqlx" | ||
repository = "https://github.com/BurntSushi/jiff" | ||
documentation = "https://docs.rs/jiff-sqlx" | ||
description = "Integration for Jiff in sqlx." | ||
categories = ["date-and-time"] | ||
keywords = ["date", "time", "jiff", "sqlx", "zone"] | ||
workspace = "../.." | ||
edition = "2021" | ||
rust-version = "1.70" | ||
include = ["/*.rs", "/*.dat", "COPYING", "LICENSE-MIT", "UNLICENSE"] | ||
|
||
[lib] | ||
name = "jiff_sqlx" | ||
bench = false | ||
path = "src/lib.rs" | ||
|
||
[features] | ||
default = [] | ||
postgres = ["dep:sqlx-postgres"] | ||
sqlite = ["dep:sqlx-sqlite"] | ||
|
||
[dependencies] | ||
jiff = { path = "../..", default-features = false } | ||
sqlx-core = { version = "0.8.0", default-features = false } | ||
sqlx-postgres = { version = "0.8.0", default-features = false, optional = true } | ||
sqlx-sqlite = { version = "0.8.0", default-features = false, optional = true } | ||
|
||
[dev-dependencies] | ||
jiff = { path = "../..", default-features = true } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Andrew Gallant | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
jiff-icu | ||
======== | ||
WIP | ||
|
||
### Documentation | ||
|
||
https://docs.rs/jiff-icu |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
This is free and unencumbered software released into the public domain. | ||
|
||
Anyone is free to copy, modify, publish, use, compile, sell, or | ||
distribute this software, either in source code form or as a compiled | ||
binary, for any purpose, commercial or non-commercial, and by any | ||
means. | ||
|
||
In jurisdictions that recognize copyright laws, the author or authors | ||
of this software dedicate any and all copyright interest in the | ||
software to the public domain. We make this dedication for the benefit | ||
of the public at large and to the detriment of our heirs and | ||
successors. We intend this dedication to be an overt act of | ||
relinquishment in perpetuity of all present and future rights to this | ||
software under copyright law. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
For more information, please refer to <http://unlicense.org/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*! | ||
This crate provides integration points for [Jiff](jiff) and [SQLx][sqlx]. | ||
|
||
Examples can be found in the | ||
[examples directory of the Jiff repository][examples]. | ||
|
||
# Organization | ||
|
||
This crates defines several types that wrap corresponding types in Jiff. Each | ||
wrapper type provides implementations of traits found in SQLx. For most types, | ||
these are the [`sqlx_core::types::Type`], [`sqlx_core::decode::Decode`] and | ||
[`sqlx_core::encode::Encode`] traits. | ||
|
||
The intended workflow is to use these wrapper types within your wire types for | ||
encoding and decoding data from databases such as PostgreSQL. The wrapper types | ||
own the logic for encoding and decoding the data in database specific formats. | ||
|
||
In order to the minimize the annoyance of wrapper types, the following | ||
conveniences are afforded: | ||
|
||
* A [`ToSqlx`] trait is provided. Several Jiff types implement this trait. The | ||
trait provides easy conversion to the corresponding wrapper type in this crate. | ||
* A concrete `to_jiff` method is provided on each wrapper type. For example, | ||
[`Timestamp::to_jiff`]. This method is the reverse of `ToSqlx`. This converts | ||
from the wrapper type to the corresponding Jiff type. | ||
* There are `From` trait implementations from the wrapper type to the | ||
corresponding Jiff type, and vice versa. | ||
|
||
# Database support | ||
|
||
At present, both PostgreSQL and SQLite are supported. | ||
|
||
Ideally, MySQL support would be present too, but it | ||
[appears impossible until SQLx exposes some APIs][sqlx-mysql-bunk]. | ||
|
||
# Future | ||
|
||
This crate exists because there are generally only three ways to implement | ||
the necessary traits in SQLx: | ||
|
||
1. Make Jiff depend on SQLx, and implement the corresponding traits where | ||
Jiff's types are defined. | ||
2. Make SQLx depend on Jiff, and implement the corresponding traits where the | ||
traits are defined. | ||
3. Make a crate like this one with types that wrap Jiff's types, and implements | ||
the corresponding traits for the wrapper types. | ||
|
||
This was done because it seems inappropriate for a "lower level" crate like | ||
Jiff to depend on SQLx. And while it might be appropriate for SQLx to optionally | ||
depend on Jiff (like it does for [`chrono`] or [`time`]), at time of writing, | ||
Jiff is still early in its life. It's totally reasonable to wait for it to | ||
mature. Plus, the thought of three different datetime integrations is, | ||
admittedly, tough to stomach. | ||
|
||
In the future, it may be prudent for this crate to be upstreamed into SQLx | ||
itself. | ||
|
||
[sqlx]: https://docs.rs/sqlx/0.8 | ||
[examples]: https://github.com/BurntSushi/jiff/tree/master/examples/uptime | ||
[`chrono`]: https://docs.rs/chrono | ||
[`time`]: https://docs.rs/time | ||
[sqlx-mysql-bunk]: https://github.com/launchbadge/sqlx/issues/3487#issuecomment-2641843693 | ||
*/ | ||
|
||
#![deny(missing_docs)] | ||
|
||
pub use self::wrappers::{Date, DateTime, Span, Time, Timestamp, ToSqlx}; | ||
|
||
#[cfg(feature = "postgres")] | ||
mod postgres; | ||
#[cfg(feature = "sqlite")] | ||
mod sqlite; | ||
mod wrappers; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BurntSushi I just noticed this while working on my own example for launchbadge/sqlx. These crates are semver-exempt, it's not recommended to depend on them directly without pinning the version: https://docs.rs/sqlx-core/latest/sqlx_core/#note-semver-exempt-api
Is there a particular reason you didn't just use the
sqlx
crate? I don't see any relevant discussion in #50 or #141 (which actually did usesqlx
). I don't see any private types being used here.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm I honestly don't remember. I think I was just trying to use the minimal number of dependencies as I could and this "worked" as far as I could tell.
Honestly the whole process of adding an integration crate was quite difficult from the perspective of someone who doesn't actually use SQLx. There was a lot of guesswork involved and "okay the
chrono
integration does things this way so I'll do it that way too" style of reasoning.I did not see the note about semver being an exempt. I created #322 to track fixing this. Thank you for flagging this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well honestly, no one's ever really bothered before. They usually just insist on upstreaming it into SQLx, even when, in retrospect, it doesn't make a whole lot of sense (supporting the whole
git2
crate for just one type was a huge headache because of the native code dependency).This wouldn't be a problem if
jiff
wasn't so young still.time
andchrono
have been on their current major versions for years now. Whenjiff
is at that point, or you're ready to release a 1.0, I'd be happy to talk about upstreaming.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I plan to release 1.0 this summer and commit to it indefinitely.
And yeah I added the ecosystem crates because I perceived it as one the main reasons why folks were bouncing of Jiff.
It's a nasty chicken and egg problem.