Share database queries between different dialects
See original GitHub issueDescription
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:
- Created a year ago
- Comments:8 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
@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