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

Allow SQL searches #3758

Closed
michalelektryk opened this issue Nov 21, 2019 · 2 comments
Closed

Allow SQL searches #3758

michalelektryk opened this issue Nov 21, 2019 · 2 comments

Comments

@michalelektryk
Copy link

I suggest adding one feature. As Signal is already based on SQL why not let user enter SQL queries in search box? If i want to find some some url someone sent my last month in the evening it's hard, because it shows me all urls, but If i open underlying database in SQLCiper and enter:

SELECT body,TIME(DATETIME(ROUND(sent_at/1000),'unixepoch')) as time FROM messages WHERE body LIKE "%www.%.com%" AND time BETWEEN '17:00:00' AND '19:00:00';

Many of users of Signal are IT people so I do believe that this might be useful for them. The way I see it is that current search would look for "selectfrom; " and if your query matches this regex it would go instantly to db.

@scottnonnenberg-signal scottnonnenberg-signal changed the title search allows SQL searches Allows SQL searches Nov 21, 2019
@michalelektryk
Copy link
Author

In this function:

async function searchConversations(query, { limit } = {}) {
const rows = await db.all(
SELECT json FROM conversations WHERE ( id LIKE $id OR name LIKE $name OR profileName LIKE $profileName ) ORDER BY active_at DESC LIMIT $limit,
{
$id: %${query}%,
$name: %${query}%,
$profileName: %${query}%,
$limit: limit || 100,
}
);

return map(rows, row => jsonToObject(row.json));
}

it simple needs to check against regex and if it matches pass bare query string, for eg. that way:

async function searchConversations(query, { limit } = {}) {
var re=/select\s+\S*\s+from/;
if (query.match(re)!=NULL)
const rows = await db.all(query);
else
const rows = await db.all(
SELECT json FROM conversations WHERE ( id LIKE $id OR name LIKE $name OR profileName LIKE $profileName ) ORDER BY active_at DESC LIMIT $limit,
{
$id: %${query}%,
$name: %${query}%,
$profileName: %${query}%,
$limit: limit || 100,
}
);

return map(rows, row => jsonToObject(row.json));
}

@scottnonnenberg-signal scottnonnenberg-signal changed the title Allows SQL searches Allow SQL searches Nov 21, 2019
@stale
Copy link

stale bot commented Sep 27, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants