Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sqlx-sqlite/src/types/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ fn decode_datetime_from_text(value: &str) -> Option<PrimitiveDateTime> {
None
}

#[allow(deprecated)]
mod formats {
use time::format_description::BorrowedFormatItem::{Component, Literal, Optional};
use time::format_description::{modifier, BorrowedFormatItem, Component::*};
Expand Down
26 changes: 26 additions & 0 deletions tests/sqlite/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,29 @@ async fn test_column_override_exact_nullable() -> anyhow::Result<()> {
}

// we don't emit bind parameter typechecks for SQLite so testing the overrides is redundant

#[sqlx_macros::test]
async fn test_returning_primary_key_is_not_nullable() -> anyhow::Result<()> {
let mut conn = new::<Sqlite>().await?;
let id: i64 =
sqlx::query_scalar!(r#"INSERT INTO accounts ( name ) VALUES ( 'test' ) RETURNING id"#)
.fetch_one(&mut conn)
.await?;
assert!(id > 0);
Ok(())
}

#[sqlx_macros::test]
async fn test_returning_with_foreign_key_is_not_nullable() -> anyhow::Result<()> {
let mut conn = new::<Sqlite>().await?;
sqlx::query("INSERT INTO projects ( project_id ) VALUES ( 1 )")
.execute(&mut conn)
.await?;
let _id: i64 = sqlx::query_scalar!(
r#"INSERT INTO packages ( project_id ) VALUES ( 1 ) RETURNING package_id"#
)
.fetch_one(&mut conn)
.await?;

Ok(())
}
9 changes: 9 additions & 0 deletions tests/sqlite/setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ CREATE TABLE products (
price NUMERIC,
CONSTRAINT price_greater_than_zero CHECK (price > 0)
);
--
CREATE TABLE projects (
project_id INTEGER PRIMARY KEY
);
CREATE TABLE packages (
package_id INTEGER PRIMARY KEY NOT NULL CHECK(package_id >= 0),
project_id INTEGER NOT NULL,
FOREIGN KEY(project_id) REFERENCES projects(project_id)
);
Binary file modified tests/sqlite/sqlite.db
Binary file not shown.
Loading