Giter Club home page Giter Club logo

sqljocky5's Introduction

SQLJocky5

MySQL client for Dart.

Creating a connection

  var s = ConnectionSettings(
    user: "root",
    password: "dart_jaguar",
    host: "localhost",
    port: 3306,
    db: "example",
  );
  var conn = await MySqlConnection.connect(s);

Closing a connection

  await conn.close();

Execute a query

Results results = await conn.execute('select name, email from users');

Results is an iterable of Row. Columns can be accessed from Row using integer index or by name.

results.forEach((Row row) {
  // Access columns by index
  print('Name: ${row[0]}, email: ${row[1]}');
  // Access columns by name
  print('Name: ${row.name}, email: ${row.email}');
});

Prepared query

await conn.prepared('insert into users (name, email, age) values (?, ?, ?)',
  ['Bob', '[email protected]', 25]);

Insert id

An insert query's results will be empty, but will have an id if there was an auto-increment column in the table:

print("New user's id: ${result.insertId}");

Prepared multiple queries

var results = await query.preparedMulti(
  'insert into users (name, email, age) values (?, ?, ?)',
  [['Bob', '[email protected]', 25],
   ['Bill', '[email protected]', 26],
   ['Joe', '[email protected]', 37]]);

Transactions

Transaction trans = await pool.begin();
try {
  var result1 = await trans.execute('...');
  var result2 = await trans.execute('...');
  await trans.commit();
} catch(e) {
  await trans.rollback();
}

Safe transaction

await pool.transaction((trans) {
  var result1 = await trans.execute('...');
  var result2 = await trans.execute('...');
});

TODO

  • Compression
  • COM_SEND_LONG_DATA
  • CLIENT_MULTI_STATEMENTS and CLIENT_MULTI_RESULTS for stored procedures
  • Better handling of various data types, especially BLOBs, which behave differently when using straight queries and prepared queries.
  • Implement the rest of mysql's commands
  • Handle character sets properly? Currently defaults to UTF8 for the connection character set. Is it necessary to support anything else?
  • Improve performance where possible
  • Geometry type
  • Decimal type should probably use a bigdecimal type of some sort
  • MySQL 4 types (old decimal, anything else?)
  • Test against multiple mysql versions

sqljocky5's People

Contributors

adamlofts avatar astashov avatar faisalabid avatar hexer10 avatar ibala2012 avatar jamesots avatar kaetemi avatar kevmoo avatar sethladd avatar tejainece avatar tomcaserta avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.