Skip to content

Commit 33e247c

Browse files
committed
feat: expose a Datetime EthereumSqlTypeWrapper
1 parent 65910fb commit 33e247c

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mockito = "0.30"
1515
ethers = { version = "2.0", features = ["rustls", "openssl"] }
1616
ethers-solc = "2.0.14"
1717
tokio = { version = "1", features = ["full"] }
18-
tokio-postgres = { version="0.7", features=["with-uuid-1"] }
18+
tokio-postgres = { version="0.7", features=["with-uuid-1", "with-chrono-0_4"] }
1919
bb8 = "0.8.3"
2020
bb8-postgres = "0.8.1"
2121
serde = "1.0"
@@ -40,7 +40,7 @@ ctrlc = "3.4.4"
4040
percent-encoding = "2.3.1"
4141
tracing = "0.1"
4242
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt", "time"] }
43-
chrono = "0.4.38"
43+
chrono = { version = "0.4", features = ["serde"] }
4444
log = "0.4.20"
4545
colored = "2.0"
4646
hex = "0.4.3"

core/src/database/postgres/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl PostgresClient {
317317
}
318318

319319
/// This will use COPY to insert the data into the database
320-
/// or use the normal bulk inserts if the data is not large enough to
320+
/// or use the normal bulk inserts if the data is not large enough to
321321
/// need a COPY. This uses `bulk_insert` and `bulk_insert_via_copy` under the hood
322322
pub async fn insert_bulk(
323323
&self,

core/src/database/postgres/sql_type_wrapper.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::str::FromStr;
22

33
use bytes::BytesMut;
4+
use chrono::{DateTime, Utc};
45
use ethers::{
56
abi::{Int, LogParam, Token},
67
addressbook::Address,
@@ -79,6 +80,8 @@ pub enum EthereumSqlTypeWrapper {
7980
VecString(Vec<String>),
8081
Bytes(Bytes),
8182
VecBytes(Vec<Bytes>),
83+
84+
DateTime(DateTime<Utc>),
8285
}
8386

8487
impl EthereumSqlTypeWrapper {
@@ -147,6 +150,8 @@ impl EthereumSqlTypeWrapper {
147150
EthereumSqlTypeWrapper::VecString(_) => "VecString",
148151
EthereumSqlTypeWrapper::Bytes(_) => "Bytes",
149152
EthereumSqlTypeWrapper::VecBytes(_) => "VecBytes",
153+
154+
EthereumSqlTypeWrapper::DateTime(_) => "DateTime",
150155
}
151156
}
152157

@@ -215,6 +220,9 @@ impl EthereumSqlTypeWrapper {
215220
EthereumSqlTypeWrapper::VecString(_) => PgType::TEXT_ARRAY,
216221
EthereumSqlTypeWrapper::Bytes(_) => PgType::BYTEA,
217222
EthereumSqlTypeWrapper::VecBytes(_) => PgType::BYTEA_ARRAY,
223+
224+
// DateTime
225+
EthereumSqlTypeWrapper::DateTime(_) => PgType::TIMESTAMPTZ,
218226
}
219227
}
220228
}
@@ -472,6 +480,7 @@ impl ToSql for EthereumSqlTypeWrapper {
472480
int_values.to_sql(ty, out)
473481
}
474482
}
483+
EthereumSqlTypeWrapper::DateTime(value) => value.to_sql(ty, out),
475484
}
476485
}
477486

@@ -1133,6 +1142,9 @@ pub fn map_ethereum_wrapper_to_json(
11331142
EthereumSqlTypeWrapper::VecBytes(bytes) => {
11341143
json!(bytes.iter().map(hex::encode).collect::<Vec<_>>())
11351144
}
1145+
EthereumSqlTypeWrapper::DateTime(date_time) => {
1146+
json!(date_time.to_rfc3339())
1147+
}
11361148
};
11371149
result.insert(abi_input.name.clone(), value);
11381150
wrappers_index_processed.push(current_wrapper_index);

core/src/manifest/yaml.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ pub fn read_manifest(file_path: &PathBuf) -> Result<Manifest, ReadManifestError>
266266
let manifest_before_transform: Manifest = serde_yaml::from_str(&contents)?;
267267

268268
contents = substitute_env_variables(&contents)?;
269-
269+
270270
let mut manifest_after_transform: Manifest = serde_yaml::from_str(&contents)?;
271271

272272
// as we don't want to inject the RPC URL in rust projects in clear text we should change

documentation/docs/pages/docs/changelog.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ github branch - https://github.com/joshstevens19/rindexer/tree/release/0.10.0
2929
### Features
3030
-------------------------------------------------
3131
- feat: expose an insert_bulk new postgres function to make inserting bulk data easier
32+
- feat: expose a Datetime EthereumSqlTypeWrapper
3233

3334
## 0.9.0-beta - 19th September 2024
3435

0 commit comments

Comments
 (0)