Comments (7)
@viliwonka authentication can be done by:
// create a shared setting
ArangoDatabase.ChangeSetting(s =>
{
s.Database = "dbname";
// credential for `dbname` database
s.Credential = new NetworkCredential("username", "password");
// credential for `_system` database, for operation that needs to be run under _system db
s.SystemDatabaseCredential = new NetworkCredential("username", "password");
});
// and use this setting by
using (var db = ArangoDatabase.CreateWithSetting())
{
}
you can read more about DatabaseSetting
at http://www.arangoclient.net/Document/DatabaseSetting
from arangoclient.net.
Thanks! Yes, I have read that link (docs) but didn't saw Auth mentioned anywhere.
I will test it (I am using F# not C#), so when it works I will paste code here and close issue.
from arangoclient.net.
Initialization
module Database
open System.Net
open System.Net.Sockets
open System.Collections.Generic
open System.Text
open ArangoDB.Client
//Settings
let init() =
ArangoDatabase.ChangeSetting(fun s ->
s.Url <- "http://[IP HERE]"
s.Database <- "MainDatabase"
s.Credential <- new NetworkCredential("[ID HERE]", "[PASS HERE]")
s.SystemDatabaseCredential <- new NetworkCredential("[ID HERE]", "[PASS HERE]")
s.CreateCollectionOnTheFly <- false
s.WaitForSync <- true
)
//DATABASE INSTANCE
let mainDb = ArangoDatabase.CreateWithSetting()
Player type::
type public Player(ID:string, email:string, salt:byte[], hash:byte[]) =
[<DocumentProperty(Identifier = IdentifierType.Key)>]
member public this.ID = ID
member public this.email = email
member public this.salt = salt
member public this.hash = hash
Function, where I insert Player into the database (and it works). It's not finished, I have too much callbacks (result and success seems redundant)
let makePlayerDocument ID email salt hash result success error cancelled=
let newPlayer = new Player(ID, email, salt, hash)
let task =
mainDb.InsertAsync<Player>(
newPlayer,
baseResult = result
)
|> Async.AwaitTask
Async.StartWithContinuations(
task,
(fun x -> "Success" |> Logging.Info),
(fun e -> "Exception" |> Logging.Info),
(fun c -> "Canceled" |> Logging.Info))
Is this correct way to do it? Anyway, I am closing it, it works. I hope I can improve on this code, to make it easy and clean as possible.
from arangoclient.net.
@viliwonka unfortunately i don't know F#, but your code looks ok. just know ArangoDatabase
object is disposable and should be wrapped in using statement.
from arangoclient.net.
Thanks.
About using statement, I will use the ArangoDatabase whole time, until end of the time. It's for backend project, so database will be active non-stop.
Better/shorter code for future F# users:
type DatabaseOperationCallback<'S, 'E, 'C> =
| Success of 'S
| Exception of 'E
| Cancelled of 'C
let baseResultHandler (bRes: Data.BaseResult) = if bRes.Error then bRes.Error |> string |> Logging.Error
let makePlayerDocument ID email salt hash =
let newPlayer = new Player(ID, email, salt, hash)
let asyncTask =
mainDb.InsertAsync<Player>(newPlayer, baseResult = (fun bRes -> bRes|>baseResultHandler))
|> Async.AwaitTask
Async.Catch(asyncTask)
from arangoclient.net.
@viliwonka you should not keep the ArangoDatabase
object for the application life time, ArangoDatabase
object is responsible for ChangeTracking
too. it means ArangoDatabase
object keeps loaded document, so when you change the loaded document and do an db.Update
, it can detect which property is updated, so it only sends the updated property to ArangoDB server(partial updating).
for now ChangeTracking
is the only reason you should not keep the ArangoDatabase
object for the application lifetime,you can disable ChangeTracking
but at future support for caching may be added to client that could be another reason for this.
creating new ArangoDatabase
object is a cheap operation, means you can create whenever database operation is needed.
if this is ugly you can create it for the scope of a request, for example in the ASP.NET MVC project, you can create it like this:
public class HomeController : Controller
{
IArangoDatabase db;
public HomeController()
{
db = ArangoDatabase.CreateWithSetting();
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
from arangoclient.net.
Ok, I did it like this:
//Creates database with settings and returns it
let MainDb() = ArangoDatabase.CreateWithSetting()
Then I do asynchronous operation (left details out because it's not important I think)
//For every database operation, I get database instance and do operation on it
//use = using in C#
use db = MainDb()
db.InsertAsync<Clan>(newClan, baseResult = resHandler("createClan"))
|> awaitCatch //Async.AwaitTask and then Async.Catch
I do this for every operation (createPlayer, exists, get etc). Or should I do it in "context"? Maybe it doesn't matter, because it's disposed anyway.
Thanks for free support by the way. If I get it very right, I could give you F# example for front page (just like C# one).
from arangoclient.net.
Related Issues (20)
- ArangoServerException not throw when db unavailable HOT 2
- Thread safety HOT 7
- Confused with SystemDatabaseCredential HOT 5
- Custom Index HOT 6
- ByExampleAsync missing HOT 2
- Make ChangeCollectionPropertyForType public HOT 1
- Using LINQ query with Where performance HOT 1
- Error in generated AQL when upserting a generic document HOT 7
- ArangoServerException eats up all the useful information like status code and error number HOT 2
- Make collection name resolver more extensible HOT 2
- Annotating a property of type Guid as DocumentProperty.Key throws InvalidCastException HOT 2
- Support private setter
- CreateStatement<object> & Remove Vertex HOT 1
- Ternary operator support
- Global error handling policy
- Support for keyOptions: uuid
- Edge Document API not supported?
- Cannot Simply Connect to Server...... HOT 2
- Secure connection to ArangoDB
- Query directly within a collection
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arangoclient.net.