progaudi/progaudi.tarantool

Can't insert

LestatDelionkur opened this issue · 5 comments

I'm insert tuple with the following code
var result= await _primaryIndex.Insert<TarantoolTuple<T>>(TarantoolTuple.Create(entity));
and get an exception "Тarantool returns an error for request with id: 87, code: 0x00008027 and message: Tuple field count 1 is less than required by a defined index (expected 2)."
This is my entity code:

    [MsgPackArray]
    public class UnitType
    {
        [MsgPackArrayElement(0)]
        public ulong Id { get; set; }
        [MsgPackArrayElement(1)]
        public string Name { get; set; }
    }

  --Space definition
    unit_type=box.schema.space.create('unit_type',{format={
        [1]={["name"]="id",["type"]="unsigned"},
        [2]={["name"]="name",["type"]="string"}
    },if_not_exists = true})
    unit_type_id_seq=box.schema.sequence.create('unit_type_id_seq');

    unit_type:create_index('primary',{
        if_not_exists=true,
        type='TREE',
        unique=true,
        parts={1,'UNSIGNED'}
        ,sequence='unit_type_id_seq'
    })

Can you help me with insert and update operations? I can't find guide for this

So, usually, when you have sequence, you want id be equals to nil. Also you do not (for insert) need to wrap your entity in tuple. I would suggest to try this: var result= await _primaryIndex.Insert(entity);.

I will look into this tomorrow, if advice will not help.

Thanks! It's works great. One more question) If i use array field in tarantool, does connector map it to the class property with type ulong[]?

@LestatDelionkur yes, if every member of array is assignable to ulong.

Hi. I always get this error "ConverterNotFoundException: Converter not found for type User ProGaudi.MsgPack.Light.MsgPackContext.GetConverter()" . Can you help me again?)

    [MsgPackArray]
    [Space("user")]
    public class User : IDbEntity
    {
        [MsgPackArrayElement(0)]
        public ulong? Id { get; set; }
        [MsgPackArrayElement(1)]
        public string Login { get; set; }
        [MsgPackArrayElement(2)]
        public string Username { get; set; }
        [MsgPackArrayElement(3)]
        public string PasswordHash { get; set; }
        [MsgPackArrayElement(4)]
        public ulong? StatusId { get; set; }
        [MsgPackArrayElement(5)]
        public ulong[] Roles { get; set; }
        [MsgPackArrayElement(6)]
        public string Email { get; set; }
        [MsgPackArrayElement(7)]
        public bool EmailConfirmed { get; set; }
        [MsgPackArrayElement(8)]
        public string Phone { get; set; }
        [MsgPackArrayElement(9)]
        public bool PhoneNumberConfirmed { get; set; }
        [MsgPackArrayElement(10)]
        public bool TwoFactorEnabled { get; set; }
        [MsgPackArrayElement(11)]
        public int AccessFailedCount { get; set; }

    }
  user=box.schema.space.create('user',{format={
        [1]={["name"]="id",["type"]="unsigned"},
        [2]={["name"]="login",["type"]="string"},
        [3]={["name"]="username",["type"]="string"},
        [4]={["name"]="password",["type"]="string"},
        [5]={["name"]="status_id",["type"]="unsigned"},
        [6]={["name"]="roles",["type"]="array"},
        [7]={["name"]="email",["type"]="string"},
        [8]={["name"]="email_confirmed",["type"]="boolean"} ,
        [9]={["name"]="phone",["type"]="string"},
        [10]={["name"]="phone_number_confirmed",["type"]="boolean"},
        [11]={["name"]="two_factor_enabled",["type"]="boolean"},
        [12]={["name"]="access_failed_count",["type"]="integer"}      
    }})

When you create a Box object, you have an option to pass a MsgPackContext for it. You should do something like this:

var msgPackContext = new MsgPackContext();

// this will trigger scan of your assembly for classes, marked with attributes.
msgPackContext.DiscoverConverters<User >();

var clientOptions = new ClientOptions(options.Value.ReplicationSource, context: context);
this.Box = new Box(clientOptions);
this.Box.Connect().GetAwaiter().GetResult();