@@ -974,72 +974,74 @@ describe("sqlite.tbl", function()
974974 end )
975975
976976 describe (" :index access" , function ()
977- -- local db_path = "/tmp/idx_db"
977+ local db_path = " :memory: " or " /tmp/idx_db"
978978 -- vim.loop.fs_unlink(db_path)
979- db = sql :open ()
979+ db = sql :open (db_path )
980980
981981 describe (" string_index:" , function ()
982- local kvpair = tbl (" kvpair" , {
982+ local kv = tbl (" kvpair" , {
983983 key = { " text" , primary = true , required = true , unique = true },
984- value = " integer" ,
984+ len = " integer" ,
985985 }, db )
986986
987987 it (" access/insert-to table using primary key" , function ()
988- kvpair .a = { value = 1 }
989- eq ({ key = " a" , value = 1 }, kvpair .a )
988+ kv .a = { len = 1 }
989+ eq ({ key = " a" , len = 1 }, kv .a )
990990 end )
991991
992- it (" access/update a row field value" , function ()
993- kvpair .a .value = 2
994- eq (2 , kvpair .where ({ value = 2 }).value , " should have been set" )
995- eq (2 , kvpair .a .value , " should have been set" )
996- kvpair .a .value = 3
997- eq ({ key = " a" , value = 3 }, kvpair .a , " should return values" )
992+ it (" access/update a row field len" , function ()
993+ -- eq({}, kv.a)
994+ kv .a = { len = 1 }
995+ kv .a .len = 2
996+ eq (2 , kv :where ({ len = 2 }).len , " should have been set" )
997+ eq (2 , kv .a .len , " should have been set" )
998+ kv .a .len = 3
999+ eq ({ key = " a" , len = 3 }, kv .a , " should return values" )
9981000 end )
9991001
10001002 it (" remove a row using primary key" , function ()
1001- kvpair .a = nil
1002- eq (nil , kvpair . where { key = " a" }, " should be empty" )
1003- eq ({}, kvpair .a , " should be empty" )
1003+ kv .a = nil
1004+ eq (nil , kv : where { key = " a" }, " should be empty" )
1005+ eq ({}, kv .a , " should be empty" )
10041006 end )
10051007
1006- it (" sets a row field value without creating the row first" , function ()
1007- kvpair [" some key with spaces :D" ].value = 4
1008- eq (kvpair [" some key with spaces :D" ], { key = " some key with spaces :D" , value = 4 })
1009- kvpair [" some key with spaces :D" ] = nil
1008+ it (" sets a row field len without creating the row first" , function ()
1009+ kv [" some key with spaces :D" ].len = 4
1010+ eq (kv [" some key with spaces :D" ], { key = " some key with spaces :D" , len = 4 })
1011+ kv [" some key with spaces :D" ] = nil
10101012 end )
10111013
10121014 it (" query using index" , function ()
1013- kvpair .a .value , kvpair .b .value , kvpair .c .value = 1 , 2 , 3
1015+ kv .a .len , kv .b .len , kv .c .len = 1 , 2 , 3
10141016 eq (
1015- {
1016- { key = " a" , value = 1 },
1017- { key = " b" , value = 2 },
1018- },
1019- kvpair [{
1020- where = { value = { 1 , 2 , 3 } },
1021- order_by = { asc = { " key" , " value " } },
1022- limit = 2 ,
1023- }]
1017+ {
1018+ { key = " a" , len = 1 },
1019+ { key = " b" , len = 2 },
1020+ },
1021+ kv [{
1022+ where = { len = { 1 , 2 , 3 } },
1023+ order_by = { asc = { " key" , " len " } },
1024+ limit = 2 ,
1025+ }]
10241026 )
10251027 end )
1026- -- it("bulk update", function()
1027- -- kvpair [{ value = { 1, 2, 3 } }] = { value = 10 }
1028- -- eq(
1029- -- {
1030- -- { key = "a", value = 10 },
1031- -- { key = "b", value = 10 },
1032- -- },
1033- -- kvpair [{
1034- -- order_by = { asc = { "key" } },
1035- -- limit = 2,
1036- -- }]
1037- -- )
1038- -- end)
1039- end )
1040-
1041- -- vim.loop.fs_unlink(db_path)
1042- end )
1028+ it (" bulk update" , function ()
1029+ kv [{ len = { 1 , 2 , 3 } }] = { len = 10 }
1030+ eq (
1031+ {
1032+ { key = " a" , len = 10 },
1033+ { key = " b" , len = 10 },
1034+ },
1035+ kv [{
1036+ order_by = { asc = { " key" } },
1037+ limit = 2 ,
1038+ }]
1039+ )
1040+ end )
1041+ end )
1042+
1043+ -- vim.loop.fs_unlink(db_path)
1044+ end )
10431045
10441046 clean ()
10451047end )
0 commit comments