Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.62k stars 600 forks source link

Is it possible to execute multiple queries in a single statement ? #1724

Open alvinlal opened 11 months ago

alvinlal commented 11 months ago

is something like this possible 👇 , i have tried this and only the first query is being executed and rest is ignored.

await this.database
      .get('contact')
      .query(
      Q.unsafeSqlQuery(`
     INSERT OR REPLACE INTO contact (id,phone_number,contact_name) VALUES (1,'+91726353533','john doe');\n
     INSERT OR REPLACE INTO contact (id,phone_number,contact_name) VALUES (2,'+91726352222','jane doe');\n
     INSERT OR REPLACE INTO contact (id,phone_number,contact_name) VALUES (3,'+91726352225','chris doe');\n
     `)
iliapnmrv commented 10 months ago

no, it seems not to be possible. you might need call db and query multiple times

radex commented 6 months ago

See src/adapters/sqlite/type.ts, the key word is unsafeExecuteMultiple. It's possible, but you have to be careful about changing things that may be cached on JS side, as it could mess up queries.