A simple C++ framework based on file

A simple C++ framework based on file.

瞎扯淡

前段时间(其实离现在已经不短了)印象笔记免费用户限制客户端同步个数, 像我这样 WindowsPC, WindowsBook, WindowsPad, WindowsPhoen, iPhone, MacBook, AndroidPad这么多设备需要同(我真不是装逼, 好吧我在装逼), 两台设备配额肯定不够的啊, 有木有, 别跟我说可以付费啊, 付费就不限制了, 反正我就不付费.

于是乎就突发奇想, 自己开发一个笔记应用, 那么问题来了, 得需要服务器呢, 怎么办, 想来想去, 想到不是有git吗? 我可以用git来做服务器存储笔记文件啊, 我真他妈是个天才, 恩, 我差点就信了.

经过一段时间的构思, 想起如果使用数据库的话, 会生成字节码文件, 这可不妙, git 对处理字节码可不在行, 思前想后, 最终决定使用纯纯文本文件为存储源, 存储数据, 反正也不会有很大的数据量, 于是乎就google了一番, 没找到相关的开源库, 心想这下坑爹了. 最终没办法, 只能自学了C++开始写这个库, 不要问我为什么不用自己擅长的语言写, 我要跨平台啊, 啊, 啊, 啊… 跨平台的话, 除了C/C++, 我还没有找到很好的选择. 这个项目我是准备支持全平台的, 好吧, 给自己挖了个巨坑… 反正无所谓了, 挖了就挖了, 填补填的上就看造化了.

废话就这么多了, 下面是文档和开源地址

GitHub

Get Started

Use

Drag src/* to your projects

1
2
3
4
5
6
7
#include "FdbrQueryBuilder.h"

using namespace FileDBR;

int main(int argc, const char * argv[]) {
FdbrQueryBuilder queryBuilder("/Users/MakeHui/Desktop/");
}

Definition

Create table and delete table

createTable

Create table

bool createTable(string table, vector<string> columns)

  • table: The table name
  • columns: create column name
  • return: bool
1
bool data = queryBuilder.createTable("tablename.fdbr", {"field1", "field2", "field3"});

deleteTable

Delete table

bool createTable(string table)

  • table: The table name
  • return: bool
1
bool data = queryBuilder.deleteTable("tablename.fdbr");

Where

In the basic use. You can use symbols to filter parameters.

equality

field1 = 123

1
2
3
vector<map<string, string>> data = queryBuilder.select("tablename.fdbr", {"field1", "field2"}, {{"field1", "123"}});
// or
vector<map<string, string>> data = queryBuilder.select("tablename.fdbr", {"field1", "field2"}, {{"field1 =", "123"}});

not equal

field1 != 123

1
vector<map<string, string>> data = queryBuilder.select("tablename.fdbr", {"field1", "field2"}, {{"field1 !=", "123"}});

greater

field1 > 123

1
vector<map<string, string>> data = queryBuilder.select("tablename.fdbr", {"field1", "field2"}, {{"field1 >", "123"}});

lesser

field1 < 123

1
vector<map<string, string>> data = queryBuilder.select("tablename.fdbr", {"field1", "field2"}, {{"field1 <", "123"}});

greater or equal

field1 >= 123

1
vector<map<string, string>> data = queryBuilder.select("tablename.fdbr", {"field1", "field2"}, {{"field1 >=", "123"}});

lesser or equal

field1 <= 123

1
vector<map<string, string>> data = queryBuilder.select("tablename.fdbr", {"field1", "field2"}, {{"field1 <=", "123"}});

like

field1 like 123

1
vector<map<string, string>> data = queryBuilder.select("tablename.fdbr", {"field1", "field2"}, {{"field1 ~", "123"}});

not like

field1 not like 123

1
vector<map<string, string>> data = queryBuilder.select("tablename.fdbr", {"field1", "field2"}, {{"field1 !~", "123"}});

Query

Some to the query method in common use.

select

Select data from table

vector<map<string, string>> select(string table, vector<string> columns = {}, map<string, string> where = {}, map<string, string> order = {})

  • table: The table name
  • columns: The target columns of data will be fetched
  • where: Query conditions
  • order: Sorting conditions
  • return: vector<map<string, string>>
1
vector<map<string, string>> data = queryBuilder.select("tablename.fdbr", {"field1", "field2"}, {{"field1", "123"}}, {{"field1", "DESC"}})

insert

Insert new records in table

bool insert(string table, map<string, string> datas)

  • table: The table name
  • datas: The data will be inserted into table
  • return: bool
1
bool data = queryBuilder.insert("tablename.fdbr", {{"field1", "123"}, {"field3", "456"}});

update

Modify data in table

unsigned int update(string table, map<string, string> datas, map<string, string> where = {})

  • table: The table name
  • datas: The data that will be modified
  • where: Query conditions
  • return: The number of rows affected
1
unsigned int data = queryBuilder.update("tablename.fdbr", {{"field1", "111"}}, {{"field1", "100"}});

del

Delete data from table

unsigned int del(string table, map<string, string> where = {})

  • table: The table name
  • where: Query conditions
  • return: The number of rows affected
1
unsigned int data = queryBuilder.del("tablename.fdbr", {{"field1", "100"}});

get

Get only one record from table

map<string, string> get(string table, vector<string> columns = {}, map<string, string> where = {}, map<string, string> order = {})

  • table: The table name
  • columns: The target columns of data will be fetched
  • where: Query conditions
  • order: Sorting conditions
  • return map<string, string>
1
map<string, string> data = queryBuilder.get("tablename.fdbr", {"field2"}, {{"field1", "123"}}, {{"field1", "ASC"}})

has

Determine whether the target data existed

bool has(string table, map<string, string> where = {})

  • table: The table name
  • where: Query conditions
  • return: bool
1
bool data = queryBuilder.has("tablename.fdbr", {{"field1", "100"}});

count

Counts the number of rows

unsigned int count(string table, map<string, string> where = {});

  • table: The table name
  • where: Query conditions
  • return: unsigned int
1
unsigned int data = queryBuilder.count("tablename.fdbr", {{"field1", "100"}});

max

Get the maximum value for the column and support string

string max(string table, string column, map<string, string> where = {})

  • table: The table name
  • column: The target column will be calculated
  • where: Query conditions
  • return: string
1
string data = queryBuilder.max("tablename.fdbr", "field2", {{"field1", "100"}});

min

Get the minimum value for the column and support string

string min(string table, string column, map<string, string> where = {});

  • table: The table name
  • column: The target column will be calculated
  • where: Query conditions
  • return: string
1
string data = queryBuilder.min("tablename.fdbr", "field2", {{"field1", "100"}});

avg

Get the average value for the column

long double avg(string table, string column, map<string, string> where = {});

  • table: The table name
  • column: The target column will be calculated
  • where: Query conditions
  • return: long double
1
long double data = queryBuilder.avg("tablename.fdbr", "field2", {{"field1", "100"}});

sum

Get the total value for the column

long double sum(string table, string column, map<string, string> where = {});

  • table: The table name
  • column: The target column will be calculated
  • where: Query conditions
  • return: long double
1
long double data = queryBuilder.sum("tablename.fdbr", "field2", {{"field1", "100"}});

License

FileDBR is under the LGPLv2.1 license.