Skip to content

Commit ca42981

Browse files
cursoragentlovasoa
andcommitted
Checkpoint before follow-up message
Co-authored-by: contact <[email protected]>
1 parent 3c84fc2 commit ca42981

26 files changed

+1981
-20
lines changed

Cargo.lock

Lines changed: 354 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ offline = ["sqlx-macros/offline", "sqlx-core/offline"]
5757

5858
# intended mainly for CI and docs
5959
all = ["tls", "all-databases", "all-types"]
60-
all-databases = ["mysql", "sqlite", "postgres", "mssql", "any"]
60+
all-databases = ["mysql", "sqlite", "postgres", "mssql", "snowflake", "any"]
6161
all-types = [
6262
"bigdecimal",
6363
"decimal",
@@ -131,6 +131,7 @@ postgres = ["sqlx-core/postgres", "sqlx-macros/postgres"]
131131
mysql = ["sqlx-core/mysql", "sqlx-macros/mysql"]
132132
sqlite = ["sqlx-core/sqlite", "sqlx-macros/sqlite"]
133133
mssql = ["sqlx-core/mssql", "sqlx-macros/mssql"]
134+
snowflake = ["sqlx-core/snowflake", "sqlx-macros/snowflake"]
134135

135136
# types
136137
bigdecimal = ["sqlx-core/bigdecimal", "sqlx-macros/bigdecimal"]

sqlx-core/Cargo.toml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ default = ["migrate"]
2020
migrate = ["sha2", "crc"]
2121

2222
# databases
23-
all-databases = ["postgres", "mysql", "sqlite", "mssql", "any"]
23+
all-databases = ["postgres", "mysql", "sqlite", "mssql", "snowflake", "any"]
2424
postgres = [
2525
"md-5",
2626
"sha2",
@@ -45,6 +45,17 @@ mysql = [
4545
]
4646
sqlite = ["libsqlite3-sys", "futures-executor", "flume"]
4747
mssql = ["uuid", "encoding_rs", "regex"]
48+
snowflake = [
49+
"reqwest",
50+
"jsonwebtoken",
51+
"rsa",
52+
"sha2",
53+
"base64",
54+
"serde",
55+
"serde_json",
56+
"uuid",
57+
"chrono"
58+
]
4859
any = []
4960

5061
# types
@@ -170,6 +181,8 @@ hashlink = "0.10.0"
170181
indexmap = "2.0.0"
171182
hkdf = { version = "0.12.0", optional = true }
172183
event-listener = "5.4.0"
184+
reqwest = { version = "0.12", optional = true, default-features = false, features = ["json", "rustls-tls"] }
185+
jsonwebtoken = { version = "9.3", optional = true }
173186

174187
dotenvy = "0.15"
175188

sqlx-core/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ pub mod migrate;
8383
feature = "postgres",
8484
feature = "mysql",
8585
feature = "mssql",
86-
feature = "sqlite"
86+
feature = "sqlite",
87+
feature = "snowflake"
8788
),
8889
feature = "any"
8990
))]
@@ -105,6 +106,10 @@ pub mod mysql;
105106
#[cfg_attr(docsrs, doc(cfg(feature = "mssql")))]
106107
pub mod mssql;
107108

109+
#[cfg(feature = "snowflake")]
110+
#[cfg_attr(docsrs, doc(cfg(feature = "snowflake")))]
111+
pub mod snowflake;
112+
108113
// Implements test support with automatic DB management.
109114
#[cfg(feature = "migrate")]
110115
pub mod testing;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
use crate::arguments::Arguments;
2+
use crate::encode::{Encode, IsNull};
3+
use crate::snowflake::{Snowflake, SnowflakeTypeInfo};
4+
use crate::types::Type;
5+
use std::borrow::Cow;
6+
7+
/// Implementation of [`Arguments`] for Snowflake.
8+
#[derive(Debug, Default, Clone)]
9+
pub struct SnowflakeArguments {
10+
// Store arguments as strings since Snowflake SQL API uses text protocol
11+
pub(crate) bindings: Vec<String>,
12+
}
13+
14+
/// Implementation of [`ArgumentBuffer`] for Snowflake.
15+
#[derive(Debug)]
16+
pub struct SnowflakeArgumentBuffer {
17+
pub(crate) buffer: Vec<u8>,
18+
}
19+
20+
impl SnowflakeArguments {
21+
pub fn new() -> Self {
22+
Self {
23+
bindings: Vec::new(),
24+
}
25+
}
26+
27+
pub(crate) fn len(&self) -> usize {
28+
self.bindings.len()
29+
}
30+
31+
pub(crate) fn get(&self, index: usize) -> Option<&String> {
32+
self.bindings.get(index)
33+
}
34+
}
35+
36+
impl<'q> Arguments<'q> for SnowflakeArguments {
37+
type Database = Snowflake;
38+
39+
fn reserve(&mut self, additional: usize, _size: usize) {
40+
self.bindings.reserve(additional);
41+
}
42+
43+
fn add<T>(&mut self, value: T)
44+
where
45+
T: 'q + Encode<'q, Self::Database> + Type<Self::Database>,
46+
{
47+
let mut buffer = SnowflakeArgumentBuffer::new();
48+
let is_null = value.encode_by_ref(&mut buffer);
49+
50+
match is_null {
51+
IsNull::No => {
52+
// Convert the encoded bytes to a string
53+
let binding = String::from_utf8_lossy(&buffer.buffer).into_owned();
54+
self.bindings.push(binding);
55+
}
56+
IsNull::Yes => {
57+
self.bindings.push("NULL".to_string());
58+
}
59+
}
60+
}
61+
}
62+
63+
impl Default for SnowflakeArgumentBuffer {
64+
fn default() -> Self {
65+
Self {
66+
buffer: Vec::new(),
67+
}
68+
}
69+
}
70+
71+
impl SnowflakeArgumentBuffer {
72+
pub fn new() -> Self {
73+
Self::default()
74+
}
75+
}

sqlx-core/src/snowflake/column.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use crate::column::{Column, ColumnIndex};
2+
use crate::error::Error;
3+
use crate::snowflake::{Snowflake, SnowflakeTypeInfo};
4+
use std::borrow::Cow;
5+
6+
/// Implementation of [`Column`] for Snowflake.
7+
#[derive(Debug, Clone)]
8+
pub struct SnowflakeColumn {
9+
pub(crate) name: String,
10+
pub(crate) type_info: SnowflakeTypeInfo,
11+
pub(crate) ordinal: usize,
12+
}
13+
14+
impl SnowflakeColumn {
15+
pub(crate) fn new(name: String, type_info: SnowflakeTypeInfo, ordinal: usize) -> Self {
16+
Self {
17+
name,
18+
type_info,
19+
ordinal,
20+
}
21+
}
22+
}
23+
24+
impl crate::column::private_column::Sealed for SnowflakeColumn {}
25+
26+
impl Column for SnowflakeColumn {
27+
type Database = Snowflake;
28+
29+
fn ordinal(&self) -> usize {
30+
self.ordinal
31+
}
32+
33+
fn name(&self) -> &str {
34+
&self.name
35+
}
36+
37+
fn type_info(&self) -> &SnowflakeTypeInfo {
38+
&self.type_info
39+
}
40+
}

0 commit comments

Comments
 (0)