Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: binary storage db #153

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ pub fn handle_new_command(
postgres: if postgres_enabled {
Some(PostgresDetails {
enabled: true,
binary_storage: None,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this should actually be called "max_optimisation"

drop_each_run: None,
relationships: None,
indexes: None,
Expand Down
13 changes: 12 additions & 1 deletion core/src/database/postgres/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fn generate_event_table_sql_with_comments(
abi_inputs: &[EventInfo],
contract_name: &str,
schema_name: &str,
binary_mode: bool,
apply_full_name_comment_for_events: Vec<String>,
) -> String {
abi_inputs
Expand All @@ -53,7 +54,15 @@ fn generate_event_table_sql_with_comments(
let event_columns = if event_info.inputs.is_empty() {
"".to_string()
} else {
generate_columns_with_data_types(&event_info.inputs).join(", ") + ","
if binary_mode {
generate_columns_with_data_types(&event_info.inputs)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not everything can be stored in bytes like booleans etc we only want to store hex stuff as bytes so i think you need to filter out based on the solidity type which ones to do?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use a .filter() or .filter_map() for this? I'm not sure exactly

.iter()
.map(|column| format!("{} BYTEA", column))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for arrays it has to be BYTEA[]

.collect::<Vec<_>>()
.join(", ")
} else {
generate_columns_with_data_types(&event_info.inputs).join(", ")
}
};

let create_table_sql = format!(
Expand Down Expand Up @@ -160,6 +169,7 @@ pub fn generate_tables_for_indexer_sql(
project_path: &Path,
indexer: &Indexer,
disable_event_tables: bool,
binary_mode: bool,
) -> Result<Code, GenerateTablesForIndexerSqlError> {
let mut sql = "CREATE SCHEMA IF NOT EXISTS rindexer_internal;".to_string();

Expand All @@ -185,6 +195,7 @@ pub fn generate_tables_for_indexer_sql(
&event_names,
&contract.name,
&schema_name,
binary_mode,
event_matching_name_on_other,
));
}
Expand Down
6 changes: 5 additions & 1 deletion core/src/database/postgres/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub async fn setup_postgres(
let client = PostgresClient::new().await?;

let disable_event_tables = manifest.storage.postgres_disable_create_tables();

let binary_mode = manifest.storage.binary_storage();
if manifest.storage.postgres_drop_each_run() {
info!(
"`drop_each_run` enabled so dropping all data for {} before starting",
Expand All @@ -41,6 +41,9 @@ pub async fn setup_postgres(
client.batch_execute(sql.as_str()).await?;
info!("Dropped all data for {}", manifest.name);
}
if manifest.storage.binary_storage() {
info!("storing data in bytes")
}

if !disable_event_tables {
info!("Creating tables for {}", manifest.name);
Expand All @@ -51,6 +54,7 @@ pub async fn setup_postgres(
project_path,
&manifest.to_indexer(),
disable_event_tables,
binary_mode,
)?;
debug!("{}", sql);
client.batch_execute(sql.as_str()).await?;
Expand Down
Loading