@@ -980,7 +980,7 @@ describe("sqlite.tbl", function()
980980
981981 describe (" string_index:" , function ()
982982 local kv = tbl (" kvpair" , {
983- key = { " text" , primary = true , required = true , unique = true },
983+ key = { " text" , primary = true , required = true , default = " none " },
984984 len = " integer" ,
985985 }, db )
986986
@@ -1038,6 +1038,13 @@ describe("sqlite.tbl", function()
10381038 }]
10391039 )
10401040 end )
1041+
1042+ it (" insert with 0 or true to skip the primary key value." , function ()
1043+ kv [true ] = { len = 5 }
1044+ eq (5 , kv .none .len )
1045+ kv [" " ] = { len = 6 }
1046+ eq ({ key = " none" , len = 6 }, kv :where { len = 6 })
1047+ end )
10411048 end )
10421049
10431050 describe (" number_index" , function ()
@@ -1082,6 +1089,41 @@ describe("sqlite.tbl", function()
10821089 )
10831090 end )
10841091 end )
1092+
1093+ describe (" Relationships" , function ()
1094+ local todos = tbl (" todos_indexer" , {
1095+ id = true ,
1096+ title = " text" ,
1097+ project = {
1098+ reference = " projects.title" ,
1099+ required = true ,
1100+ on_delete = " cascade" ,
1101+ on_update = " cascade" ,
1102+ },
1103+ }, db )
1104+
1105+ local projects = tbl (" projects" , {
1106+ title = { type = " text" , primary = true , required = true , unique = true },
1107+ deadline = { " date" , default = db .lib .date " now" },
1108+ }, db )
1109+
1110+ it (" create new table with default values" , function ()
1111+ projects .neovim = {}
1112+ eq (true , projects .neovim .deadline == os.date " !%Y-%m-%d" )
1113+ projects [" sqlite" ] = {}
1114+ --- TODO: if you have sqilte.lua todos[2] return empty table
1115+ end )
1116+
1117+ it (" fails if foregin key doesn't exists" , function ()
1118+ eq (
1119+ false ,
1120+ pcall (function ()
1121+ todos [2 ].project = " ram"
1122+ end )
1123+ )
1124+ end )
1125+ end )
1126+
10851127 -- vim.loop.fs_unlink(db_path)
10861128 end )
10871129
0 commit comments