Skip to content

Executing SQL synchronously via JSI #1401

Answered by scarlac
scarlac asked this question in Q&A
Discussion options

You must be logged in to vote

I'm sharing my solution, as it may be handy for others doing a transition. It assumes the availability of:

  1. const adapter = ... referring to the SQLiteJSI adapter
  2. const schema = ... referring to the appSchema definition
/**
 * Execute a raw SQL 'SELECT' query to the SQLite database.
 * You must always start with 'SELECT *' (all columns) to allow hydration (relation data => object)
 * SELECTs are safe, but UPDATE, DELETE, and INSERTs must follow up with a call to rawClearCache()!
 * otherwise data goes stale in other places
 * @param table Table name, used as part of the cache key (keyed as tableName@rowId)
 **/
export function rawQuery<T = any>(table: string, sql: string, args: any[] = []) 

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by scarlac
Comment options

You must be logged in to vote
2 replies
@scarlac
Comment options

@radex
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants