2

I'm trying to create a context with dataModel and persistentStore... Follow the code below working with PostgreSQL:

  @override
  Future prepare() async {
    logger.onRecord.listen((rec) => print("$rec ${rec.error ?? ""} ${rec.stackTrace ?? ""}"));

    final dataModel = ManagedDataModel.fromCurrentMirrorSystem();
    final persistentStore = PostgreSQLPersistentStore.fromConnectionInfo(
      "heroes_user", "password", "localhost", 5432, "heroes");

    context = ManagedContext(dataModel, persistentStore);
  }

I want use MySQL instead PostgreSQL, I dont find any tutorial using it.

Leonardo Severo
  • 470
  • 5
  • 13
  • Why do you want to use MySQL instead of PostgreSQL? – Suragch May 02 '19 at 19:19
  • I don't think it is necessary to use MySQL, but I am curios from a theoretical perspective how to add a different database. – Suragch May 03 '19 at 21:48
  • Cause I just have experience with MySQL, and my time is short to learn PostgreSQL! :/ – Leonardo Severo May 03 '19 at 21:58
  • I would expect you could use one of [these pub packages](https://stackoverflow.com/questions/11963444/how-to-connect-mysql-database-with-dart). It won't have the ORM that Aqueduct provides for PostgreSQL, though. – Suragch May 03 '19 at 22:32
  • [PostgreSQL vs MySQL](https://www.2ndquadrant.com/en/postgresql/postgresql-vs-mysql/) – Suragch May 03 '19 at 22:38
  • Thanks for the support dude, but u know if I can use sqljocky with aqueduct? (I'm using sqljocky as an example, but I'm talking about other kinda of packes) Can I create a connection and from it create the dataModel I need? – Leonardo Severo May 03 '19 at 22:49
  • You can use other packages along with Aqueduct. I've done that before. I haven't used an alternate database, but I don't expect the package itself to be a problem. The part I don't know is how to create a [service](http://aqueduct.io/docs/core_concepts/#services) for it. – Suragch May 03 '19 at 22:58
  • I have a persistentStore which get the connection object to create my ManagedContext. If I use these packages to create my connection, I can use it to create that persistentStore without any ploblem? – Leonardo Severo May 04 '19 at 00:41
  • I'm not sure. While waiting for someone who knows to answer, try it out and update your question with more details as you learn more. If your solve it yourself, all the better. You can add your own answer to help me and other people with the same question. – Suragch May 04 '19 at 01:51
  • You can use [mysql1](https://pub.dev/packages/mysql1) package to connect to MySQL I haven't tried it myself but the library looks well maintained – Nadeem Siddique May 10 '19 at 17:56

1 Answers1

4

Here is the general procedure using another type of database:

My recommendation:

  • Use the default PostgreSQL implementation. It will take a lot less time to learn than it will to implement everything on your own for MySQL. The default implementation is probably also better tested. With the ORM, you don't even use much raw PostgreSQL code anyway, which itself isn't significantly different than raw MySQL code.
  • You could also check out the Angel server, which seems to be more modular than Aqueduct, but you are still going to have to implement your own MySQL service. See this.
  • Do as much development as you can without choosing a framework or database. As a principle of clean architecture, these are details. If possible, abstract them away. See Clean architecture for the rest of us.
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393