mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-25 19:40:25 +00:00
feat: make macros aware of macros.preferred-crates
This commit is contained in:
@@ -11,7 +11,7 @@ pub struct SqliteColumn {
|
||||
pub(crate) type_info: SqliteTypeInfo,
|
||||
|
||||
#[cfg_attr(feature = "offline", serde(default))]
|
||||
pub(crate) origin: ColumnOrigin
|
||||
pub(crate) origin: ColumnOrigin,
|
||||
}
|
||||
|
||||
impl Column for SqliteColumn {
|
||||
|
||||
@@ -49,7 +49,7 @@ pub(crate) fn describe(conn: &mut ConnectionState, query: &str) -> Result<Descri
|
||||
|
||||
for col in 0..num {
|
||||
let name = stmt.handle.column_name(col).to_owned();
|
||||
|
||||
|
||||
let origin = stmt.handle.column_origin(col);
|
||||
|
||||
let type_info = if let Some(ty) = stmt.handle.column_decltype(col) {
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
use std::ffi::c_void;
|
||||
use std::ffi::CStr;
|
||||
|
||||
use std::os::raw::{c_char, c_int};
|
||||
use std::ptr;
|
||||
use std::ptr::NonNull;
|
||||
use std::slice::from_raw_parts;
|
||||
use std::str::{from_utf8, from_utf8_unchecked};
|
||||
use std::sync::Arc;
|
||||
use crate::error::{BoxDynError, Error};
|
||||
use crate::type_info::DataType;
|
||||
use crate::{SqliteError, SqliteTypeInfo};
|
||||
use libsqlite3_sys::{
|
||||
sqlite3, sqlite3_bind_blob64, sqlite3_bind_double, sqlite3_bind_int, sqlite3_bind_int64,
|
||||
sqlite3_bind_null, sqlite3_bind_parameter_count, sqlite3_bind_parameter_name,
|
||||
@@ -20,9 +17,12 @@ use libsqlite3_sys::{
|
||||
SQLITE_TRANSIENT, SQLITE_UTF8,
|
||||
};
|
||||
use sqlx_core::column::{ColumnOrigin, TableColumn};
|
||||
use crate::error::{BoxDynError, Error};
|
||||
use crate::type_info::DataType;
|
||||
use crate::{SqliteError, SqliteTypeInfo};
|
||||
use std::os::raw::{c_char, c_int};
|
||||
use std::ptr;
|
||||
use std::ptr::NonNull;
|
||||
use std::slice::from_raw_parts;
|
||||
use std::str::{from_utf8, from_utf8_unchecked};
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::unlock_notify;
|
||||
|
||||
@@ -114,8 +114,9 @@ impl StatementHandle {
|
||||
}
|
||||
|
||||
pub(crate) fn column_origin(&self, index: usize) -> ColumnOrigin {
|
||||
if let Some((table, name)) =
|
||||
self.column_table_name(index).zip(self.column_origin_name(index))
|
||||
if let Some((table, name)) = self
|
||||
.column_table_name(index)
|
||||
.zip(self.column_origin_name(index))
|
||||
{
|
||||
let table: Arc<str> = self
|
||||
.column_db_name(index)
|
||||
@@ -125,20 +126,20 @@ impl StatementHandle {
|
||||
// TODO: check that SQLite returns the names properly quoted if necessary
|
||||
|db| format!("{db}.{table}").into(),
|
||||
);
|
||||
|
||||
|
||||
ColumnOrigin::Table(TableColumn {
|
||||
table,
|
||||
name: name.into()
|
||||
name: name.into(),
|
||||
})
|
||||
} else {
|
||||
ColumnOrigin::Expression
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn column_db_name(&self, index: usize) -> Option<&str> {
|
||||
unsafe {
|
||||
let db_name = sqlite3_column_database_name(self.0.as_ptr(), check_col_idx!(index));
|
||||
|
||||
|
||||
if !db_name.is_null() {
|
||||
Some(from_utf8_unchecked(CStr::from_ptr(db_name).to_bytes()))
|
||||
} else {
|
||||
@@ -170,7 +171,7 @@ impl StatementHandle {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub(crate) fn column_type_info(&self, index: usize) -> SqliteTypeInfo {
|
||||
SqliteTypeInfo(DataType::from_code(self.column_type(index)))
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@ impl VirtualStatement {
|
||||
ordinal: i,
|
||||
name: name.clone(),
|
||||
type_info,
|
||||
origin: statement.column_origin(i),
|
||||
});
|
||||
|
||||
column_names.insert(name, i);
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use crate::Sqlite;
|
||||
#[allow(unused_imports)]
|
||||
use sqlx_core as sqlx;
|
||||
|
||||
use crate::Sqlite;
|
||||
|
||||
// f32 is not included below as REAL represents a floating point value
|
||||
// stored as an 8-byte IEEE floating point number (i.e. an f64)
|
||||
// For more info see: https://www.sqlite.org/datatype3.html#storage_classes_and_datatypes
|
||||
@@ -20,24 +19,6 @@ impl_type_checking!(
|
||||
String,
|
||||
Vec<u8>,
|
||||
|
||||
#[cfg(all(feature = "chrono", not(feature = "time")))]
|
||||
sqlx::types::chrono::NaiveDate,
|
||||
|
||||
#[cfg(all(feature = "chrono", not(feature = "time")))]
|
||||
sqlx::types::chrono::NaiveDateTime,
|
||||
|
||||
#[cfg(all(feature = "chrono", not(feature = "time")))]
|
||||
sqlx::types::chrono::DateTime<sqlx::types::chrono::Utc> | sqlx::types::chrono::DateTime<_>,
|
||||
|
||||
#[cfg(feature = "time")]
|
||||
sqlx::types::time::OffsetDateTime,
|
||||
|
||||
#[cfg(feature = "time")]
|
||||
sqlx::types::time::PrimitiveDateTime,
|
||||
|
||||
#[cfg(feature = "time")]
|
||||
sqlx::types::time::Date,
|
||||
|
||||
#[cfg(feature = "uuid")]
|
||||
sqlx::types::Uuid,
|
||||
},
|
||||
@@ -48,4 +29,28 @@ impl_type_checking!(
|
||||
// The type integrations simply allow the user to skip some intermediate representation,
|
||||
// which is usually TEXT.
|
||||
feature-types: _info => None,
|
||||
|
||||
// The expansion of the macro automatically applies the correct feature name
|
||||
// and checks `[macros.preferred-crates]`
|
||||
datetime-types: {
|
||||
chrono: {
|
||||
sqlx::types::chrono::NaiveDate,
|
||||
|
||||
sqlx::types::chrono::NaiveDateTime,
|
||||
|
||||
sqlx::types::chrono::DateTime<sqlx::types::chrono::Utc>
|
||||
| sqlx::types::chrono::DateTime<_>,
|
||||
},
|
||||
time: {
|
||||
sqlx::types::time::OffsetDateTime,
|
||||
|
||||
sqlx::types::time::PrimitiveDateTime,
|
||||
|
||||
sqlx::types::time::Date,
|
||||
},
|
||||
},
|
||||
numeric-types: {
|
||||
bigdecimal: { },
|
||||
rust_decimal: { },
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user