SurrealDB client written in pure dart. auto reconnect, typed functions

Overview

Tests

SurrealDB Client For Dart & Flutter

SurrealDB client for Dart and Flutter.

Quick Start

import 'package:surrealdb/surrealdb.dart';

void main(List<String> args) async {
  final client = SurrealDB('ws://localhost:8000/rpc');

  client.connect();
  await client.wait();
  await client.use('test', 'test');
  await client.signin(user: 'root', pass: 'root');

  await client.create('person', TestModel(false, 'title'));

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

  List<Map<String, Object?>> persons = await client.select('person');

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

  print(groupBy);

  print(persons.length);
}

Features

connect()

Connects to a database endpoint provided in constructer and authenticate with token if provided in constructer.

close()

Closes the persistent connection to the database.

wait()

Ensures connections established with the database and pinged successfully.

ping()

Closes the persistent connection to the database.

use(String namespace, String database)

Switch to a specific namespace and database.

info()

Retrieve info about the current Surreal instance

signup(String user, String pass)

Signs up to a specific authentication scope

signin(String user, String pass)

Signs in to a specific authentication scope

invalidate()

Invalidates the authentication for the current connection

authenticate(String token)

Authenticates the current connection with a JWT token

kill(String query)

Kill a specific query

let(String key, String val)

Assigns a value as a parameter for this connection

create(String thing, dynamic data)

Creates a record in the database. data has to be json encodable object or class has toJson method.

Future<List<T>> select(String table)

Selects all records in a table, or a specific record, from the database

query(String query, [Map<String, Object?>? vars])

Runs a set of SurrealQL statements against the database

update(String thing, [Object? data])

Updates all records in a table, or a specific record, in the database NOTE: This function replaces the current document / record data with the specified data.

change(String thing, [Object? data])

Modifies all records in a table, or a specific record, in the database NOTE: This function merges the current document / record data with the specified data.

modify(String thing, [Object? data])

Applies JSON Patch changes to all records, or a specific record, in the database NOTE: This function patches the current document / record data with the specified JSON Patch data.

delete(String thing)

Deletes all records in a table, or a specific record, from the database

You might also like...

A dart package which provides a lot of helpers functions for easy development.

more_functions A dart package which provides a lot of helpers functions for easy development. Installation Add this to your packages pubspec.yaml file

Dec 5, 2021

A package that exports functions for converting, formatting, and nicening of dates/times in Dart.

Instant A library for manipulating and formatting DateTimes in Dart. Dates and times have never been easier. | DateTime timezone manipulation | Easy f

Jan 22, 2022

Access app version and git informations from auto-generated and configurable widgets

This is a proof of concept and WIP Feedback and ideas welcome !! Access your pubspec and git commit informations like versions and commit status from

Jul 7, 2021

An HTTP file downloader packed with many features - resumable downloads, multiple connections, buffering, auto-retry, etc.

An HTTP file downloader packed with many features - resumable downloads, multiple connections, buffering, auto-retry, etc. Features Resumable downloa

Feb 2, 2022

A customizable carousel slider widget in Flutter which supports inifinte scrolling, auto scrolling, custom child widget, custom animations and built-in indicators.

A customizable carousel slider widget in Flutter which supports inifinte scrolling, auto scrolling, custom child widget, custom animations and built-in indicators.

flutter_carousel_widget A customizable carousel slider widget in Flutter. Features Infinite Scroll Custom Child Widget Auto Play Horizontal and Vertic

Oct 8, 2022

Demo app with continuous integration setup for auto across android/iOS app stores

demo_flutter_ci A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

Dec 25, 2021

Auto route lib - Personal customized use to increase CupertinoRoute transition duration

Auto route lib - Personal customized use to increase CupertinoRoute transition duration , auto route 1.0.0-beta.10 base, so i have to reupload from .pub-cache instead fork it

Jan 4, 2022

Flutter plugin for auto resize widgets to get then "responsives".

Flutter plugin for auto resize widgets to get then

Responsive Widgets This plugin helps to create responsive widgets, that makes auto-size with the proportion between reference screen size (width, heig

Nov 3, 2022

Asset manager helps you auto-generate the assets code and add it to your pubspec.yaml .

Asset manager helps you auto-generate the assets code and add it to your pubspec.yaml .

Asset Manager Asset manager helps you auto-generate the assets code and add it to your pubspec.yaml . Quick start dart pub global activate asset_manag

Nov 1, 2022
Comments
  • allow to set globalTimeout for rpc calls

    allow to set globalTimeout for rpc calls

    I ran into some issues with the default timeout of 5 seconds

    Future.delayed(timeout ?? const Duration(seconds: 5), ()

    so I made it configurable at as a parameter for client.connect(); which defaults to one minute.

    I have also adapted the URL for the tests.

    opened by willyfromtheblock 0
  • type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>' in type cast

    type '_InternalLinkedHashMap' is not a subtype of type 'List' in type cast

    Unhandled exception:
    type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>' in type cast
    #0      SurrealDB.select (package:surrealdb/src/surrealdb.dart:118)
     <asynchronous suspension>
    

    latest nightly

    Tests pass, though me calling await surrealClient.select("blockchain:height"); is causing the error above

    opened by willyfromtheblock 0
  • .wait() future does not complete with surrealdb nightly build

    .wait() future does not complete with surrealdb nightly build

    https://hub.docker.com/layers/surrealdb/surrealdb/nightly/images/sha256-42d40cb75d6bced61bebdec89df4ab054bce747884f2f7e137f8e2f6f0b1fbde?context=explore

    If left unchanged the following error occurs: 01:30 +0 -3: test/surrealdb_test.dart: should create [E] TimeoutException after 0:00:30.000000: Test timed out after 30 seconds. See https://pub.dev/packages/test#timeouts dart:isolate _RawReceivePortImpl._handleMessage

    If I remove await client.wait();

    from the tests, they succeed.

    opened by willyfromtheblock 0
Owner
Duhan BALCI
Duhan BALCI
Shared preferences typed - A type-safe wrapper around shared preferences, inspired by ts-localstorage

Typed Shared Preferences A type-safe wrapper around shared_preferences, inspired

Philipp Bauer 0 Jan 31, 2022
Lightweight and blazing fast key-value database written in pure Dart.

Fast, Enjoyable & Secure NoSQL Database Hive is a lightweight and blazing fast key-value database written in pure Dart. Inspired by Bitcask. Documenta

HiveDB 3.3k Nov 26, 2022
Lightweight and blazing fast key-value database written in pure Dart.

Fast, Enjoyable & Secure NoSQL Database Hive is a lightweight and blazing fast key-value database written in pure Dart. Inspired by Bitcask. Documenta

HiveDB 3.3k Nov 16, 2022
DartMeltySoundFont - a SoundFont synthesizer (i.e. '.sf2' player) written in pure Dart

DartMeltySoundFont DartMeltySoundFont is a SoundFont synthesizer (i.e. '.sf2' player) written in pure Dart. It is a port of MeltySynth (C#, MIT Licens

Chip Weinberger 11 Oct 29, 2022
A simple set of terminal-based arcade games written in pure Dart.

dartcade A simple set of terminal-based arcade games written in pure Dart. Purpose I was developing some simple 2D UI libraries (such as package:gridd

Matan Lurey 6 Sep 29, 2022
Pure Dart Client for Nakama Server 🌟🥰🤩

Nakama Flutter Client ?? ?? ?? ?? Nakama is an open-source scalable game server. This is a Flutter client for Nakama written in pure dart and supports

Oliver Brunsmann 56 Nov 18, 2022
Mysql.dart - MySQL client for Dart written in Dart

Native MySQL client written in Dart for Dart See example directory for examples

null 43 Oct 10, 2022
This is the Zuri Chat Android app project repository handled by TEAM SOCRATES, written with pure Flutter.

Zuri Chat Overview This is the Zuri Chat Android app project repository handled by TEAM SOCRATES, written with pure Flutter. NB: Always contact Team l

Zuri Chat 31 Oct 11, 2022
Dart package responsible to provide the basic resources to Lambda Functions with Clean Dart

AWS Lambda Core This package is responsible to provide the basic resources to all services; Usage pubspec.yaml dependencies: aws_lambda_core: <laste

David Araujo 1 Dec 2, 2021
This is a mostly auto-generated library for using the mattermost api from Dart.

Mattermost API Client in Dart This is an implementation of a Mattermost API client in dart. It is not the only one, but it has significant advantages

null 1 Jun 15, 2022