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
|
||||
coldbase = colddb.Colddb("mydb")
|
||||
```
|
||||
2. add an extra folder to the directory. every new file will be added to the global tag(folder).
|
||||
```lua
|
||||
coldbase.add_global_tag("ips")
|
||||
```
|
||||
3. store key item(this key has no value)
|
||||
2. store key item(this key has no value)
|
||||
```lua
|
||||
coldbase.set_key("MyKey")
|
||||
```
|
||||
4. store key-value item
|
||||
3. store key-value item
|
||||
```lua
|
||||
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
|
||||
coldbase.get("MyKeyAndValue", nil, function(arg)
|
||||
if arg then
|
||||
@ -40,35 +36,35 @@ coldbase.get_key("MyKey", nil, function(arg)
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
coldbase.get_or_add_tag("Extra_Folder", {"Extra", "Folder"})
|
||||
```
|
||||
13. remove tag by name.
|
||||
12. remove tag by name.
|
||||
```lua
|
||||
coldbase.remove_tag("Extra_Folder")
|
||||
```
|
||||
|
16
colddb.lua
16
colddb.lua
@ -185,22 +185,6 @@ function colddb.Colddb(directory)
|
||||
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)
|
||||
local t = ""
|
||||
if not self.db.tags[name] then
|
||||
|
Loading…
Reference in New Issue
Block a user