@@ -87,6 +87,7 @@ def setup():
8787 compiles (sql_path .file_stem , "sqlite" )(compile_path_file_stem )
8888 compiles (sql_path .file_ext , "sqlite" )(compile_path_file_ext )
8989 compiles (array .length , "sqlite" )(compile_array_length )
90+ compiles (array .contains , "sqlite" )(compile_array_contains )
9091 compiles (string .length , "sqlite" )(compile_string_length )
9192 compiles (string .split , "sqlite" )(compile_string_split )
9293 compiles (string .regexp_replace , "sqlite" )(compile_string_regexp_replace )
@@ -269,13 +270,16 @@ def create_string_functions(conn):
269270
270271 _registered_function_creators ["string_functions" ] = create_string_functions
271272
272- has_json_extension = functions_exist (["json_array_length" ])
273+ has_json_extension = functions_exist (["json_array_length" , "json_array_contains" ])
273274 if not has_json_extension :
274275
275276 def create_json_functions (conn ):
276277 conn .create_function (
277278 "json_array_length" , 1 , py_json_array_length , deterministic = True
278279 )
280+ conn .create_function (
281+ "json_array_contains" , 3 , py_json_array_contains , deterministic = True
282+ )
279283
280284 _registered_function_creators ["json_functions" ] = create_json_functions
281285
@@ -428,10 +432,22 @@ def py_json_array_length(arr):
428432 return len (orjson .loads (arr ))
429433
430434
435+ def py_json_array_contains (arr , value , is_json ):
436+ if is_json :
437+ value = orjson .loads (value )
438+ return value in orjson .loads (arr )
439+
440+
431441def compile_array_length (element , compiler , ** kwargs ):
432442 return compiler .process (func .json_array_length (* element .clauses .clauses ), ** kwargs )
433443
434444
445+ def compile_array_contains (element , compiler , ** kwargs ):
446+ return compiler .process (
447+ func .json_array_contains (* element .clauses .clauses ), ** kwargs
448+ )
449+
450+
435451def compile_string_length (element , compiler , ** kwargs ):
436452 return compiler .process (func .length (* element .clauses .clauses ), ** kwargs )
437453
0 commit comments