Advertisement
Guest User

Untitled

a guest
Nov 29th, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.95 KB | None | 0 0
  1.     //Settings
  2.     let init() =
  3.                     //anonymous function with parameter s
  4.         ArangoDatabase.ChangeSetting(fun s ->
  5.             //arrow is for setting the data
  6.             s.Url <- "http://ip:port"    
  7.             s.Database <- "MainDatabase"
  8.             s.Credential <- new NetworkCredential("username", "password")
  9.             s.SystemDatabaseCredential <- new NetworkCredential("username", "password")
  10.             s.CreateCollectionOnTheFly <- false
  11.        
  12.             s.WaitForSync <- true
  13.         )
  14.  
  15.     //Creates database instance and returns it
  16.     let MainDb() = ArangoDatabase.CreateWithSetting()
  17.  
  18. ///////////////////////////////////////
  19.  
  20.     //function for inserting player into database
  21.     let createPlayer ID email salt hash clanID =
  22.        
  23.         let newPlayer = new Player(ID, email, salt, hash, clanID)
  24.  
  25.         use db = MainDb() //use means using in C#
  26.  
  27.         db.InsertAsync<Player>(newPlayer, baseResult = resHandler("createPlayer"))
  28.         |> awaitCatch
  29.  
  30. ////////////////////////////////////////
  31.     //function which returns player from database by its ID
  32.     let getPlayer ID =
  33.            
  34.         use db = MainDb() //use means using in C#
  35.            
  36.         db.DocumentAsync<Player>(ID, baseResult = resHandler("getPlayer"))
  37.         |> awaitCatch
  38.  
  39. ////////////////////////////////////
  40.     //awaits task with possible exception
  41.     let awaitCatch task =
  42.         task
  43.         |> Async.AwaitTask
  44.         |> Async.Catch
  45.  
  46. //////////////////////////////////
  47.     //class in C#, what you see here are parameters with types for constructing new object
  48.     type public Player(ID:string, email:string, salt:byte[], hash:byte[], clanID:string) =
  49.  
  50.         [<DocumentProperty(Identifier = IdentifierType.Key)>]
  51.         member public this.ID = ID
  52.  
  53.         member public this.email = email
  54.  
  55.         member public this.salt = salt
  56.  
  57.         member public this.hash = hash
  58.  
  59.         member public this.clanID = clanID
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement