pyorient : How to create a vertex using record_create - orientdb

class Person(Node):
id = String(unique = True)
name = String()
I tried the following way to create a Person node. But it's not working.
person = {
'Person' : Person(name='Record', id = 1004).__dict__
}
client.record_create(0, person)
What am I doing wrong?

You can use the "command" statement:

Related

Initialize Array in Class - Swift

I am strugeling to work with the array accounts, I don't really know how I should handle it, how I should initialize it in order to correctly append the object accountFromJohn to the list accounts.
class Bank {
var bicCode : String
var address : String
var customer : Customer
var accounts : [BankAccount] = []
init(bicCode : String, address : String, customer : Customer) {
self.bicCode = bicCode
self.address = address
self.customer = customer
}
}
var accountFromJohn = BankAccount(accountNumber : 192, balance : 20, customer : John)
var ING = Bank(bicCode : "LUING18", address : "Avenue du Swing", customer : Paul)
ING.accounts.append(accountFromJohn)
print(ING.accounts) // output : [main.BankAccount] ; wanted output : [accountFromJohn]
Best Reagars,
Thanks in advance.
Everything is fine.
The array contains an instance of BankAccount rather than an arbitrary variable name accountFromJohn.
Prove it by printing
print(ING.accounts.first?.customer ?? "Accounts is empty")
However it's possible to print accountFromJohn. in BankAccount adopt CustomStringConvertible and add the property
var description : String {
return "accountFrom\(customer)"
}
For this as one approach you can assign values to accounts while initialisation of objects.
class Bank {
var bicCode : String
var address : String
var customer : Customer
var accounts : [BankAccount]
init(bicCode : String, address : String, customer : Customer, accounts: [BankAccount]) {
self.bicCode = bicCode
self.address = address
self.customer = customer
self.accounts = accounts
}
}
Then you can work with the objects properly.
var accountFromJohn = [BankAccount(accountNumber : 192, balance : 20, customer : John)]
var ING = Bank(bicCode : "LUING18", address : "Avenue du Swing", customer : Paul, accounts: accountFromJohn)
And then you can append data to Bank list like yourObject.append(ING), if you want to change values of accounts, you can do it by yourObject[desiredElement].accounts.append(accountsData) and if you need to retrieve values yourObject[desiredElement].accounts

How to retrieve the ‘List<myObject>' realm array to array from realm model class?

My realm model class look like
class RoomRealmModel : Object {
dynamic var id: String = ""
var details = List<RoomDetailRealmModel>()
func saveItem() {
do {
let realm = try Realm()
realm.beginWrite()
realm.add(self, update: true)
try realm.commitWrite()
} catch{}
}
}
class RoomDetailRealmModel : Object{
dynamic var detailId: String = ""
dynamic var displayText: String = ""
}
I want to retrieve 'details' from the following.
details = RLMArray<RoomDetailRealmModel> <0x600000114f40> (
[0] RoomDetailRealmModel {
text = hello;
Counters = 9;
ParentID = ;
detailId = 33;
displayText = hello ;
}
);
I always get empty like in my console
(lldb) po (destinationData?[index]?.details)!
List<RoomDetailRealmModel> <0x600000853620> (
)
I am updating ‘details’ list via realm update command. I always get realm array.But I want to retrieve array type from realm array.Please help me, how to solve this issue
If you want to obtain [myObject] instead of List you can do something like this:
var array: [myObject] = [myObject]()
for object in myObjectList {
array.append(object)
}
Where myObjectList is List.
You can simply create a regular Swift Array from a Realm List by calling the initializer of Array accepting a Sequence, since List conforms to the sequence protocol.
So you can simply do
let room = RoomRealmModel()
let roomDetailsArray = Array(room.details)

Realm Swift - Filter on first element of a relationship

I have 2 realm object A and B linked with a relationship :
class A: Object {
let Bs = List<B>()
}
class B: Object {
dynamic var Id:Int = 0
}
So now, I need to get all A objects where the first Bs has the Id = 1.
If I use this line of code :
realm.objects(A).filter("ANY Bs.Id = 1")
I get all A objects, where one of the Bs has the Id = 1. But in my case, I need to check only the first Bs. Is it possible to do that in Realm ? Is there something like :
realm.objects(A).filter("FIRST Bs.Id = 1")
or
realm.objects(A).filter("TOP Bs.Id = 1")
Thank you for your help ! :)
Regards,
How about:
realm.objects(A).filter("ANY Bs.Id = 1").first
Do you have any other conditions?

Scala Play Overloaded method value [save] cannot be applied

Getting Overloaded method value [save] cannot be applied to (models.UserReset)
model :
case class UserReset (
id: ObjectId = new ObjectId,
userId: ObjectId,
email : String,
key : String,
used : Boolean = false,
createDate: Date = new Date()
)
Controller :
//save reset info
val userResetVal = UserReset(userId = user.id, email = user.email, key = resetLink)
User.save(userResetVal)
Not sure why? Or should I include Id, Used and createDate in val userResetVal = UserReset(userId = user.id, email = user.email, key = resetLink)?
Do you want UserReset to be a separate model from User? In this case you also need
object UserReset {
// define the corresponding table structure
// and methods including save
}
and call
UserReset.save(userResetVal)

How to add multiple Anonymous Type in c#?

Consider this
var source = new{ Id = "1", Name = "Name1"}
It works fine. But if I want to add 1 more property how to do so...
It failed
var source = new{ Id = "1", Name = "Name1"},new{ Id = "1", Name = "Name1"}
what is the correct syntax for this?
See Collection initializers and anonymous types on MSDN:
var source = new [] { new { Id = "1", Name = "Name1"},
new { Id = "2", Name = "Name2"}};