Skip to content

Support other sql dialects #79

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

Open
simolus3 opened this issue Jul 19, 2019 · 19 comments
Open

Support other sql dialects #79

simolus3 opened this issue Jul 19, 2019 · 19 comments
Labels
enhancement New feature or request

Comments

@simolus3
Copy link
Owner

simolus3 commented Jul 19, 2019

Current status of other dialects: We have initial support for them, but drift puts its main focus on sqlite3 and some features may not fully work with other database systems.

You can use drift with postgres or MariaDB by adding a git dependency to the respective packages. These packages aren't stable, but all kind of feedback is much appreciated!


I am looking for a way to have my database running on a server and use moor to not deal with plain sql. For my purposes, I do not need my the auto updating part. I believe it is currently not possible to connect to remote dbs, do you plan to make this possible in the future?

Originally posted by @jwallat in #32 (comment)

Connecting to a server DBMS should be fairly straightforward by implementing a custom QueryExecutor. However, the generated queries are designed to work with sqlite, so we might have to modify that code to work with other database engines. @jwallat is there a specific database engine you have in mind? I'd take a look at that first then.

@simolus3 simolus3 added the enhancement New feature or request label Jul 19, 2019
@jwallat
Copy link

jwallat commented Jul 19, 2019 via email

@simolus3
Copy link
Owner Author

Yeah, sqlite on a server doesn't really scale, MariaDb/MySQL will work much better.

I just managed to connect moor to a MySql server here, but it already throws at the first statement because of a syntax error. The generated statements are designed to work with sqlite at the moment, so that was expected :D I'll try to add proper support for MySQL soon.

@Sacchid
Copy link

Sacchid commented Jul 26, 2019

@simolus3
Copy link
Owner Author

Good to know, thanks. I'll take a look at it. We use sqljockey for MySQL, which seems to work good so far. The main problem is that database engines all have a slightly different interpretation of sql, so we need to adapt the generation code to reflect that. Swapping out the underlying driver is rather easy.

@Sacchid
Copy link

Sacchid commented Jul 27, 2019

Ok, I just shared that as Aqueduct.io has PostgreSQL based Statically-typed ORM and Database Migration and as you might know is a very stable open source REST framework written in dart.

@simolus3 simolus3 changed the title Support other databases Support other sql dialects Jul 28, 2019
@jaumard
Copy link

jaumard commented Dec 17, 2019

I would be interested in PostgreSQL support :)
Any tips (steps) on how to start to provide such feature ?

@simolus3
Copy link
Owner Author

Any tips (steps) on how to start to provide such feature ?

There are different aspects to this:

  1. Moor needs to be able to send statements to a database. For this, you can implement a DatabaseDelegate (defined in package:moor/backends.dart). It has methods like runInsert, runUpdate, runSelect, etc. Those will be called by moor to support the database. A good starting point for this could be the implementation of the FlutterQueryExecutor here. If you know a good Postgres library for Dart, writing a DatabaseDelegate for moor hopefully comes down to just wrapping that library.
  2. Support it when generating queries from the Dart DSL: Technically, it should be possible to use moor with postgres after a DatabaseDelegate has been written. In practice, that's probably not going to work if there are differences between PostgresSQL and sqlite syntax. Those need to be handled in moor.

I'm not sure if and how we should support different dialects in .moor files yet. Maybe we can rewrite them to work on different engines, but I didn't put a lot of thought into that so far.

The majority of moor users use Flutter or some other client-side Dart, so supporting different engines isn't a big priority for me. But if you're interested in working on a DatabaseDelegate for Postgres I'll support you as best as I can. If you run into problems because of different syntax in Postgres and sqlite, I'll gladly help resolve them with changes to moor.

@westito
Copy link
Collaborator

westito commented Oct 23, 2021

I would be interested in PostgreSQL support :)
Any tips (steps) on how to start to provide such feature ?

Postgres PR: #1507

@PlugFox
Copy link

PlugFox commented Oct 27, 2021

We need a good ORM for postgres on dart)
Thanks you @westito

@gisborne
Copy link

gisborne commented Apr 22, 2022

FYI SQLite works just fine on a server, . So you might want to explore support for BedrockDB.

Presumably, it would be fairly easy.

Although I’m pretty excited about Postgres support.

@westito
Copy link
Collaborator

westito commented Apr 25, 2022

According to Bedrock documentation it is compatible with MySQL. A mysql dialect may fit for this RDBM. However, the current implementation of Drift makes hard to create dialects (this Postgres dialect also has many hacks to get it work). Drift is under refactor right now to make it more generic and handle dialects more easily. Be patient.

@odunboye
Copy link

Is there MySQL support?

@vanlooverenkoen
Copy link

I am using SQLite on server side at the moment. But as it was already mentioned. This will not scale very good. But it does work if for certain applications.

@gisborne
Copy link

gisborne commented Oct 7, 2022

Just offering some advice: SQLite is absolutely suitable for a lot of quite heavy-use sites.

Expensify even built a traditional database server based on SQLite, supporting redundancy and failover and all sorts of goodies.

I would still prefer Postgres because of other features it has. But SQLite is efficient even under heavy load.

@vanlooverenkoen
Copy link

What would you consider heavy load?

@gisborne
Copy link

gisborne commented Oct 7, 2022

Expensify is a very popular, heavy-use app, and it has scaled just fine with SQLite.

SQLite can handle just about any load; it's a question of whether its other features suit the application.

Traditionally embedded SQLite doesn't support failover and such, and requires pretty much one application server that holds the database. That is a limitation.

But either sharding or Bedrock DB or some plugins that are available get around that.

I would much rather use SQLite than MySQL or SQL Server. I would somewhat prefer to use Postgres because it has the best SQL features, but SQLite is pretty good.

@egyleader
Copy link

+1 voting for postgres support

@f-person
Copy link

@egyleader, it's been already implemented in #1507.

@simolus3 i wonder if this issue should be closed? Or can the initial comment on the issue be updated to track the progress/plans for any other future DB servers?

@simolus3
Copy link
Owner Author

I think the issue should stay open since we don't have stable support for other dialects, but I've updated the original issue to mention the current state of the ongoing work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests