2021-07-25 13:55:58 +00:00
# Angel3 ORM for MySQL
2021-12-20 04:25:43 +00:00
![Pub Version (including pre-releases) ](https://img.shields.io/pub/v/angel3_orm_mysql?include_prereleases )
2021-06-18 10:15:23 +00:00
[![Null Safety ](https://img.shields.io/badge/null-safety-brightgreen )](https://dart.dev/null-safety)
[![Gitter ](https://img.shields.io/gitter/room/angel_dart/discussion )](https://gitter.im/angel_dart/discussion)
2021-12-20 04:25:43 +00:00
[![License ](https://img.shields.io/github/license/dukefirehawk/angel )](https://github.com/dukefirehawk/angel/tree/master/packages/orm/angel_orm_mysql/LICENSE)
2021-06-18 10:15:23 +00:00
2022-04-23 04:21:39 +00:00
This package contains the SQL Executor required by Angel3 ORM to work with MySQL and MariaDB respectively. In order to better support the differences in MySQL and MariaDb underlying protocols, two different drives have to be used. For MariaDb 10.2.x, `mysql1` driver provides the best results, while `mysql_client` driver handles MySQL 8.x.x without issues.
2021-06-18 10:15:23 +00:00
2022-07-16 02:44:49 +00:00
* MariaDbExecutor
* MySqlExecutor
2022-01-02 07:21:17 +00:00
2022-04-23 04:21:39 +00:00
## Supported database version
2022-01-02 07:21:17 +00:00
2022-04-23 04:21:39 +00:00
* MariaDb 10.2.x
2022-04-24 00:55:17 +00:00
* MySQL 8.x
2022-01-02 07:21:17 +00:00
2022-04-23 04:21:39 +00:00
**Note** MySQL below version 8.0 and MariaDB below version 10.2 are not supported as Angel3 ORM requires common table expressions (CTE).
2022-04-24 02:59:03 +00:00
## Connecting to MariaDB database 10.2.x
2022-04-23 04:21:39 +00:00
```dart
2022-04-24 02:59:03 +00:00
import 'package:mysql1/mysql1.dart';
2022-04-23 04:21:39 +00:00
var settings = ConnectionSettings(
host: 'localhost',
port: 3306,
db: 'orm_test',
2022-07-16 02:44:49 +00:00
user: 'test',
password: 'test123');
2022-04-23 04:21:39 +00:00
var connection = await MySqlConnection.connect(settings);
2022-04-24 02:59:03 +00:00
var logger = Logger('orm_mariadb');
2022-04-23 04:21:39 +00:00
var executor = MariaDbExecutor(connection, logger: logger);
```
2022-04-24 02:59:03 +00:00
## Connecting to MySQL database 8.x
2022-04-23 04:21:39 +00:00
```dart
2022-04-24 02:59:03 +00:00
import 'package:mysql_client/mysql_client.dart';
2022-04-23 04:21:39 +00:00
var connection = await MySQLConnection.createConnection(
host: "localhost",
port: 3306,
databaseName: "orm_test",
userName: "test",
2022-07-16 02:44:49 +00:00
password: "test123",
2022-04-23 04:21:39 +00:00
secure: false);
var logger = Logger('orm_mysql');
await connection.connect(timeoutMs: 10000);
var executor = MySqlExecutor(connection, logger: logger);
```
2022-05-16 05:04:21 +00:00
2022-07-16 02:44:49 +00:00
### Issues
* Blob
* DateTime value not in UTC
* Transaction is broken
## Creating a new database in MariaDB/MySQL
1. Login to MariaDB/MySQL database console with the following command.
```bash
mysql -u root -p
```
1. Run the following commands to create a new database, `orm_test` and grant both local and remote access to user, `test` . Replace `orm_test` , `test` and `test123` with your own database name, username and password respectively.
```mysql
create database orm_test;
create user 'test'@'localhost' identified by 'test123';
grant all privileges on orm_test.* to 'test'@'localhost';
create user 'test'@'%' identified by 'test123';
grant all privileges on orm_test.* to 'test'@'%';
```
2022-05-16 05:04:21 +00:00
## Known limitation
2022-07-16 02:44:49 +00:00
### Using `mysql1` driver on MariabDb
* Blob
* DateTime value not in UTC
* Transaction is broken
### Using `mysql1` driver on MySQL
* Blob is not supported
### Using `mysql_client` driver on MariabDb
* Blob is not supported
### Using `mysql_client` driver on MySQL
2022-05-16 05:04:21 +00:00
* Blob is not supported