opendbs 1.0.0 copy "opendbs: ^1.0.0" to clipboard
opendbs: ^1.0.0 copied to clipboard

Official Flutter/Dart client library for OpenDBS, the high-performance database with Node.js/Rust architecture.

example/main.dart

import 'package:opendbs/opendbs.dart';

void main() async {
  print("๐Ÿš€ Starting OpenDBS Flutter/Dart Client Example...");

  // 1. Initialize
  final client = OpenDBS('http://localhost:4402', ignoreSSL: true);

  try {
    // 2. Login
    print("๐Ÿ”‘ Logging in...");
    final loginRes = await client.login('admin', 'admin123');
    print("โœ… Logged in as: ${loginRes['user']['username']}");

    // 3. Create Database
    print("๐Ÿ“‚ Creating database 'flutter_demo_db'...");
    try {
      await client.createDatabase('flutter_demo_db');
      print("   Database created.");
    } catch (e) {
      print("   โ„น๏ธ  Database might already exist ($e)");
    }

    // 4. Create Racks
    print("๐Ÿ“ฆ Creating racks...");
    try {
      await client.createRack('flutter_demo_db', 'users', type: 'nosql');
      print("   NoSQL Rack 'users' created.");
    } catch (e) {}

    try {
      await client.createRack(
        'flutter_demo_db',
        'orders',
        type: 'sql',
        schema: {
          'id': {'type': 'number', 'required': true},
          'total': {'type': 'number'},
        },
      );
      print("   SQL Rack 'orders' created.");
    } catch (e) {}

    // 5. Insert Data
    print("๐Ÿ“ Inserting data...");
    await client.insert('flutter_demo_db', 'users', {
      'name': 'Dart Vader',
      'email': 'dart@example.com',
    });

    try {
      await client.sql(
        'flutter_demo_db',
        "INSERT INTO orders (id, total) VALUES (999, 123.45)",
      );
    } catch (e) {
      print("โš ๏ธ SQL Insert failed: $e");
    }
    print("โœ… Data inserted.");

    // 6. Search
    print("๐Ÿ” Searching...");
    final users = await client.find('flutter_demo_db', 'users');
    print("   Found ${users.length} users.");

    // 7. Fuzzy Search
    print("โšก Testing Fuzzy Search...");
    final fuzzy = await client.fuzzySearch(
      'flutter_demo_db',
      'users',
      'name',
      'Vader',
    );
    print("   Fuzzy Results: $fuzzy");

    // 8. Cleanup
    print("\n๐Ÿงน Cleaning up resources...");
    try {
      await client.deleteRack('flutter_demo_db', 'users');
    } catch (e) {}
    try {
      await client.deleteRack('flutter_demo_db', 'orders');
    } catch (e) {}
    try {
      await client.deleteDatabase('flutter_demo_db');
    } catch (e) {}
    print("   Deleted temporary resources.");
  } catch (e) {
    if (e.toString().contains('Connection refused')) {
      print("\nโŒ Error: Could not connect to OpenDBS at http://localhost:4402");
    } else {
      print("\nโŒ Error: $e");
    }
  }
}
0
likes
140
points
--
downloads

Publisher

unverified uploader

Official Flutter/Dart client library for OpenDBS, the high-performance database with Node.js/Rust architecture.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, http

More

Packages that depend on opendbs