surrealdb 1.0.2 copy "surrealdb: ^1.0.2" to clipboard
surrealdb: ^1.0.2 copied to clipboard

SurrealDB client written in pure dart. Auto reconnect, Typed functions

example/example.dart

// ignore_for_file: avoid_print

import 'package:surrealdb/surrealdb.dart';

void main(List<String> args) async {
  const options = SurrealDBOptions();

  final client = SurrealDB('ws://localhost:8000/rpc', options: options)
    ..connect();
  await client.wait();
  await client.use('test', 'test');
  await client.signin(user: 'root', pass: 'root');

  final person = await client.create(
    'person',
    TestModel(marketing: false, title: 'Title'),
  );

  final person2 = await client.create('person', {
    'title': 'Founder & CEO',
    'name': {
      'first': 'Tobie',
      'last': 'Morgan Hitchcock',
    },
    'marketing': false,
  });

  final persons = await client.select<Map<String, dynamic>>('person');

  final groupByQuery = await client.query(
    r'SELECT marketing, count() FROM type::table($tb) GROUP BY marketing',
    {
      'tb': 'person',
    },
  );

  print(person);
  print(person2);
  print(persons);
  print(groupByQuery);
  client.close();
}

class TestModel {
  TestModel({required this.marketing, required this.title});

  factory TestModel.fromJson(Map<String, dynamic> json) {
    return TestModel(
      marketing: json['marketing'] as bool,
      title: json['title'] as String,
    );
  }

  final bool marketing;
  final String title;

  Map<String, Object> toJson() {
    return {
      'marketing': marketing,
      'title': title,
    };
  }
}
33
likes
160
pub points
66%
popularity

Publisher

verified publisherduhanbalci.com

SurrealDB client written in pure dart. Auto reconnect, Typed functions

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

uuid, web_socket_channel

More

Packages that depend on surrealdb