@@ -14,7 +14,7 @@ import { AnyNullClass, DbNullClass, JsonNullClass } from '../../../common-types'
1414import type { BuiltinType , FieldDef , GetModels , SchemaDef } from '../../../schema' ;
1515import { DELEGATE_JOINED_FIELD_PREFIX } from '../../constants' ;
1616import type { FindArgs } from '../../crud-types' ;
17- import { createInternalError } from '../../errors' ;
17+ import { createInternalError , createNotSupportedError } from '../../errors' ;
1818import {
1919 getDelegateDescendantModels ,
2020 getManyToManyRelation ,
@@ -374,7 +374,15 @@ export class SqliteCrudDialect<Schema extends SchemaDef> extends BaseCrudDialect
374374 value : unknown ,
375375 ) {
376376 return match ( operation )
377- . with ( 'array_contains' , ( ) => sql < any > `EXISTS (SELECT 1 FROM jsonb_each(${ lhs } ) WHERE value = ${ value } )` )
377+ . with ( 'array_contains' , ( ) => {
378+ if ( Array . isArray ( value ) ) {
379+ throw createNotSupportedError (
380+ 'SQLite "array_contains" only supports checking for a single value, not an array of values' ,
381+ ) ;
382+ } else {
383+ return sql < any > `EXISTS (SELECT 1 FROM jsonb_each(${ lhs } ) WHERE value = ${ value } )` ;
384+ }
385+ } )
378386 . with ( 'array_starts_with' , ( ) =>
379387 this . eb ( this . eb . fn ( 'json_extract' , [ lhs , this . eb . val ( '$[0]' ) ] ) , '=' , value ) ,
380388 )
@@ -390,7 +398,7 @@ export class SqliteCrudDialect<Schema extends SchemaDef> extends BaseCrudDialect
390398 ) {
391399 return this . eb . exists (
392400 this . eb
393- . selectFrom ( this . eb . fn ( 'json_each ' , [ receiver ] ) . as ( '$items' ) )
401+ . selectFrom ( this . eb . fn ( 'jsonb_each ' , [ receiver ] ) . as ( '$items' ) )
394402 . select ( this . eb . lit ( 1 ) . as ( '$t' ) )
395403 . where ( buildFilter ( this . eb . ref ( '$items.value' ) ) ) ,
396404 ) ;
0 commit comments