Skip to content

Commit b75a0a3

Browse files
committed
🐛 docgen
1 parent 2751ece commit b75a0a3

1 file changed

Lines changed: 21 additions & 31 deletions

File tree

lua/sql.lua

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,26 @@
1010
---@brief ]]
1111
---@tag sql.lua
1212

13+
---@class sqltbl.key
14+
---@field cid number: column index
15+
---@field name string: column key
16+
---@field type string: column type
17+
---@field required boolean: whether the column key is required or not
18+
---@field primary boolean: whether the column is a primary key
19+
---@field default string: the default value of the column
20+
---@field reference string: table_name.column
21+
---@field on_update sqldb.trigger: what to do when the key gets updated
22+
---@field on_delete sqldb.trigger: what to do when the key gets deleted
23+
24+
---@class sqlquery.update @Query spec that are passed to a number of db: methods.
25+
---@field where table: filter down values using key values.
26+
---@field set table: key and value to updated.
27+
28+
---@class sqlquery.select @Query spec that are passed to select method
29+
---@field where table: filter down values using key values.
30+
---@field keys table: keys to include. (default all)
31+
---@field join table: table_name = foreign key, foreign_table_name = primary key
32+
1333
local clib = require "sql.defs"
1434
local stmt = require "sql.stmt"
1535
local u = require "sql.utils"
@@ -22,28 +42,9 @@ local flags = clib.flags
2242
---@field uri string: database uri
2343
---@field conn sqldb.types.blob: sqlite connection c object.
2444
---@field db sqldb: fallback when the user overwrite @sqldb methods (extended only).
25-
2645
local DB = {}
2746
DB.__index = DB
2847

29-
---@class sqltbl.key
30-
---@field cid number: column index
31-
---@field name string: column key
32-
---@field type string: column type
33-
---@field required boolean: whether the column key is required or not
34-
---@field primary boolean: whether the column is a primary key
35-
---@field default string: the default value of the column
36-
---@field reference string: table_name.column
37-
---@field on_update sqldb.trigger: what to do when the key gets updated
38-
---@field on_delete sqldb.trigger: what to do when the key gets deleted
39-
40-
---@alias sqldb.trigger
41-
---| '"no action"' : when a parent key is modified or deleted from the database, no special action is taken.
42-
---| '"restrict"' : prohibites from deleting/modifying a parent key when a child key is mapped to it.
43-
---| '"null"' : when a parent key is deleted/modified, the child key that mapped to the parent key gets set to null.
44-
---| '"default"' : similar to "null", except that sets to the column's default value instead of NULL.
45-
---| '"cascade"' : propagates the delete or update operation on the parent key to each dependent child key.
46-
4748
---Get a table schema, or execute a given function to get it
4849
---@param schema table|nil
4950
---@param self sqldb
@@ -346,10 +347,6 @@ function DB:insert(tbl_name, rows, schema)
346347
return succ, last_rowid
347348
end
348349

349-
---@class sqlquery.update @Query spec that are passed to a number of db: methods.
350-
---@field where table: filter down values using key values.
351-
---@field set table: key and value to updated.
352-
353350
---Update table row with where closure and list of values
354351
---returns true incase the table was updated successfully.
355352
---@param tbl_name string: the name of the db table.
@@ -390,9 +387,6 @@ function DB:update(tbl_name, specs, schema)
390387
end)
391388
end
392389

393-
---@alias sqlquery.delete table<string, string>
394-
---TOOD: support querys with `and`
395-
396390
---Delete a {tbl_name} row/rows based on the {specs} given. if no spec was given,
397391
---then all the {tbl_name} content will be deleted.
398392
---@param tbl_name string: the name of the db table.
@@ -402,6 +396,7 @@ end
402396
---@usage `db:delete("todos", { id = 1 })` delete row that has id as 1
403397
---@usage `db:delete("todos", { id = {1,2,3} })` delete all rows that has value of id 1 or 2 or 3
404398
---@usage `db:delete("todos", { id = {1,2,3} }, { id = {"<", 5} } )` matching ids or greater than 5
399+
---@todo support querys with `and`
405400
function DB:delete(tbl_name, where)
406401
a.is_sqltbl(self, tbl_name, "delete")
407402

@@ -426,11 +421,6 @@ function DB:delete(tbl_name, where)
426421
return true
427422
end
428423

429-
---@class sqlquery.select @Query spec that are passed to select method
430-
---@field where table: filter down values using key values.
431-
---@field keys table: keys to include. (default all)
432-
---@field join table: table_name = foreign key, foreign_table_name = primary key
433-
434424
---Query from a table with where and join options
435425
---@param tbl_name string: the name of the db table to select on
436426
---@param spec sqlquery.select

0 commit comments

Comments
 (0)