Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to support other SQL dialects? #1009

Closed
Wavesonics opened this issue Oct 12, 2018 · 26 comments
Closed

Is it possible to support other SQL dialects? #1009

Wavesonics opened this issue Oct 12, 2018 · 26 comments
Labels
component: sql-psi Should be implemented in https://github.com/AlecStrong/sql-psi enhancement

Comments

@Wavesonics
Copy link

Being able to support MySQL or Postgres would be an awesome feature for non-mobile projects.

Would this be easy to accomplish with sqldelight? Or are things pretty tightly coupled to Sqlite?

@AlecKazakova
Copy link
Collaborator

we definitely intend on doing this. There isn't a ton of adjustments needed to make it work but right now it is strictly tied to sqlite, but only the dialect not the engine itself.

The sample sqlite driver we provide here: https://github.com/square/sqldelight/tree/master/drivers/sqlite-driver is actually just a wrapper around a jdbc sqlite driver (xerial). It would be possible to instead use a MySQL/Postgres jdbc driver with the same wrapper and then run the apis we generate. You'd be restricted to SQLite syntax (which is kind of a subset of SQL) though so it's more a hack than an actual feature at the moment

@Wavesonics
Copy link
Author

Well great to know it's on your minds, I would love to use this in other environments.

@ScottPierce
Copy link

It looks like Xerial supports several database types, including MySql and Postgres. Supporting this might be fairly trivial.

@AlecKazakova
Copy link
Collaborator

yea the driver side is fairly easily covered, but we have to switch out the dialect going in because we currently wouldnt support something like

CREATE TABLE stuff (
  text VARCHAR(20)
);

@AlecKazakova
Copy link
Collaborator

(which also shouldnt be insanely hard, just not focusing on it till post-1.0)

@AlecKazakova AlecKazakova pinned this issue Jan 10, 2019
@AlecKazakova AlecKazakova unpinned this issue Jan 10, 2019
@AlecKazakova AlecKazakova pinned this issue Jan 10, 2019
@dibog
Copy link

dibog commented Jan 11, 2019

+1 for Postgres and HSQLDB

@dibog
Copy link

dibog commented Jan 11, 2019

In case you support additional databases: Would you also support datasources to be able to use the SQLDelight in a multi-thread context?

@AlecKazakova
Copy link
Collaborator

we've set it up so that multithreading is up to the driver, so yea shouldnt be a problem

@AlecKazakova AlecKazakova added the component: sql-psi Should be implemented in https://github.com/AlecStrong/sql-psi label Jan 12, 2019
@GianfrancoMS
Copy link
Contributor

GianfrancoMS commented Jun 4, 2019

Any updates on this issue? I would love to use sqldelight on the backend.

@AlecKazakova
Copy link
Collaborator

i have begun the process of thinking deeply about it

@AlecKazakova
Copy link
Collaborator

holy fuck 22 thumbs up

@ScottPierce
Copy link

Lol. I'd prefer using something like this to interact with databases on a server than all the crappy ORMs that are out there. I think a lot of people feel the same.

@NikkyAI
Copy link

NikkyAI commented Oct 21, 2019

I wonder if it would be possible to speed up this issue somehow, bugbounty or such ?

@Aditya94A
Copy link

Can anyone recommend a good library (ORM or not) for dealing with databases with a Kotlin backend? (Exposed doesn't seem very mature and there aren't a lot of others built for Kotlin libraries for this)

@meoyawn
Copy link

meoyawn commented Dec 14, 2019

https://mybatis.org/mybatis-3/ it's like https://developer.android.com/training/data-storage/room/index.html but reflection-based and very mature

Use it in https://listenbox.app/ with ktor (1.4k MAU), couldn't find anything better on the JVM

@ScottPierce
Copy link

@AlecStrong Do you have any updated thoughts on this a year later? This issue is at 66 thumbs up now.

@AlecKazakova
Copy link
Collaborator

i'd like to incrementally get this working. Goal right now is for some semblance of MySQL support - I'll start with adding column types but if there's other parts of MySQL's dialect which aren't in SQLite let me know and I can focus on that before the next release

@AlecKazakova
Copy link
Collaborator

with 1.3.0 you can enable mysql as follows

sqldelight {
  MyDatabase {
    dialect = "mysql"
  }
}

// Use the jdbc driver to power it, requires an overriding class that provides a JDBC connection
dependencies {
    implementation "com.squareup.sqldelight:jdbc-driver:1.3.0"
}

@Savrov
Copy link

Savrov commented May 2, 2020

@AlecStrong sorry, for my incompetence in this field, but does it mean that a developer can write SQL queries in MySQL-manner (using some MySQL special functions)? And how is it possible to connect to an external MySQL database. Thank you.
P.S. I would like to use SqlDelight within my apps and backend server with a shared infrastructure layer. As I suppose there should be the only difference in setup (like connecting to MySQL database) and importing inside build.gradle files.

@LouisCAD
Copy link
Contributor

LouisCAD commented May 2, 2020

@Savrov To connect to an external MySQL database, you need to configure the JDBC driver and connection accordingly in your code. This should be no different that without SqlDelight and only JDBC for the connection part.

@travisfw
Copy link

How can I contribute to SqlDelight for Postgres?

@AlecKazakova
Copy link
Collaborator

to start there needs to be a grammar for postgres which starts overriding rules, similar to how we've done for mysql: https://github.com/AlecStrong/sql-psi/tree/master/core/src/main/kotlin/com/alecstrong/sql/psi/core/mysql

thats the hard part, the rest is easy! I'm focused on mysql/sqlite support and would absolutely love if postgres was contributed

@veyndan
Copy link
Collaborator

veyndan commented May 15, 2020

I've been using a fairly trivial implementation of the PostgreSQL dialect for a side project. The grammar only consists of the column types that I've been using. I'll polish it up and try to make a PR sometime over the weekend ✌️

@AlecKazakova
Copy link
Collaborator

amazing - yea the goal isn't to have complete grammars off the bat but build stuff out as it comes up

@AlecKazakova
Copy link
Collaborator

Alright I'm CLOSING THIS ONE OUT. We'll have 1.4.0 out soon which has mysql/postgres/h2 support in varying levels of usability, mysql having the most at the moment. It'll be documented more in that release, and from there we should have separate issues for unsupported features of those dialects. THANKS ALL ENJOY

@AlecKazakova
Copy link
Collaborator

AlecKazakova commented Jun 4, 2020

if you want to use it today target the snapshots and use the gradle flag

sqldelight {
  MyDatabase {
    dialect = "mysql" // or postgresql, hsql
  }
}

@AlecKazakova AlecKazakova unpinned this issue Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: sql-psi Should be implemented in https://github.com/AlecStrong/sql-psi enhancement
Projects
None yet
Development

No branches or pull requests