dart_odbc 6.0.0 copy "dart_odbc: ^6.0.0" to clipboard
dart_odbc: ^6.0.0 copied to clipboard

A Dart package for interacting with ODBC databases. It allows you to connect to ODBC data sources and execute SQL queries directly from your Dart applications.

example/lib/example.dart

import 'package:dart_odbc/dart_odbc.dart';
import 'package:dotenv/dotenv.dart';

void main(List<String> args) {
  run(args);
}

Future<void> run(List<String> args) async {
  // loading variable from env
  final DotEnv env = DotEnv()..load(['.env']);

  // username for the database
  final username = env['USERNAME'];
  // password for the database
  final password = env['PASSWORD'];

  final dsn = env['DSN'];

  // optionally to select database
  final db = env['DATABASE'];

  final odbc = DartOdbc(dsn: dsn);
  await odbc.connect(username: username!, password: password!);

  if (db != null) {
    await odbc.execute('USE $db');
  }

  // Assume a table like this
  // +-----+-------+-------------+
  // | UID | NAME  | DESCRIPTION |
  // +-----+-------+-------------+
  // | 1   | Alice |             |
  // | 2   | Bob   |             |
  // +-----+-------+-------------+
  // The name is a column of size 150
  // The description is a column of size 500

  // result = odbc.execute(
  //   'SELECT * FROM USERS WHERE UID = ?',
  //   params: [1],
  // );
  List<Map<String, dynamic>> result = await odbc.execute(
    args[0], //  <-- SQL query
    params: args.sublist(1), // <-- SQL query parameters
  );

  print(result);

  // finally disconnect from the db
  await odbc.disconnect();
}
28
likes
0
points
223
downloads

Publisher

verified publisherslpirate.dev

Weekly Downloads

A Dart package for interacting with ODBC databases. It allows you to connect to ODBC data sources and execute SQL queries directly from your Dart applications.

Repository (GitHub)
View/report issues

Topics

#db #database #odbc #sqlserver #oracle

License

unknown (license)

Dependencies

ffi, logging

More

Packages that depend on dart_odbc