Set flushing to false

This commit is contained in:
Coder12a 2018-11-11 23:48:15 -06:00
parent 213c3bd3be
commit 1b06ca384a
2 changed files with 44 additions and 14 deletions

View File

@ -2,20 +2,18 @@ ColdDB
===========
ColdDB is a minetest mod that implements a serverless, asynchronous, NoSQL database engine.<br>
It provides a key or key-value storage system using plain Lua tables. It also can iterate through the keys.<br>
It is not required to add this mod to secure.trusted_mods this mod will still work.
It provides a key or key-value storage system using plain Lua tables, also it can iterate through the keys.<br>
Usage
===========
Copy *colddb.lua* file to your minetest mod or game. Copy the code from colddb's init file to your mods init file<br>
Then create a lua file for handling database's or any file you like.<br>
Copy both *colddb.lua* and *async* files to your minetest mod or game. Copy the code from colddb's init file to your mods init file<br>
Write this code in your lua file.
1. create a directory and link it as a database.
```lua
coldbase = colddb.get_db("mydb")
```
2. added an extra folder to the directory. every new file will be added to the global tag(folder).
2. add an extra folder to the directory. every new file will be added to the global tag(folder).
```lua
colddb.add_global_tag(coldbase,"ips")
```
@ -54,15 +52,15 @@ coldbase.add_to_mem_pool = true
```lua
coldbase.indexes = true
```
9. only if coldbase.indexes == true. returns the amount of keys are in the indexing file.
9. only if coldbase.indexes is true. returns the amount of keys that are in the indexing file.
```lua
colddb.get_count(coldbase)
```
10. only if coldbase.indexes == true. iterates through the indexing file(breaks and ends if it reached the end of the file).
10. only if coldbase.indexes is true. iterates through the indexing file(breaks and ends if it reaches the end of the file).
```lua
colddb.iterate_index_table(coldbase,nil,func_list_keys,nil)
```
11. adds folders which can be used in other functions that have tag_name arg.
11. adds a folder which can be used in other functions that have tag_name arg.
```lua
colddb.add_tag(coldbase,"Extra_Folder",{"Extra","Folder"})
```
@ -110,7 +108,7 @@ minetest.register_chatcommand("ip", {
func = function(name, param)
-- Get the ip record asynchronously.
colddb.get(ip_db,param,nil,function(record)
-- If record is contains data send it to the player.
-- If database contains the record data then send it to the player.
if record then
minetest.chat_send_player(name,string.format("%s:%s",param,record))
else
@ -143,35 +141,65 @@ API
- **colddb.add_tag(db,name,tag)**
- **colddb.get_or_add_tag(db,name,tag)**
-
- **colddb.get_or_add_tag(db,name,tag) --> tag_name**
Returns a tag or creates a new one if does not exist.
- **colddb.remove_tag(db,name)**
- **colddb.get_count(db,tag_name)**
Removes a tag.
- **colddb.get_count(db,tag_name) --> count**
Returns the count from the index table file.
- **colddb.iterate_index_table(db,begin_func,func_on_iterate,end_func,args,tag_name)**
- **begin_func(args)**
- function iterates through the index table file.
- **begin_func(args) --> args**
- function that is ran before the loop begins.
- **func_on_iterate(key,index,args)**
- function that is ran in the for loop.
- **end_func(args)**
- end function that is ran after the for loop ends.
- **colddb.set(db,name,_table,tag_name)**
- Writes data to the database. Key-Value.
- **colddb.set_key(db,name,tag_name)**
- Writes data to the database. Key-nil.
- **colddb.get(db,name,tag_name,callback(arg))**
- Returns specified data from the database in a callback function.
- **colddb.get_key(db,name,tag_name,callback(arg))**
- Returns if the key exist in the database.
- **colddb.remove(db,name,tag_name)**
- Deletes the specified data from the database.
- **Database object fields**
- **indexes**
- If truth the database makes a indexing file for keys.
- **add_to_mem_pool**
- If truth when you get keys or values it gets cached in the memory for faster access next time.
License
===========

View File

@ -324,6 +324,7 @@ function colddb.append_index_table(db,key,tag_name)
local fl = f.file
if f.needs_flushing == true then
fl:flush()
f.needs_flushing = false
end
db.indexes_pool[cs].needs_flushing = true
fl:seek("end")
@ -337,6 +338,7 @@ function colddb.append_index_table(db,key,tag_name)
local fl = f.file
if f.needs_flushing == true then
fl:flush()
f.needs_flushing = false
end
db.indexes_pool[cs].needs_flushing = true
local c = 0
@ -367,7 +369,7 @@ function colddb.get_count(db,tag_name)
local fl = f.file
if f.needs_flushing == true then
fl:flush()
f.needs_flushing = true
f.needs_flushing = false
end
fl:seek("set")
local count = tonumber(fl:read("*l"))
@ -429,7 +431,7 @@ function colddb.iterate_index_table(db,begin_func,func_on_iterate,end_func,args,
local fl = f.file
if f.needs_flushing == true then
fl:flush()
f.needs_flushing = true
f.needs_flushing = false
end
-- Get count
fl:seek("set")