Created
February 25, 2020 21:11
-
-
Save evbruno/86f6a1de6287e6551a06babf1a84a5c2 to your computer and use it in GitHub Desktop.
Fauna Hello World
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
using FaunaDB.Client; | |
using FaunaDB.Types; | |
using FaunaDB.Query; | |
using static FaunaDB.Query.Language; | |
namespace FaunaTest | |
{ | |
class Program | |
{ | |
//static readonly string ENDPOINT = "https://db.fauna.com:443"; | |
static readonly string ENDPOINT = "http://localhost:8443"; | |
static readonly string SECRET = "secret"; | |
static void ProcessData(Value[] values, Expr source) | |
{ | |
Console.WriteLine("Source: ${0}", source); | |
foreach (Value value in values) | |
{ | |
Console.WriteLine(value); | |
} | |
Console.WriteLine(""); | |
} | |
static async Task DoQuery(FaunaClient client, Expr source) | |
{ | |
Value result = await client.Query(Paginate(source)); | |
IResult<Value[]> data = result.At("data").To<Value[]>(); | |
data.Match( | |
Success: value => ProcessData(value, source), | |
Failure: reason => Console.WriteLine($"Something went wrong: {reason}") | |
); | |
} | |
public static void Main(string[] args) | |
{ | |
var endpoint = ENDPOINT; | |
var secret = SECRET; | |
if (args.Length == 2) | |
{ | |
endpoint = args[0]; | |
secret = args[1]; | |
} | |
var client = new FaunaClient(endpoint: endpoint, secret: secret); | |
Console.WriteLine("Running w/ endpoint: \"{0}\"... \n", endpoint); | |
DoQuery(client, Collections()).Wait(); | |
DoQuery(client, Indexes()).Wait(); | |
DoQuery(client, Databases()).Wait(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>netcoreapp3.1</TargetFramework> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="FaunaDB.Client" Version="2.11.0" /> | |
</ItemGroup> | |
</Project> |
Author
evbruno
commented
Feb 25, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment