Giter Club home page Giter Club logo

iw_database's Introduction

iw_database

This project is an implementation that allow developers to encapsulate their own usage of database clients.

The main objective of this project is to create a package that provide a database client encapsulated and by doing this allow developers to use it in many apps rather than create their own encapsulation for each project.

For now, the package supports only MySQL, however, other database clients could be supported in the future.

Usage

Here is an example that make some SQL requests using the supported MySQL method and also the way to handle database exceptions.

You can also read the unit tests to see all the possibilities that the implementation supports.

import 'dart:io';

import 'package:iw_database/iw_database.dart';

Future<void> main() async {
  try {
    final DatabaseProperties properties = DatabaseProperties(
      host: 'localhost',
      port: 3306,
      name: 'tests',
      username: 'root',
      password: 'root',
    );

    final DatabaseClientService service = MySQLDatabaseClientService(
      properties: properties,
    );

    await service.openConnection();

    final results = await service.executeQuery(
      sql: 'SELECT id, name FROM test_table WHERE id > :id',
      parameters: {
        'id': 5,
      },
    );

    print(results);
    
    // Prints:
    // DatabaseResult(rows: 5, results: [{id: 6, name: Teste 06}, {id: 7, name: Teste 07}, {id: 8, name: Teste 08}, {id: 9, name: Teste 09}, {id: 10, name: Teste 10}])


    await service.closeConnection();

    exit(0);
  } on DatabaseException catch (error) {
    print(error);
    exit(-1);
  }
}

Feito com โ™ฅ por Ivan Wilhelm.

Codificado no Visual Studio Code da Microsoft

iw_database's People

Stargazers

 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.