Skip to content

Commit bc41686

Browse files
committed
fix: add new type for EthereumSqlTypeWrapper to handle VARCHAR strings
1 parent 5374bde commit bc41686

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

core/src/database/postgres/sql_type_wrapper.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@ pub enum EthereumSqlTypeWrapper {
9191

9292
// Strings and Bytes
9393
String(String),
94+
StringVarchar(String),
95+
StringChar(String),
9496
StringNullable(String),
97+
StringVarcharNullable(String),
98+
StringCharNullable(String),
9599
VecString(Vec<String>),
100+
VecStringVarchar(Vec<String>),
101+
VecStringChar(Vec<String>),
96102
Bytes(Bytes),
97103
BytesNullable(Bytes),
98104
VecBytes(Vec<Bytes>),
@@ -177,8 +183,14 @@ impl EthereumSqlTypeWrapper {
177183

178184
// Strings and Bytes
179185
EthereumSqlTypeWrapper::String(_) => "String",
186+
EthereumSqlTypeWrapper::StringVarchar(_) => "StringVarchar",
187+
EthereumSqlTypeWrapper::StringChar(_) => "StringChar",
180188
EthereumSqlTypeWrapper::StringNullable(_) => "StringNullable",
189+
EthereumSqlTypeWrapper::StringVarcharNullable(_) => "StringVarcharNullable",
190+
EthereumSqlTypeWrapper::StringCharNullable(_) => "StringCharNullable",
181191
EthereumSqlTypeWrapper::VecString(_) => "VecString",
192+
EthereumSqlTypeWrapper::VecStringVarchar(_) => "VecStringVarchar",
193+
EthereumSqlTypeWrapper::VecStringChar(_) => "VecStringChar",
182194
EthereumSqlTypeWrapper::Bytes(_) => "Bytes",
183195
EthereumSqlTypeWrapper::BytesNullable(_) => "BytesNullable",
184196
EthereumSqlTypeWrapper::VecBytes(_) => "VecBytes",
@@ -272,7 +284,13 @@ impl EthereumSqlTypeWrapper {
272284
EthereumSqlTypeWrapper::String(_) | EthereumSqlTypeWrapper::StringNullable(_) => {
273285
PgType::TEXT
274286
}
287+
EthereumSqlTypeWrapper::StringVarchar(_) |
288+
EthereumSqlTypeWrapper::StringVarcharNullable(_) => PgType::VARCHAR,
289+
EthereumSqlTypeWrapper::StringChar(_) |
290+
EthereumSqlTypeWrapper::StringCharNullable(_) => PgType::CHAR,
275291
EthereumSqlTypeWrapper::VecString(_) => PgType::TEXT_ARRAY,
292+
EthereumSqlTypeWrapper::VecStringVarchar(_) => PgType::VARCHAR_ARRAY,
293+
EthereumSqlTypeWrapper::VecStringChar(_) => PgType::CHAR_ARRAY,
276294
EthereumSqlTypeWrapper::Bytes(_) | EthereumSqlTypeWrapper::BytesNullable(_) => {
277295
PgType::BYTEA
278296
}
@@ -580,15 +598,21 @@ impl ToSql for EthereumSqlTypeWrapper {
580598
out.extend_from_slice(&buf);
581599
Ok(IsNull::No)
582600
}
583-
EthereumSqlTypeWrapper::String(value) => String::to_sql(value, ty, out),
584-
EthereumSqlTypeWrapper::StringNullable(value) => {
601+
EthereumSqlTypeWrapper::String(value) |
602+
EthereumSqlTypeWrapper::StringVarchar(value) |
603+
EthereumSqlTypeWrapper::StringChar(value) => String::to_sql(value, ty, out),
604+
EthereumSqlTypeWrapper::StringNullable(value) |
605+
EthereumSqlTypeWrapper::StringVarcharNullable(value) |
606+
EthereumSqlTypeWrapper::StringCharNullable(value) => {
585607
if value.is_empty() {
586608
return Ok(IsNull::Yes);
587609
}
588610

589611
String::to_sql(value, ty, out)
590612
}
591-
EthereumSqlTypeWrapper::VecString(values) => {
613+
EthereumSqlTypeWrapper::VecString(values) |
614+
EthereumSqlTypeWrapper::VecStringVarchar(values) |
615+
EthereumSqlTypeWrapper::VecStringChar(values) => {
592616
if values.is_empty() {
593617
Ok(IsNull::Yes)
594618
} else {
@@ -1355,8 +1379,14 @@ pub fn map_ethereum_wrapper_to_json(
13551379
EthereumSqlTypeWrapper::I8(i) => json!(i),
13561380
EthereumSqlTypeWrapper::VecI8(i8s) => json!(i8s),
13571381
EthereumSqlTypeWrapper::String(s) |
1358-
EthereumSqlTypeWrapper::StringNullable(s) => json!(s),
1359-
EthereumSqlTypeWrapper::VecString(strings) => json!(strings),
1382+
EthereumSqlTypeWrapper::StringNullable(s) |
1383+
EthereumSqlTypeWrapper::StringVarchar(s) |
1384+
EthereumSqlTypeWrapper::StringVarcharNullable(s) |
1385+
EthereumSqlTypeWrapper::StringChar(s) |
1386+
EthereumSqlTypeWrapper::StringCharNullable(s) => json!(s),
1387+
EthereumSqlTypeWrapper::VecString(strings) |
1388+
EthereumSqlTypeWrapper::VecStringVarchar(strings) |
1389+
EthereumSqlTypeWrapper::VecStringChar(strings) => json!(strings),
13601390
EthereumSqlTypeWrapper::Bytes(bytes) |
13611391
EthereumSqlTypeWrapper::BytesNullable(bytes) => json!(hex::encode(bytes)),
13621392
EthereumSqlTypeWrapper::VecBytes(bytes) => {

documentation/docs/pages/docs/start-building/rust-project-deep-dive/indexers.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,14 +827,22 @@ pub enum EthereumSqlTypeWrapper {
827827
828828
// Address
829829
Address(Address),
830+
AddressNullable(Address),
830831
AddressBytes(Address),
832+
AddressBytesNullable(Address),
831833
VecAddress(Vec<Address>),
832834
VecAddressBytes(Vec<Address>),
833835
834836
// Strings and Bytes
835837
String(String),
838+
StringVarchar(String),
839+
StringChar(String),
836840
StringNullable(String),
841+
StringVarcharNullable(String),
842+
StringCharNullable(String),
837843
VecString(Vec<String>),
844+
VecStringVarchar(Vec<String>),
845+
VecStringChar(Vec<String>),
838846
Bytes(Bytes),
839847
BytesNullable(Bytes),
840848
VecBytes(Vec<Bytes>),

0 commit comments

Comments
 (0)