2

I am building an Expo app using expo-sqlite and TypeOrm through DataSource to interact with the mobile device built-in sqlite DB.

I need to use a regex matching function in a database query.

Here is my TypeOrm DataSource:

import * as SQLite from 'expo-sqlite'

new DataSource({
  database: 'db-name',
  type: 'expo',
  driver: SQLite,
  entities: [...entities],
  synchronize: true,
  logging: 'all',
})

Whenever I use REGEXP function as follows

const dataSource = await getDataSource()
const usersRepository = dataSource.getRepository(User)
const query = usersRepository.createQueryBuilder('user')

query.where(`user.name REGEXP 'stringQuery'`)

I get the error:

Error code 1: no such function: REGEXP

How can I define the REGEXP function or any other regex matching functionality?

3
  • 2
    See sqlite.org/… Commented Apr 29 at 21:05
  • I did read this article before, the problem is that with expo-sqlite i don't have an access to createFunction or loadExtension methods to apply this Commented Apr 30 at 11:08
  • 1
    Then you're probably out of luck. Commented Apr 30 at 17:44

1 Answer 1

1

Error no such function: REGEXP happens because SQLite does not include a built-in REGEXP function by default. Unlike LIKE or GLOB, REGEXP is a user-defined function that needs to be manually registered with the SQLite engine.

Use LIKE or GLOB instead of REGEXP

query.where("user.name LIKE :pattern", { pattern: `%stringQuery%` })

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.