Conversation
Simplify getting DB connection by removing oncelock linting Add schema version to DB to determine if schema load is required
| }; | ||
|
|
||
| let index = Arc::new(Mutex::new(Graph::new())); | ||
| let db_path = std::env::temp_dir().join("index.db").to_string_lossy().to_string(); |
There was a problem hiding this comment.
This path should be within the project being indexed
There was a problem hiding this comment.
Will leave this for now and address in a follow up PR once we determine where temp files for the indexer should be placed in a project.
460a91a to
17f986d
Compare
| #[must_use] | ||
| pub fn new(uri: String) -> Self { | ||
| let mut local_index = Graph::new(); | ||
| let mut local_index = Graph::new(String::new()); |
There was a problem hiding this comment.
Choosing to simply pass an empty string here since this instance won't be using a DB connection
vinistock
left a comment
There was a problem hiding this comment.
Just a couple of comments, but I think this is enough for us to move forward and start iterating on it
rust/index/src/model/db.rs
Outdated
| /// # Errors | ||
| /// Will return an Error if we fail to establish or set a connection | ||
| pub fn get_connection(&self) -> Result<Connection, Box<dyn Error>> { | ||
| let mut conn = if self.path == ":memory:" { |
There was a problem hiding this comment.
Let's remove the memory thing for now since we're not using it. If we were to keep it, I'd argue this should leverage an enum instead of a string, so that we make better use of the type system.
enum ConnectionType {
Path(String),
Memory
}There was a problem hiding this comment.
True the magic string comparison isn't great. Will add an enum we can check here
rust/index/src/model/db.rs
Outdated
| let current_version: i32 = conn.query_row("PRAGMA user_version", [], |row| row.get(0))?; | ||
|
|
||
| if current_version < SCHEMA_VERSION { | ||
| if self.path == ":memory:" { |
This PR adds a DB model to the codebase that can be used for initializing DB connections.
The important areas for review are:
dbas a new attribute onGraphschema.sqlChanges related to writing Index data to the DB will be added in a follow up PR.