Skip to content

Commit

Permalink
preserve order of inserted options
Browse files Browse the repository at this point in the history
  • Loading branch information
DolceTriade committed Feb 4, 2024
1 parent af52752 commit 8ae1e94
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions blade/db/postgres/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,10 @@ impl state::DB for Postgres {
let mut vals = vec![];
let mut vec_helper = |vec: &Vec<String>, kind_: &str| {
if !vec.is_empty() {
vec.iter().for_each(|v| {
let uid = uuid::Uuid::new_v4().to_string();
let uid = uuid::Uuid::new_v4().to_string();
vec.iter().enumerate().for_each(|(i, v)| {
vals.push((
id.eq(uid),
id.eq(format!("{}-{:04}", uid, i)),
invocation_id.eq(inv_id.to_string()),
kind.eq(kind_.to_string()),
keyval.eq(crate::envscrub::scrub(v)),
Expand Down Expand Up @@ -357,7 +357,7 @@ impl state::DB for Postgres {
let ret: Vec<_> = schema::options::table
.select((schema::options::kind, schema::options::keyval))
.filter(schema::options::invocation_id.eq(id))
.order_by(schema::options::kind)
.order_by(schema::options::id.asc())
.load::<(String, String)>(&mut self.conn)?;

ret.into_iter().for_each(|(kind, keyval)| match &kind[..] {
Expand Down
8 changes: 4 additions & 4 deletions blade/db/sqlite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@ impl state::DB for Sqlite {
let mut vals = vec![];
let mut vec_helper = |vec: &Vec<String>, kind_: &str| {
if !vec.is_empty() {
vec.iter().for_each(|v| {
let uid = uuid::Uuid::new_v4().to_string();
let uid = uuid::Uuid::new_v4().to_string();
vec.iter().enumerate().for_each(|(i, v)| {
vals.push((
id.eq(uid),
id.eq(format!("{}-{:04}", uid, i)),
invocation_id.eq(inv_id.to_string()),
kind.eq(kind_.to_string()),
keyval.eq(crate::envscrub::scrub(v)),
Expand Down Expand Up @@ -370,7 +370,7 @@ impl state::DB for Sqlite {
let ret: Vec<_> = schema::Options::table
.select((schema::Options::kind, schema::Options::keyval))
.filter(schema::Options::invocation_id.eq(id))
.order_by(schema::Options::kind)
.order_by(schema::Options::id.asc())
.load::<(String, String)>(&mut self.conn)?;

ret.into_iter().for_each(|(kind, keyval)| match &kind[..] {
Expand Down

0 comments on commit 8ae1e94

Please sign in to comment.