progaudi / progaudi.tarantool

.net connector for Tarantool NoSql database.
MIT License
48 stars 16 forks source link

Insert with autoincrement Id filed #142

Closed rkulow closed 5 years ago

rkulow commented 5 years ago

I'm trying to insert items with an autoincrement Id. Therefore I created my init lua file:

some_space = box.schema.space.create('some_space', { format = { 
        [1] = {["name"] = "id", ["type"]="unsigned"},
        [2] = {["name"] = "text", ["type"]="string"}
}})
unit_type_id_seq=box.schema.sequence.create('id_seq');
some_space:create_index('primary', {
        if_not_exists = true,
        type = 'TREE',
        unique = true,
        parts = {1, 'UNSIGNED'},
        sequence='id_seq'
})

Now in C#: I'am using a class like this:

[MsgPackArray]
public class TestItem
{
        [MsgPackArrayElement(0)]
        public ulong? Id { get; set; }

        [MsgPackArrayElement(1)]
        public string Name { get; set; }
}

And I'am trying to insert some data:

await index.Insert(new TestItem()
{
        Id = null, 
        Name = "ABCDE"
});

I left the Id filed null to use the autoincrement Id function. Unfortunately this isn't working as expected:

Tarantool returns an error for request with id: 28, code: 0x00008017 and message: Tuple field 1 type does not match one required by operation: expected integer.

Can you help me with this insert operation? By the way the best would be, if this insert function cloud return (if success) the assigned Id.

aensidhe commented 5 years ago

@KulowRainer

Please take a look onto repro of your issue in attached file. Everything is working as expected.

GH-142.zip

Could you elaborate?

rkulow commented 5 years ago

Thanks, I tried your quick example in a clean docker container - and it worked as expected. So I cleaned up my whole data directory and completely recreated my docker cluster - then my original source code worked also as expected. Maybe there was some inconsistency in my data directory. I'am using the docker container tarantool/tarantool:1.10.2-0-gc0d8063b6 and Nuget progaudi.tarantool version 0.12.1

aensidhe commented 5 years ago

@KulowRainer if you'll have good repro don't hesitate to reopen issue. Closing now.