@@ -980,7 +980,7 @@ describe("sqlite.tbl", function()
980
980
981
981
describe (" string_index:" , function ()
982
982
local kv = tbl (" kvpair" , {
983
- key = { " text" , primary = true , required = true , unique = true },
983
+ key = { " text" , primary = true , required = true , default = " none " },
984
984
len = " integer" ,
985
985
}, db )
986
986
@@ -1038,6 +1038,13 @@ describe("sqlite.tbl", function()
1038
1038
}]
1039
1039
)
1040
1040
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 )
1041
1048
end )
1042
1049
1043
1050
describe (" number_index" , function ()
@@ -1080,8 +1087,45 @@ describe("sqlite.tbl", function()
1080
1087
limit = 2 ,
1081
1088
}]
1082
1089
)
1090
+ t [0 ] = { name = " x" }
1091
+ eq (" x" , t [t .last_id ].name )
1092
+ end )
1093
+ end )
1094
+
1095
+ describe (" Relationships" , function ()
1096
+ local todos = tbl (" todos_indexer" , {
1097
+ id = true ,
1098
+ title = " text" ,
1099
+ project = {
1100
+ reference = " projects.title" ,
1101
+ required = true ,
1102
+ on_delete = " cascade" ,
1103
+ on_update = " cascade" ,
1104
+ },
1105
+ }, db )
1106
+
1107
+ local projects = tbl (" projects" , {
1108
+ title = { type = " text" , primary = true , required = true , unique = true },
1109
+ deadline = { " date" , default = db .lib .date " now" },
1110
+ }, db )
1111
+
1112
+ it (" create new table with default values" , function ()
1113
+ projects .neovim = {}
1114
+ eq (" string" , type (projects .neovim .deadline ))
1115
+ projects [" sqlite" ] = {}
1116
+ --- TODO: if you have sqilte.lua todos[2] return empty table
1117
+ end )
1118
+
1119
+ it (" fails if foregin key doesn't exists" , function ()
1120
+ eq (
1121
+ false ,
1122
+ pcall (function ()
1123
+ todos [2 ].project = " ram"
1124
+ end )
1125
+ )
1083
1126
end )
1084
1127
end )
1128
+
1085
1129
-- vim.loop.fs_unlink(db_path)
1086
1130
end )
1087
1131
0 commit comments