Skip to content

Commit 73b5712

Browse files
committed
Merge branch 'master' into support-offline-workspaces
2 parents b4bff01 + ae2e5db commit 73b5712

File tree

13 files changed

+89
-24
lines changed

13 files changed

+89
-24
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ categories = [ "database", "asynchronous" ]
2626
authors = [
2727
2828
"Austin Bonander <[email protected]>", # [email protected]
29-
"Chloe Ross <[email protected]>", # zach@launchbadge.com
29+
"Chloe Ross <[email protected]>", # chloe@launchbadge.com
3030
"Daniel Akhterov <[email protected]>", # [email protected]
3131
]
3232

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ sqlx = { version = "0.4.0-beta.1", default-features = false, features = [ "runti
148148

149149
* `bigdecimal`: Add support for `NUMERIC` using the `bigdecimal` crate.
150150

151+
* `decimal`: Add support for `NUMERIC` using the `rust_decimal` crate.
152+
151153
* `ipnetwork`: Add support for `INET` and `CIDR` (in postgres) using the `ipnetwork` crate.
152154

153155
* `json`: Add support for `JSON` and `JSONB` (in postgres) using the `serde_json` crate.

sqlx-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2018"
88
authors = [
99
"Ryan Leckey <[email protected]>",
1010
"Austin Bonander <[email protected]>",
11-
"Zachery Gyurkovitz <zgyurkovitz@gmail.com>",
11+
"Chloe Ross <orangesnowfox@gmail.com>",
1212
"Daniel Akhterov <[email protected]>",
1313
]
1414

sqlx-core/src/postgres/connection/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ impl PgConnection {
7474

7575
if let MessageFormat::ReadyForQuery = message.format {
7676
self.handle_ready_for_query(message)?;
77-
break;
7877
}
7978
}
8079

sqlx-core/src/postgres/type_info.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,10 @@ impl TypeInfo for PgTypeInfo {
755755
fn is_null(&self) -> bool {
756756
false
757757
}
758+
759+
fn is_void(&self) -> bool {
760+
matches!(self.0, PgType::Void)
761+
}
758762
}
759763

760764
impl PartialEq<PgCustomType> for PgCustomType {

sqlx-core/src/sqlite/connection/establish.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
use std::io;
2-
use std::ptr::{null, null_mut};
3-
4-
use libsqlite3_sys::{
5-
sqlite3_busy_timeout, sqlite3_extended_result_codes, sqlite3_open_v2, SQLITE_OK,
6-
SQLITE_OPEN_CREATE, SQLITE_OPEN_MEMORY, SQLITE_OPEN_NOMUTEX, SQLITE_OPEN_PRIVATECACHE,
7-
SQLITE_OPEN_READONLY, SQLITE_OPEN_READWRITE,
8-
};
9-
use sqlx_rt::blocking;
10-
111
use crate::error::Error;
122
use crate::sqlite::connection::handle::ConnectionHandle;
133
use crate::sqlite::statement::StatementWorker;
144
use crate::{
155
common::StatementCache,
166
sqlite::{SqliteConnectOptions, SqliteConnection, SqliteError},
177
};
8+
use libsqlite3_sys::{
9+
sqlite3_busy_timeout, sqlite3_extended_result_codes, sqlite3_open_v2, SQLITE_OK,
10+
SQLITE_OPEN_CREATE, SQLITE_OPEN_MEMORY, SQLITE_OPEN_NOMUTEX, SQLITE_OPEN_PRIVATECACHE,
11+
SQLITE_OPEN_READONLY, SQLITE_OPEN_READWRITE,
12+
};
13+
use sqlx_rt::blocking;
14+
use std::io;
15+
use std::{
16+
convert::TryFrom,
17+
ptr::{null, null_mut},
18+
};
1819

1920
pub(crate) async fn establish(options: &SqliteConnectOptions) -> Result<SqliteConnection, Error> {
2021
let mut filename = options
@@ -48,6 +49,8 @@ pub(crate) async fn establish(options: &SqliteConnectOptions) -> Result<SqliteCo
4849
flags |= SQLITE_OPEN_MEMORY;
4950
}
5051

52+
let busy_timeout = options.busy_timeout;
53+
5154
let handle = blocking!({
5255
let mut handle = null_mut();
5356

@@ -85,8 +88,13 @@ pub(crate) async fn establish(options: &SqliteConnectOptions) -> Result<SqliteCo
8588
// This causes SQLite to automatically sleep in increasing intervals until the time
8689
// when there is something locked during [sqlite3_step]. This is sync. but we only
8790
// run [sqlite3_step] in [blocking!] so its okay.
88-
// TODO: Allow this timeout to be configured in SqliteOptions
89-
status = unsafe { sqlite3_busy_timeout(handle.0.as_ptr(), 5000) };
91+
//
92+
// We also need to convert the u128 value to i32, checking we're not overflowing.
93+
let ms =
94+
i32::try_from(busy_timeout.as_millis()).expect("Given busy timeout value is too big.");
95+
96+
status = unsafe { sqlite3_busy_timeout(handle.0.as_ptr(), ms) };
97+
9098
if status != SQLITE_OK {
9199
return Err(Error::Database(Box::new(SqliteError::new(handle.as_ptr()))));
92100
}

sqlx-core/src/sqlite/options/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod journal_mode;
55
mod parse;
66

77
pub use journal_mode::SqliteJournalMode;
8-
use std::borrow::Cow;
8+
use std::{borrow::Cow, time::Duration};
99

1010
/// Options and flags which can be used to configure a SQLite connection.
1111
///
@@ -49,6 +49,7 @@ pub struct SqliteConnectOptions {
4949
pub(crate) journal_mode: SqliteJournalMode,
5050
pub(crate) foreign_keys: bool,
5151
pub(crate) statement_cache_capacity: usize,
52+
pub(crate) busy_timeout: Duration,
5253
}
5354

5455
impl Default for SqliteConnectOptions {
@@ -67,6 +68,7 @@ impl SqliteConnectOptions {
6768
foreign_keys: true,
6869
statement_cache_capacity: 100,
6970
journal_mode: SqliteJournalMode::Wal,
71+
busy_timeout: Duration::from_secs(5),
7072
}
7173
}
7274

@@ -119,4 +121,13 @@ impl SqliteConnectOptions {
119121
self.statement_cache_capacity = capacity;
120122
self
121123
}
124+
125+
/// Sets a timeout value to wait when the database is locked, before
126+
/// returning a busy timeout error.
127+
///
128+
/// The default busy timeout is 5 seconds.
129+
pub fn busy_timeout(mut self, timeout: Duration) -> Self {
130+
self.busy_timeout = timeout;
131+
self
132+
}
122133
}

sqlx-core/src/type_info.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@ pub trait TypeInfo: Debug + Display + Clone + PartialEq<Self> + Send + Sync {
88
/// Common type names are `VARCHAR`, `TEXT`, or `INT`. Type names should be uppercase. They
99
/// should be a rough approximation of how they are written in SQL in the given database.
1010
fn name(&self) -> &str;
11+
12+
#[doc(hidden)]
13+
fn is_void(&self) -> bool {
14+
false
15+
}
1116
}

sqlx-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2018"
88
authors = [
99
1010
"Austin Bonander <[email protected]>", # [email protected]
11-
"Zachery Gyurkovitz <zgyurkovitz@gmail.com>", # zach@launchbadge.com
11+
"Chloe Ross <orangesnowfox@gmail.com>", # chloe@launchbadge.com
1212
"Daniel Akhterov <[email protected]>", # [email protected]
1313
]
1414

sqlx-macros/src/query/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub use input::QueryMacroInput;
1010
use quote::{format_ident, quote};
1111
use sqlx_core::connection::Connection;
1212
use sqlx_core::database::Database;
13-
use sqlx_core::describe::Describe;
13+
use sqlx_core::{column::Column, describe::Describe, type_info::TypeInfo};
1414
use sqlx_rt::block_on;
1515

1616
use crate::database::DatabaseExt;
@@ -221,7 +221,12 @@ where
221221

222222
let query_args = format_ident!("query_args");
223223

224-
let output = if data.describe.columns().is_empty() {
224+
let output = if data
225+
.describe
226+
.columns()
227+
.iter()
228+
.all(|it| it.type_info().is_void())
229+
{
225230
let db_path = DB::db_path();
226231
let sql = &input.src;
227232

0 commit comments

Comments
 (0)