一个简单的轻量级可移植的嵌入式数据库库
pysdb的Python项目详细描述
PYSDB
PysDB是一个轻量级、可移植、可嵌入的数据库管理库
先导入:
import pysdb
概念
SDB_商店
SDB_Store是一组数据库
<>是所有数据库存在的目录。sdb_store可以通过以下命令创建:
$ mkdir /path/to/SDB_STORE/ && touch /path/to/SDB_STORE/sdbstore
如果您喜欢不同的目录名,请将db_store更改为您喜欢的任何名称,例如:
$ mkdir /path/to/MY_STORE/ && touch /path/to/MY_STORE/sdbstore
数据库
集合组是一个数据库
收藏
一捆记录是一个集合(有点像一张表)
记录
记录就像表中的一行
记录是纯python字典
示例:
student_record1 = {
"name": "student1_name1",
"age":19
}
示例
import pysdb
store = pysdb.UseStore('/path/to/DB_STORE/') # use the created store (returns a pointer to store)
store.CreateDB('db') # creates a db in store (returns true or false)
db = store.OpenDB('db') # opens a db in store (return a pointer to db)
store.CloseDB('db') # closes an opened db
store.DropDB('db') # deletes the entire database (return true or false)
store.LookForDB('db') # checks if a Database exists (returns true or false)
db.CreateCl('cl') # creates a collection in db (returns true or false)
cl = db.OpenCl('cl') # opens a collection in db (returns a pointer to the collection)
db.CloseCl('cl') # closes the collection
db.DropCl('cl') # deletes a collection in db (returns true or false)
db.LookForCl('cl') # checks if a collection exists (returns true or false)
# create a record (pure python dictionary)
student_record1 = {
"name": "student_name1",
"age":19
}
student_record2 = {
"name": "student_name2",
"age":20
}
cl.AddRec('student_record_1', student_record1) # adds a record to cl
cl.UpdateRect('student_record_1', student_record2) # updates the record in cl
cl.ReadRec('student_record_1') # returns a Record ( python dictionary - same as above student_record1 )
cl.RemoveRect('student_record_1') # removes a Record in cl