-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow eg. pkgx +rust
like pkgx^1 does
#1090
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,10 +30,15 @@ pub fn cache(config: &Config, conn: &mut Connection) -> Result<(), Box<dyn Error | |
project TEXT, | ||
envline TEXT | ||
); | ||
CREATE TABLE aliases ( | ||
project TEXT, | ||
alias TEXT | ||
); | ||
CREATE INDEX idx_project ON provides(project); | ||
CREATE INDEX idx_program ON provides(program); | ||
CREATE INDEX idx_project_dependencies ON dependencies(project); | ||
CREATE INDEX idx_project_companions ON companions(project); | ||
CREATE INDEX idx_alias_project ON aliases(alias); | ||
", | ||
)?; | ||
|
||
|
@@ -53,6 +58,13 @@ pub fn cache(config: &Config, conn: &mut Connection) -> Result<(), Box<dyn Error | |
)?; | ||
} | ||
|
||
if let Some(display_name) = pkg.display_name { | ||
tx.execute( | ||
"INSERT INTO aliases (project, alias) VALUES (?1, ?2);", | ||
params![pkg.project, display_name], | ||
)?; | ||
} | ||
|
||
for dep in pkg.deps { | ||
tx.execute( | ||
"INSERT INTO dependencies (project, pkgspec) VALUES (?1, ?2);", | ||
|
@@ -103,6 +115,24 @@ pub fn which(cmd: &String, conn: &Connection) -> Result<Vec<String>, rusqlite::E | |
Ok(rv) | ||
} | ||
|
||
pub fn projects_for_symbol( | ||
symbol: &String, | ||
conn: &Connection, | ||
) -> Result<Vec<String>, rusqlite::Error> { | ||
let mut stmt = conn.prepare( | ||
" | ||
SELECT project FROM provides WHERE program = ?1 | ||
UNION | ||
SELECT project FROM aliases WHERE LOWER(alias) = LOWER(?1);", | ||
)?; | ||
let mut rv = Vec::new(); | ||
let mut rows = stmt.query(params![symbol])?; | ||
while let Some(row) = rows.next()? { | ||
rv.push(row.get(0)?); | ||
} | ||
Comment on lines
+128
to
+132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just for style reasons, this is: Ok(
stmt
.query(params![symbol])?
.map(|row| row.get(0).expect("Query returned malformed data."))
.collect::<Vec<String>
) assuming the borrow checker doesn't think you're dropping bits. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't compile and I am not enough of a rust guru yet to fix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you haven't, give There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have not, though I have been there numerous times lately since it is the latest addition to the pantry. I guess I don't see how it would help me here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not here specifically, but the feedback is rapid and, to my mind, better organized than rust-analyzer+vscode (it also works no matter what base directory you're in, which rust-analyzer struggles with). |
||
Ok(rv) | ||
} | ||
|
||
pub fn runtime_env_for_project( | ||
project: &String, | ||
conn: &Connection, | ||
|
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 sense migrations coming. there's a fair few tools in rust for that. and a few in pkgx, like
goose
.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.
we would certainly be more proper to be able to update the db incrementally and with migrations. That’s work I am not interested in RN tho for sure.