-
Notifications
You must be signed in to change notification settings - Fork 17
Introduce database export and import #292
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
Conversation
dependencies/typedb/repositories.bzl
Outdated
remote = "https://github.com/typedb/typedb-driver", | ||
tag = "3.2.0", # sync-marker: do not remove this comment, this is used for sync-dependencies by @typedb_driver | ||
remote = "https://github.com/farost/typedb-driver", | ||
commit = "e3b3ab1df21c7bbeef6b3bfd9b1a040343fbb54a", # sync-marker: do not remove this comment, this is used for sync-dependencies by @typedb_driver |
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.
CI is red because there is no server artifact yet. |
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.
The comments are more general than this PR, which looks good to me.
.add(CommandLeaf::new_with_inputs( | ||
"import", | ||
"Create a database with the given name based on another previously exported database.", | ||
vec![ | ||
CommandInput::new("db", get_word, None, None), | ||
CommandInput::new("schema file path", get_word, None, None), | ||
CommandInput::new("data file path", get_word, None, None), | ||
], | ||
database_import, | ||
)) | ||
.add(CommandLeaf::new_with_inputs( | ||
"export", | ||
"Export a database into a schema definition and a data files.", | ||
vec![ | ||
CommandInput::new( | ||
"db", | ||
get_word, | ||
None, | ||
Some(database_name_completer_fn(driver.clone(), runtime.clone())), | ||
), | ||
CommandInput::new("schema file path", get_word, None, None), | ||
CommandInput::new("data file path", get_word, None, None), | ||
], | ||
database_export, | ||
)); |
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.
Is get_word
really the correct parser for a file path? It looks like it just reads until whitespace.
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.
That's how files are parsed in source
:
.add(CommandLeaf::new_with_input(
"source",
"Execute a file containing a sequence of TypeQL queries. Queries may be split over multiple lines using backslash ('\\')",
CommandInput::new("file", get_word, None, Some(Box::new(file_completer))),
transaction_source,
))
src/operations.rs
Outdated
let db_name = input[0].clone(); | ||
let schema = read_to_string(input[1].clone()).map_err(|err| Box::new(err) as Box<dyn Error + Send>)?; | ||
let data_file_path: PathBuf = input[2].clone().into(); | ||
context | ||
.background_runtime | ||
.run(async move { driver.databases().import_file(db_name, schema, data_file_path).await }) | ||
.map_err(|err| Box::new(err) as Box<dyn Error + Send>)?; |
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.
I take issue with this direct use of background_runtime
, but this is not a problem with this PR.
@flyingsilverfin why aren't we using the blocking version of driver in console? It doesn't look like we're gaining anything from the async
.
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.
For 'future' usage which we may want to leverage the async driver - for instance for bulk loading.
src/operations.rs
Outdated
let schema = read_to_string(input[1].clone()).map_err(|err| Box::new(err) as Box<dyn Error + Send>)?; | ||
let data_file_path: PathBuf = input[2].clone().into(); |
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.
I would use context.read_path
or whatever it's called, to relativize the path correctly (for example, if this is running inside a script, it will relativize relative to the script location).
Basically doing that for all paths now
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.
Thanks, will test this
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.
Works fine, will preserve this
Usage and product changes
Add database export and database import operations.
Database export saves the database information (its schema and data) on the client machine as two files at provided locations:
Database import uses the exported files to create a new database with equivalent schema and data:
Implementation
Add new commands similar to other
database
interfaces. Prepare data to call the respective typedb-driver APIs.