Remove global tag
This commit is contained in:
parent
02796f2998
commit
647330a033
26
README.md
26
README.md
@ -13,19 +13,15 @@ Write this code in your lua file.
|
|||||||
```lua
|
```lua
|
||||||
coldbase = colddb.Colddb("mydb")
|
coldbase = colddb.Colddb("mydb")
|
||||||
```
|
```
|
||||||
2. add an extra folder to the directory. every new file will be added to the global tag(folder).
|
2. store key item(this key has no value)
|
||||||
```lua
|
|
||||||
coldbase.add_global_tag("ips")
|
|
||||||
```
|
|
||||||
3. store key item(this key has no value)
|
|
||||||
```lua
|
```lua
|
||||||
coldbase.set_key("MyKey")
|
coldbase.set_key("MyKey")
|
||||||
```
|
```
|
||||||
4. store key-value item
|
3. store key-value item
|
||||||
```lua
|
```lua
|
||||||
coldbase.set("MyKeyAndValue", "Hello world")
|
coldbase.set("MyKeyAndValue", "Hello world")
|
||||||
```
|
```
|
||||||
5. retrieve items (get_key's callback(arg) will return true, false, or nil)
|
4. retrieve items (get_key's callback(arg) will return true, false, or nil)
|
||||||
```lua
|
```lua
|
||||||
coldbase.get("MyKeyAndValue", nil, function(arg)
|
coldbase.get("MyKeyAndValue", nil, function(arg)
|
||||||
if arg then
|
if arg then
|
||||||
@ -40,35 +36,35 @@ coldbase.get_key("MyKey", nil, function(arg)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
6. delete key(file) this function works on both keys and key-value keys.
|
5. delete key(file) this function works on both keys and key-value keys.
|
||||||
```lua
|
```lua
|
||||||
coldbase.remove("MyKeyAndValue")
|
coldbase.remove("MyKeyAndValue")
|
||||||
```
|
```
|
||||||
7. if add_to_mem_pool is true(true by default). keys are stored in a weak lua table(memory) it will be removed by the gc if its not in-use. Storing data in memory is to prevent the database from constantly loading up data from files.
|
6. if add_to_mem_pool is true(true by default). keys are stored in a weak lua table(memory) it will be removed by the gc if its not in-use. Storing data in memory is to prevent the database from constantly loading up data from files.
|
||||||
```lua
|
```lua
|
||||||
coldbase.add_to_mem_pool = true
|
coldbase.add_to_mem_pool = true
|
||||||
```
|
```
|
||||||
8. if indexes is true(false by default). When a key file is created an indexing file stores the key for look-ups. this makes it possible to iterate through keys.
|
7. if indexes is true(false by default). When a key file is created an indexing file stores the key for look-ups. this makes it possible to iterate through keys.
|
||||||
```lua
|
```lua
|
||||||
coldbase.indexes = true
|
coldbase.indexes = true
|
||||||
```
|
```
|
||||||
9. only if coldbase.indexes is true. returns the amount of keys that are in the indexing file.
|
8. only if coldbase.indexes is true. returns the amount of keys that are in the indexing file.
|
||||||
```lua
|
```lua
|
||||||
coldbase.get_count()
|
coldbase.get_count()
|
||||||
```
|
```
|
||||||
10. only if coldbase.indexes is true. iterates through the indexing file(breaks and ends if it reaches the end of the file).
|
9. only if coldbase.indexes is true. iterates through the indexing file(breaks and ends if it reaches the end of the file).
|
||||||
```lua
|
```lua
|
||||||
coldbase.iterate_index_table(nil, func_list_keys, nil)
|
coldbase.iterate_index_table(nil, func_list_keys, nil)
|
||||||
```
|
```
|
||||||
11. adds a folder which can be used in other functions that have tag_name arg.
|
10. adds a folder which can be used in other functions that have tag_name arg.
|
||||||
```lua
|
```lua
|
||||||
coldbase.add_tag("Extra_Folder", {"Extra", "Folder"})
|
coldbase.add_tag("Extra_Folder", {"Extra", "Folder"})
|
||||||
```
|
```
|
||||||
12. returns the tag name if the tag does not exists it creates one.
|
11. returns the tag name if the tag does not exists it creates one.
|
||||||
```lua
|
```lua
|
||||||
coldbase.get_or_add_tag("Extra_Folder", {"Extra", "Folder"})
|
coldbase.get_or_add_tag("Extra_Folder", {"Extra", "Folder"})
|
||||||
```
|
```
|
||||||
13. remove tag by name.
|
12. remove tag by name.
|
||||||
```lua
|
```lua
|
||||||
coldbase.remove_tag("Extra_Folder")
|
coldbase.remove_tag("Extra_Folder")
|
||||||
```
|
```
|
||||||
|
16
colddb.lua
16
colddb.lua
@ -185,22 +185,6 @@ function colddb.Colddb(directory)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.add_global_tag = function(tag)
|
|
||||||
local t = ""
|
|
||||||
if type(tag) == "table" then
|
|
||||||
for index in pairs(tag) do
|
|
||||||
t = string.format("%s%s/", t, index)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
t = string.format("%s/", tag)
|
|
||||||
end
|
|
||||||
self.db.global_tag = string.format("%s%s", self.db.global_tag, t)
|
|
||||||
self.db.directory = string.format("%s/%s", self.db.directory, t)
|
|
||||||
if not createDir(self.db.directory) then
|
|
||||||
error(string.format("%s is not a directory.", self.db.directory))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
self.add_tag = function(name, tag)
|
self.add_tag = function(name, tag)
|
||||||
local t = ""
|
local t = ""
|
||||||
if not self.db.tags[name] then
|
if not self.db.tags[name] then
|
||||||
|
Loading…
Reference in New Issue
Block a user