-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'INSERT_fixes' of https://github.com/KyGost/gluesql into…
… INSERT_fixes
- Loading branch information
Showing
21 changed files
with
566 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#![cfg(feature = "auto-increment")] | ||
use { | ||
crate::{ | ||
data::{schema::ColumnDefExt, Row}, | ||
result::MutResult, | ||
store::{AlterTable, AutoIncrement, Store, StoreMut}, | ||
Value, | ||
}, | ||
sqlparser::ast::ColumnDef, | ||
std::fmt::Debug, | ||
}; | ||
|
||
pub async fn run< | ||
T: 'static + Debug, | ||
Storage: Store<T> + StoreMut<T> + AlterTable + AutoIncrement, | ||
>( | ||
storage: Storage, | ||
rows: Vec<Row>, | ||
column_defs: &[ColumnDef], | ||
table_name: &str, | ||
) -> MutResult<Storage, Vec<Row>> { | ||
// FAIL: No-mut | ||
let auto_increment_columns = column_defs | ||
.iter() | ||
.enumerate() | ||
.filter(|(_, column_def)| column_def.is_auto_incremented()) | ||
.map(|(index, column_def)| { | ||
( | ||
index, | ||
column_def.name.value.clone(), | ||
rows.iter() | ||
.filter(|row| matches!(row.get_value(index), Some(Value::Null))) | ||
.count() as i64, | ||
) | ||
}) | ||
.collect(); | ||
|
||
let (storage, column_values) = storage | ||
.generate_increment_values(table_name.to_string(), auto_increment_columns) | ||
.await?; | ||
|
||
let mut rows = rows; | ||
let mut column_values = column_values; | ||
for row in &mut rows { | ||
for ((index, _name), value) in &mut column_values { | ||
if matches!(row.0[*index], Value::Null) { | ||
row.0[*index] = Value::I64(*value); | ||
|
||
*value += 1; | ||
} | ||
} | ||
} | ||
Ok((storage, rows)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#[cfg(feature = "auto-increment")] | ||
pub mod auto_increment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
mod aggregate; | ||
mod alter; | ||
mod blend; | ||
mod column_options; | ||
mod context; | ||
mod evaluate; | ||
mod execute; | ||
|
Oops, something went wrong.