-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
Add option to compare site_id when values are equal to determine ultimate winner #415
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cb9a7bf
wip: compare site_id if values are the same and option is turned on
jeromegn 7cf8277
add crsql_config_set function
jeromegn 6863bac
I guess we keep this struct in 2 places
jeromegn 36e069c
add tie-breaker test
jeromegn 104a0df
fix test_merge_same_w_tie_breaker
jeromegn 3a01980
write config settings to crsql_master table to persist some of them
jeromegn bdc0710
fix config not being loaded properly on init
jeromegn af73ad1
re-generate bindings to use core instead of std
jeromegn e229737
add INNOCUOUS and DETERMINISTIC to crsql_config_get
jeromegn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,85 @@ | ||
use alloc::format; | ||
|
||
use sqlite::{Connection, Context}; | ||
use sqlite_nostd as sqlite; | ||
use sqlite_nostd::{ResultCode, Value}; | ||
|
||
use crate::c::crsql_ExtData; | ||
|
||
pub const MERGE_EQUAL_VALUES: &str = "merge-equal-values"; | ||
|
||
pub extern "C" fn crsql_config_set( | ||
ctx: *mut sqlite::context, | ||
argc: i32, | ||
argv: *mut *mut sqlite::value, | ||
) { | ||
let args = sqlite::args!(argc, argv); | ||
|
||
let name = args[0].text(); | ||
|
||
let value = match name { | ||
MERGE_EQUAL_VALUES => { | ||
let value = args[1]; | ||
let ext_data = ctx.user_data() as *mut crsql_ExtData; | ||
unsafe { (*ext_data).mergeEqualValues = value.int() }; | ||
value | ||
} | ||
_ => { | ||
ctx.result_error("Unknown setting name"); | ||
ctx.result_error_code(ResultCode::ERROR); | ||
return; | ||
} | ||
}; | ||
|
||
let db = ctx.db_handle(); | ||
match insert_config_setting(db, name, value) { | ||
Ok(value) => { | ||
ctx.result_value(value); | ||
} | ||
Err(rc) => { | ||
ctx.result_error("Could not persist config in database"); | ||
ctx.result_error_code(rc); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
fn insert_config_setting( | ||
db: *mut sqlite_nostd::sqlite3, | ||
name: &str, | ||
value: *mut sqlite::value, | ||
) -> Result<*mut sqlite::value, ResultCode> { | ||
let stmt = | ||
db.prepare_v2("INSERT OR REPLACE INTO crsql_master VALUES (?, ?) RETURNING value")?; | ||
|
||
stmt.bind_text(1, &format!("config.{name}"), sqlite::Destructor::TRANSIENT)?; | ||
stmt.bind_value(2, value)?; | ||
|
||
if let ResultCode::ROW = stmt.step()? { | ||
stmt.column_value(0) | ||
} else { | ||
Err(ResultCode::ERROR) | ||
} | ||
} | ||
|
||
pub extern "C" fn crsql_config_get( | ||
ctx: *mut sqlite::context, | ||
argc: i32, | ||
argv: *mut *mut sqlite::value, | ||
) { | ||
let args = sqlite::args!(argc, argv); | ||
|
||
let name = args[0].text(); | ||
|
||
match name { | ||
MERGE_EQUAL_VALUES => { | ||
let ext_data = ctx.user_data() as *mut crsql_ExtData; | ||
ctx.result_int(unsafe { (*ext_data).mergeEqualValues }); | ||
} | ||
_ => { | ||
ctx.result_error("Unknown setting name"); | ||
ctx.result_error_code(ResultCode::ERROR); | ||
return; | ||
} | ||
} | ||
} |
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,2 +1,2 @@ | ||
// The sha of the commit that this version of crsqlite was built from. | ||
pub const SHA: &'static str = ""; | ||
pub const SHA: &'static str = "3a01980562615001d765eec61e3ed58147a93f93"; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, I guess I should ignore this file and only generate it at build time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, possibly yes. I didn't notice it.