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 searching on Postgres #8

Merged
merged 2 commits into from
Nov 25, 2024
Merged

Conversation

maltoe
Copy link
Contributor

@maltoe maltoe commented Nov 24, 2024

Hi @egze

This patch changes the search implementation to explicitly cast the jsonb args column to text before passing it to like/2, as PostgreSQL (at least version <=15) does not support jsonb ~~ text like sqlite does.

I'd also like to also switch the like to ilike for Postgres as it defaults to case-sensitive search, but not sure how to get the adapter from Oban.Repo.

Great work, your library hits a sweet spot for me with its functionality & scope 👍

@egze
Copy link
Owner

egze commented Nov 24, 2024

Thanks for the PR. One way how to know if it's postgres or not, is to look at the Oban.config()

%Oban.Config{
  engine: ...
}

There are 3 engines:

  • Oban.Engines.Basic - postgres
  • Oban.Engines.Lite - sqlite
  • Oban.Engines.Inline - for testing

@@ -59,7 +59,7 @@ defmodule Obanalyze.ObanJobs do

from oj in query,
where: like(oj.worker, ^like),
or_where: like(oj.args, ^like)
or_where: like(fragment("?::text", oj.args), ^like)
Copy link
Owner

@egze egze Nov 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a postgres way of casting and sqlite doesn't do it like this. Try the explicit cast() function that both DBs support.

@maltoe maltoe force-pushed the allow-searching-on-postgres branch from a47ec9b to 5d25c93 Compare November 25, 2024 07:49
This patch changes the search implementation to explicitly cast the jsonb args column
to `text` before passing it to `like/2`.
@maltoe maltoe force-pushed the allow-searching-on-postgres branch from 5d25c93 to f4218c5 Compare November 25, 2024 07:53
Co-authored-by: Aleksandr Lossenko <aleksandr.lossenko@gmail.com>
@egze
Copy link
Owner

egze commented Nov 25, 2024

Great work, really appreciate it!

Your PR now makes me think that I need to setup different integration tests for Postgres and SQLite. Otherwise it can be tricky to know which queries work or not. Problem for future me.

@egze egze merged commit 30e2d6c into egze:main Nov 25, 2024
1 check passed
@maltoe maltoe deleted the allow-searching-on-postgres branch November 25, 2024 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants