Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
.dart_tool/
.packages
doc/
lib/.DS_Store
.DS_Store
pubspec.lock
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"workbench.colorCustomizations": {
"[Ayu Mirage Bordered]": {},
"activityBar.background": "#432708",
"titleBar.activeBackground": "#5E360C",
"titleBar.activeForeground": "#FEFBF8"
}
}
81 changes: 43 additions & 38 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,99 +5,104 @@ packages:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
url: "https://pub.dev"
source: hosted
version: "2.8.2"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "2.11.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.15.0"
version: "1.18.0"
faunadb_http:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "0.13.2"
version: "0.14.3"
http:
dependency: transitive
description:
name: http
url: "https://pub.dartlang.org"
sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010
url: "https://pub.dev"
source: hosted
version: "0.13.3"
version: "1.2.2"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
url: "https://pub.dev"
source: hosted
version: "4.0.0"
version: "4.0.2"
json_annotation:
dependency: transitive
description:
name: json_annotation
url: "https://pub.dartlang.org"
sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467
url: "https://pub.dev"
source: hosted
version: "4.1.0"
version: "4.8.1"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.7.0"
version: "1.11.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.9.0"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.8.1"
version: "1.10.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
version: "1.2.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
url: "https://pub.dev"
source: hosted
version: "1.2.0"
version: "1.2.1"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
url: "https://pub.dev"
source: hosted
version: "1.3.2"
web:
dependency: transitive
description:
name: web
sha256: d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062
url: "https://pub.dev"
source: hosted
version: "1.3.0"
version: "1.0.0"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=3.4.0 <4.0.0"
5 changes: 3 additions & 2 deletions lib/faunadb_http.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export 'src/FaunaConfig.dart';
export 'src/FaunaClient.dart';
export 'src/fql/result.dart';
export 'src/FaunaConfig.dart';
export 'src/FaunaDioClient.dart';
export 'src/fql/page.dart';
export 'src/fql/result.dart';
1 change: 1 addition & 0 deletions lib/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export 'src/fql/miscellaneous.dart';
export 'src/fql/read_and_write.dart';
export 'src/fql/string.dart';
export 'src/fql/time_and_date.dart';
export 'src/fql/type_checks.dart';
97 changes: 97 additions & 0 deletions lib/src/FaunaDioClient.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import 'dart:convert';

import 'package:dio/dio.dart';

import './FaunaConfig.dart';
import 'fql/result.dart';

/// The Dart native client for FaunaDB.
///
/// Query methods are asynchronous and return a [Future].
///
/// The [close()] method must be called in order to release
/// the FaunaClient I/O resources.
class FaunaDioClient {
final _dioClient = Dio();

/// Client configuration
final FaunaConfig config;

/// Creates a FaunaClient. A valid [config] is required.
FaunaDioClient(this.config);

/// Executes a query via the FaunaDB Query API.
///
/// [expression] must be either:
/// - composed using functions from the query classes
/// - serializable JSON representation of an FQL query.
///
/// Queries built using the query classes look very similar to
/// real FQL. It was an aim to mimic FQL function names and arguments
/// as closely as possible.
/// Docs on all FQL functions can be found [here][fql-cheat].
///
/// [fql-cheat]: https://docs.fauna.com/fauna/current/api/fql/cheat_sheet
///
/// Example query [expression]:
///
/// ```
/// Paginate(Match(Index('all_customers')))
/// ```
///
/// However some notable differences are:
/// - Optional FQL arguments are named arguments in Dart.
/// e.g. `Repeat('x', number: 10)`
/// - FQL functions with a variable number of arguments
/// (such as Sum, GT etc.)
/// accept a Dart List instead.
/// - Some FQL functions and arguments are reserved keywords in Dart;
/// simply add a trailing underscore to them
/// (`Map` -> `Map_`,
/// `Function` -> `Function_`,
/// `default` -> `default_`)
///
///
///
/// Any value serializable to valid JSON can also be passed
/// as an [expression].
///
/// Docs on JSON query syntax can be found [here][query-docs].
///
/// [query-docs]: https://app.fauna.com/documentation/intro/querying#query-syntax
///
/// Example JSON [expression]:
/// ```
/// {
/// 'paginate': {
/// 'match': {'index': 'all_products'},
/// }
/// }
/// ```
///
/// Throws [TimeoutException] if query response is not received within
/// [config.timeout].
Future<FaunaResponse> query(Object expression, {FaunaConfig? options}) async {
final config = (options ?? this.config);

var baseOptions = BaseOptions(
headers: config.requestHeaders,
);

_dioClient.options = baseOptions;

var response = await _dioClient.post<Map<String, dynamic>>(
config.baseUrl.toString(),
data: jsonEncode(expression),
);

var result = FaunaResponse.fromJson(response.data!);

return result;
}

/// Closes and releases all client resources.
void close() {
_dioClient.close();
}
}
19 changes: 17 additions & 2 deletions lib/src/fql/logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,28 @@ class Contains extends Expr {

Contains(this.path, this.in_);

factory Contains.fromJson(Map<String, dynamic> json) =>
_$ContainsFromJson(json);
factory Contains.fromJson(Map<String, dynamic> json) => _$ContainsFromJson(json);

@override
Map<String, dynamic> toJson() => _$ContainsToJson(this);
}

@JsonSerializable()
class ContainsStr extends Expr {
@JsonKey(name: 'containsstr')
final Object value;

@JsonKey(name: 'search')
final Object search;

ContainsStr(this.value, this.search);

factory ContainsStr.fromJson(Map<String, dynamic> json) => _$ContainsStrFromJson(json);

@override
Map<String, dynamic> toJson() => _$ContainsStrToJson(this);
}

@JsonSerializable()
class Equals extends Expr {
@JsonKey(name: 'equals')
Expand Down
11 changes: 11 additions & 0 deletions lib/src/fql/logic.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions lib/src/fql/result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Result {
} else if (value is Obj) {
return value.object;
} else if (key == 'ts') {
return DateTime.fromMicrosecondsSinceEpoch(value);
return value;
} else {
return value;
}
Expand Down Expand Up @@ -97,8 +97,7 @@ class RefResult {
return Ref(Collection(collection!.id), id);
}

factory RefResult.fromJson(Map<String, dynamic> json) =>
_$RefResultFromJson(json);
factory RefResult.fromJson(Map<String, dynamic> json) => _$RefResultFromJson(json);

Map<String, dynamic> toJson() => _$RefResultToJson(this);

Expand All @@ -121,8 +120,7 @@ class QueryResult {

QueryResult(this.params, this.expression);

factory QueryResult.fromJson(Map<String, dynamic> json) =>
_$QueryResultFromJson(json);
factory QueryResult.fromJson(Map<String, dynamic> json) => _$QueryResultFromJson(json);

Map<String, dynamic> toJson() => _$QueryResultToJson(this);

Expand Down Expand Up @@ -179,8 +177,7 @@ class FaunaResponse {
return qr;
}

factory FaunaResponse.fromJson(Map<String, dynamic> json) =>
_$FaunaResponseFromJson(json);
factory FaunaResponse.fromJson(Map<String, dynamic> json) => _$FaunaResponseFromJson(json);

Map<String, dynamic> toJson() => _$FaunaResponseToJson(this);
}
16 changes: 16 additions & 0 deletions lib/src/fql/type_checks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:faunadb_http/query.dart';
import 'package:json_annotation/json_annotation.dart';

part 'type_checks.g.dart';

@JsonSerializable()
class IsNull extends Expr {
@JsonKey(name: 'is_null')
final Object value;

IsNull(this.value);

factory IsNull.fromJson(Map<String, dynamic> json) => _$IsNullFromJson(json);
@override
Map<String, dynamic> toJson() => _$IsNullToJson(this);
}
15 changes: 15 additions & 0 deletions lib/src/fql/type_checks.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading