Skip to content
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

Search over name and keyname #51

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions src/App/Storage/SQLite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,27 @@ ensureTablesAreCreated = do
<> db_PACKAGE_DETAILS
<> " (NAME COLLATE NOCASE)"

execute_ $
"CREATE INDEX IF NOT EXISTS KEY_NAME_NOCASE_INDEX on "
<> db_PACKAGE_DETAILS
<> " (KEY_NAME COLLATE NOCASE)"

versions :: MonadSQL m => Channel -> Package -> m [(PackageDetails, Commit)]
versions channel package = do
results <- queryNamed
(fromString $ unwords
[ "SELECT " <> intercalate ","
[ db_PACKAGE_DETAILS <> ".NAME"
, db_PACKAGE_DETAILS <> ".VERSION"
, db_PACKAGE_DETAILS <> ".KEY_NAME"
, db_PACKAGE_DETAILS <> ".FULL_NAME"
, db_PACKAGE_DETAILS <> ".DESCRIPTION"
, db_PACKAGE_DETAILS <> ".COMMIT_HASH"
, db_COVERAGE <> ".COMMIT_DATE"
[ "SELECT DISTINCT " <> intercalate ","
[ "P.NAME"
, "P.VERSION"
, "P.KEY_NAME"
, "P.FULL_NAME"
, "P.DESCRIPTION"
, "P.COMMIT_HASH"
, db_COVERAGE <> ".COMMIT_DATE"
]
, "FROM " <> db_PACKAGE_DETAILS
, "INNER JOIN " <> db_COVERAGE
<> " ON "
<> db_PACKAGE_DETAILS <> ".COMMIT_HASH"
<> " = "
<> db_COVERAGE <> ".COMMIT_HASH"
, "WHERE"
, "NAME = :name COLLATE NOCASE AND CHANNEL = :channel"
, "FROM (" <> subquery <> ") AS P"
, "INNER JOIN " <> db_COVERAGE <> " ON P.COMMIT_HASH = " <> db_COVERAGE <> ".COMMIT_HASH"
, "WHERE CHANNEL = :channel"
, "ORDER BY COMMIT_DATE"
]
)
Expand All @@ -147,6 +147,13 @@ versions channel package = do
, Commit hash time
)

-- NAME = :name OR KEY_NAME = :name
subquery = unwords
[ "SELECT * FROM " <> db_PACKAGE_DETAILS <> " WHERE NAME = :name COLLATE NOCASE"
, "UNION"
, "SELECT * FROM " <> db_PACKAGE_DETAILS <> " WHERE KEY_NAME = :name COLLATE NOCASE"
]

coverage :: MonadSQL m => Channel -> m [(Period, Commit, CommitState)]
coverage channel = do
results <- queryNamed
Expand Down