Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adamlofts/mysql1_dart
MySQL driver for Dart
https://github.com/adamlofts/mysql1_dart
dart mysql mysql-driver
Last synced: 4 days ago
JSON representation
MySQL driver for Dart
- Host: GitHub
- URL: https://github.com/adamlofts/mysql1_dart
- Owner: adamlofts
- License: other
- Created: 2018-09-03T14:02:21.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-01-16T11:09:14.000Z (12 months ago)
- Last Synced: 2024-12-17T08:08:33.529Z (11 days ago)
- Topics: dart, mysql, mysql-driver
- Language: Dart
- Size: 1010 KB
- Stars: 134
- Watchers: 9
- Forks: 46
- Open Issues: 70
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
mysql1
======A MySQL driver for the Dart programming language. Works on Flutter and on the server.
This library aims to provide an easy to use interface to MySQL. `mysql1` originated
as a fork of the SQLJocky driver.Usage
-----Connect to the database
```dart
var settings = new ConnectionSettings(
host: 'localhost',
port: 3306,
user: 'bob',
password: 'wibble',
db: 'mydb'
);
var conn = await MySqlConnection.connect(settings);
```Execute a query with parameters:
```dart
var userId = 1;
var results = await conn.query('select name, email from users where id = ?', [userId]);
```Use the results:
```dart
for (var row in results) {
print('Name: ${row[0]}, email: ${row[1]}');
});
```Insert some data
```dart
var result = await conn.query('insert into users (name, email, age) values (?, ?, ?)', ['Bob', '[email protected]', 25]);
```An insert query's results will be empty, but will have an id if there was an auto-increment column in the table:
```dart
print("New user's id: ${result.insertId}");
```Execute a query with multiple sets of parameters:
```dart
var results = await query.queryMulti(
'insert into users (name, email, age) values (?, ?, ?)',
[['Bob', '[email protected]', 25],
['Bill', '[email protected]', 26],
['Joe', '[email protected]', 37]]);
```Update some data:
```dart
await conn.query(
'update users set age=? where name=?',
[26, 'Bob']);
```Flutter Web
-----------This package opens a socket to the database. The web platform does not support sockets and so this package does not work on flutter web.