mirror of https://github.com/AMT-Cheif/drift.git
Delete mysql extra
This commit is contained in:
parent
29bb6a73c8
commit
d220892f64
|
@ -1,11 +0,0 @@
|
|||
# Files and directories created by pub
|
||||
.dart_tool/
|
||||
.packages
|
||||
# Remove the following pattern if you wish to check in your lock file
|
||||
pubspec.lock
|
||||
|
||||
# Conventional directory for build outputs
|
||||
build/
|
||||
|
||||
# Directory created by dartdoc
|
||||
doc/api/
|
|
@ -1,26 +0,0 @@
|
|||
Experimental support for using Moor with an MySQL server.
|
||||
|
||||
## Using this
|
||||
For general notes on using moor, see [this guide](https://moor.simonbinder.eu/getting-started/).
|
||||
To use the MySQL backend, also add this to your pubspec (you don't need to depend on
|
||||
`moor_flutter`).
|
||||
```yaml
|
||||
dependencies:
|
||||
moor: "$latest version"
|
||||
moor_mysql:
|
||||
git:
|
||||
url: https://github.com/simolus3/moor.git
|
||||
path: extras/mysql
|
||||
```
|
||||
|
||||
Then, instead of using a `FlutterQueryExecutor`, use a `MySqlBackend` with the
|
||||
right [`ConnectionSettings`](https://pub.dev/documentation/sqljocky5/latest/connection_settings/ConnectionSettings-class.html).
|
||||
You'll need to import `package:moor_mysql/moor_mysql.dart`.
|
||||
|
||||
## Limitations
|
||||
We're currently experimenting with other database engines - Moor was mainly designed for
|
||||
sqlite and supporting advanced features of MySQL is not a priority right now.
|
||||
- No migrations - you'll need to create your tables manually
|
||||
- Some statements don't work
|
||||
- Compiled custom queries don't work - we can only parse sqlite. Of course, runtime custom
|
||||
queries with `customSelect` and `customUpdate` will work as expected.
|
|
@ -1,21 +0,0 @@
|
|||
version: "3.7"
|
||||
|
||||
services:
|
||||
database:
|
||||
image: mariadb
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: password
|
||||
MYSQL_DATABASE: example
|
||||
ports:
|
||||
- "3306:3306"
|
||||
phpmyadmin:
|
||||
depends_on:
|
||||
- database
|
||||
image: phpmyadmin/phpmyadmin
|
||||
ports:
|
||||
- "8080:80"
|
||||
environment:
|
||||
PMA_HOST: database
|
||||
PMA_USER: root
|
||||
PMA_PASSWORD: password
|
||||
PMA_PORT: 3306
|
|
@ -1,100 +0,0 @@
|
|||
/// Experimental support to run moor on a mysql backend.
|
||||
library moor_mysql;
|
||||
|
||||
import 'package:moor/backends.dart';
|
||||
import 'package:moor/moor.dart';
|
||||
import 'package:sqljocky5/connection/connection.dart';
|
||||
import 'package:sqljocky5/sqljocky.dart';
|
||||
|
||||
export 'package:sqljocky5/sqljocky.dart' show ConnectionSettings;
|
||||
|
||||
class MySqlBackend extends DelegatedDatabase {
|
||||
MySqlBackend(ConnectionSettings settings)
|
||||
: super(_MySqlDelegate(settings), logStatements: true);
|
||||
}
|
||||
|
||||
mixin _MySqlExecutor on QueryDelegate {
|
||||
Querier get _querier;
|
||||
|
||||
@override
|
||||
Future<void> runCustom(String statement, List args) async {
|
||||
await _querier.prepared(statement, args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> runInsert(String statement, List args) async {
|
||||
final result = await _querier.prepared(statement, args);
|
||||
return result.insertId;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<QueryResult> runSelect(String statement, List args) async {
|
||||
final result = await _querier.prepared(statement, args);
|
||||
|
||||
final columns = [for (var field in result.fields) field.name];
|
||||
final rows = result.toList();
|
||||
|
||||
return QueryResult(columns, rows);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> runUpdate(String statement, List args) async {
|
||||
final result = await _querier.prepared(statement, args);
|
||||
|
||||
return result.affectedRows;
|
||||
}
|
||||
}
|
||||
|
||||
class _MySqlDelegate extends DatabaseDelegate with _MySqlExecutor {
|
||||
final ConnectionSettings _settings;
|
||||
|
||||
MySqlConnection _connection;
|
||||
|
||||
_MySqlDelegate(this._settings);
|
||||
|
||||
@override
|
||||
bool get isOpen => _connection != null;
|
||||
|
||||
@override
|
||||
Querier get _querier => _connection;
|
||||
|
||||
@override
|
||||
final DbVersionDelegate versionDelegate = const NoVersionDelegate();
|
||||
|
||||
@override
|
||||
TransactionDelegate get transactionDelegate => _TransactionOpener(this);
|
||||
|
||||
@override
|
||||
SqlDialect get dialect => SqlDialect.mysql;
|
||||
|
||||
@override
|
||||
Future<void> open(_) async {
|
||||
_connection = await MySqlConnection.connect(_settings);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() async {
|
||||
await _connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
class _TransactionOpener extends SupportedTransactionDelegate {
|
||||
final _MySqlDelegate _delegate;
|
||||
|
||||
_TransactionOpener(this._delegate);
|
||||
|
||||
@override
|
||||
void startTransaction(Future Function(QueryDelegate) run) {
|
||||
_delegate._connection.transaction((transaction) async {
|
||||
final executor = _TransactionExecutor(transaction);
|
||||
await run(executor);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class _TransactionExecutor extends QueryDelegate with _MySqlExecutor {
|
||||
@override
|
||||
final Querier _querier;
|
||||
|
||||
_TransactionExecutor(this._querier);
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
name: moor_mysql
|
||||
description: MySQL support for moor
|
||||
version: 1.0.0
|
||||
author: Simon Binder <oss@simonbinder.eu>
|
||||
|
||||
environment:
|
||||
sdk: '>=2.4.0 <3.0.0'
|
||||
|
||||
dependencies:
|
||||
moor: ^2.0.0
|
||||
sqljocky5: ^2.2.0
|
||||
|
||||
dev_dependencies:
|
||||
test: ^1.6.0
|
||||
|
||||
dependency_overrides:
|
||||
moor:
|
||||
path: ../../moor
|
Loading…
Reference in New Issue