Skip to content

Commit

Permalink
refactor based on PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiecounsell committed Feb 1, 2025
1 parent 835def2 commit 570cb6e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion backend/utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def is_postgresql(conn: sa.Connection) -> bool:
return conn.engine.name == "postgresql"


def is_mysql(conn: sa.Connection) -> bool:
return conn.engine.name == "mysql"


def json_array_contains_value(
column: sa.Column, value: Any, *, session: Session
) -> ColumnElement:
Expand All @@ -29,7 +33,10 @@ def json_array_contains_value(
return sa.type_coerce(column, sa_pg.JSONB).contains(
func.cast(value, sa_pg.JSONB)
)
return func.json_contains(column, json.dumps(value))
elif is_mysql(conn):
# In MySQL, JSON.contains() requires a JSON-formatted string (even if it's an int)
return func.json_contains(column, json.dumps(value))
return func.json_contains(column, value)


def safe_float(value, default=0.0):
Expand Down

0 comments on commit 570cb6e

Please sign in to comment.