question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Share database queries between different dialects

See original GitHub issue

Description

I’m trying to develop a KMP project where server and client apps (jvm, Android, iOS and js) share the same database. The client must work offline so anything can be done locally or on the server. The client apps work using psqlite, the server postgresql.

Everything works fine if I use standard SQL in the queries. However the problems come where syntax differ. For example an upsert in sqlite would be:

REPLACE (...)
or a 
INSERT INTO (...) ON CONFLICT REPLACE

But in postgresql

INSERT INTO (...) ON CONFLICT (id) DO (...)

Is there a way or a plan to be able to work with this? Maybe it could be a way to specify the dialect of a query in the query definition (naming with the dialect like insert_sqlite: and insert_postgresql:)

Thanks!

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
vanniktechcommented, Oct 6, 2022

I also would not share the schema between server and frontend to be honest. I share my database between frontend (ios & android) and on server it’s a separate thing. Usually, clients don’t need to know every column. Also clients have some kind of uploading queues which the server does not need.

0reactions
mateuy-devcommented, Oct 10, 2022

@hfhbd thanks for the follow up.

At the end I’ve decided to divide sql files into common, psql and sqlite. I just use the common (most of the queries) for the generation of the two databases. Seeing that the common interfaces may disappear, I’ve created them manually and I delegate its methods to the current implementations. In this way I also join the common and non common queries in an interface. This is a bit of boilerplate, but I prefer it to the hack of reusing the interfaces.

If anyone wants to do this, here is my sample project

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Quick Guide to the Dialects of SQL - Towards Data Science
Written to give more power to queries within their ecosystem, T-SQL may be used with SQL Server Management Studio, Azure-based products, and  ......
Read more >
Understanding SQL Dialects - Arctype
There are numerous SQL dialects instead of one fully implemented SQL standard. In this post we learn about the major ones. Plus lists...
Read more >
Cross-database & cross-cluster queries - Azure Data Explorer
This article describes cross-database and cross-cluster queries in Azure Data Explorer.
Read more >
Save and share queries | BigQuery - Google Cloud
In the Google Cloud console, open the BigQuery page. · Click Compose new query. · Enter a valid SQL query in the Query...
Read more >
What is a database query? - TechTarget
A query gives meaning to the lines of code used in every query language. As such, both the user and the database exchange...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found