From 30ecbd214154165d89462f97f974349df3ab588a Mon Sep 17 00:00:00 2001 From: twmht Date: Thu, 20 Jun 2019 22:21:48 +0800 Subject: [PATCH] update --- _sources/tutorial/index.rst.txt | 76 +++++++++++++++++++++++++++++++++ index.html | 1 + searchindex.js | 2 +- tutorial/index.html | 76 +++++++++++++++++++++++++++++++++ 4 files changed, 154 insertions(+), 1 deletion(-) diff --git a/_sources/tutorial/index.rst.txt b/_sources/tutorial/index.rst.txt index a74c622..8b6ce1b 100644 --- a/_sources/tutorial/index.rst.txt +++ b/_sources/tutorial/index.rst.txt @@ -1,6 +1,82 @@ Basic Usage of python-rocksdb ***************************** +Column Family +============= + +python-rocksdb also supports column family :: + + db = pyrocksdb.DB() + opts = pyrocksdb.Options() + opts.create_if_missing = True + s = db.open(opts, 'path/to/db') + # create new column family + copts = pyrocksdb.ColumnFamilyOptions() + s, cf = db.create_column_family(copts, "new_cf") + del cf + db.close() + # open db with the column families + cfd1 = pyrocksdb.ColumnFamilyDescriptor(pyrocksdb.DefaultColumnFamilyName, pyrocksdb.ColumnFamilyOptions()) + cfd2 = pyrocksdb.ColumnFamilyDescriptor("new_cf", pyrocksdb.ColumnFamilyOptions()) + cfds = pyrocksdb.VectorColumnFamilyDescriptor() + cfds.append(cfd1) + cfds.append(cfd2) + db_opts = pyrocksdb.DBOptions() + # column family handles + s, cfhs = db.open(db_opts, 'path/to/db', cfds) + assert(s.ok()) + assert(len(cfhs) == 2) + assert(cfhs[0].get_name() == pyrocksdb.DefaultColumnFamilyName) + assert(cfhs[1].get_name() =='new_cf') + + wopts = pyrocksdb.WriteOptions() + ropts = pyrocksdb.ReadOptions() + s = db.put(wopts, cfhs[0], b'key', b'value') + assert(s.ok()) + b = db.get(ropts, cfhs[0], b'key') + assert(b.status.ok()) + assert(b.data == b'value') + b = db.get(ropts, cfhs[1], b'key') + assert(b.status.is_not_found()) + + s = db.put(wopts, cfhs[1], b'key', b'value2') + assert(s.ok()) + b = db.get(ropts, cfhs[1], b'key') + assert(b.status.ok()) + assert(b.data == b'value2') + + b = db.get(ropts, cfhs[0], b'key') + assert(b.status.ok()) + assert(b.data == b'value') + + s = db.delete(wopts, cfhs[0], b'key') + assert(s.ok()) + b = db.get(ropts, cfhs[0], b'key') + assert(b.status.is_not_found()) + + s = db.delete(wopts, cfhs[1], b'key') + assert(s.ok()) + b = db.get(ropts, cfhs[1], b'key') + assert(b.status.is_not_found()) + + # write batch + update = pyrocksdb.WriteBatch() + update.put(cfhs[0], b'key1', b'value1') + update.put(cfhs[0], b'key2', b'value2') + update.delete(cfhs[0], 'key1') + s = db.write(wopts, update) + assert(s.ok()) + b = db.get(ropts, cfhs[0], b'key1') + assert(b.status.is_not_found()) + b = db.get(ropts, cfhs[0], b'key2') + assert(b.status.ok()) + assert(b.data == b'value2') + + for cfh in cfhs: + del cfh + db.close() + + Wrtie Batch =========== diff --git a/index.html b/index.html index 25059da..57b1f1e 100644 --- a/index.html +++ b/index.html @@ -69,6 +69,7 @@
  • Tutorial diff --git a/searchindex.js b/searchindex.js index 9cf3949..5aa7848 100644 --- a/searchindex.js +++ b/searchindex.js @@ -1 +1 @@ -Search.setIndex({docnames:["changelog","index","installation","tutorial/index"],envversion:{"sphinx.domains.c":1,"sphinx.domains.changeset":1,"sphinx.domains.cpp":1,"sphinx.domains.javascript":1,"sphinx.domains.math":2,"sphinx.domains.python":1,"sphinx.domains.rst":1,"sphinx.domains.std":1,"sphinx.ext.todo":1,"sphinx.ext.viewcode":1,sphinx:56},filenames:["changelog.rst","index.rst","installation.rst","tutorial/index.rst"],objects:{},objnames:{},objtypes:{},terms:{"default":[0,3],"import":[0,1],"true":[0,1],Added:0,For:0,With:[],access:0,accord:0,activ:[],add:0,advanc:0,all:0,allow:0,allow_mmap_read:0,allow_mmap_writ:0,also:[0,3],alwai:0,anymor:0,api:0,appli:3,apt:[],argument:0,assert:[1,3],automat:0,avail:0,batch:1,becaus:0,behav:3,bin:[],bind:1,blob:[1,3],block_restart_interv:0,block_siz:0,block_size_devi:0,blockbasedtablefactori:0,bloom_bits_per_kei:0,bloom_bits_per_prefix:0,bottommost_level_compact:0,builder:0,bunch:0,call:[0,3],can:1,change_level:0,changelog:1,clone:2,close:[1,3],code:0,collect:3,com:[0,2],compact:0,compact_rang:0,compaction_options_univers:0,compaction_styl:0,compactrang:0,compressiontyp:0,could:0,creat:1,create_if_miss:1,data:[1,3],databas:0,db_stats_log_interv:0,delet:[1,3],dev:[],dict:0,differ:3,disable_seek_compact:0,distro:[],document:0,drop:0,enabl:0,end:0,ensur:0,expect:3,facebook:0,fals:0,feel:1,first:3,fix:0,follow:0,fork:1,format:0,found:1,free:1,from:[0,1],gather:3,get:[0,1,3],get_properti:0,git:2,github:[0,1,2],have:[0,3],how:[0,1],http:[0,1,2],increaseparallel:1,index:1,init:0,initi:0,instal:1,instruct:1,interfac:1,is_not_found:3,issu:[0,1],item:[0,3],iter:[0,1],iteritem:0,iterkei:0,itertool:0,itervalu:0,its:3,kei:[0,3],key0:3,key1:[1,3],key2:3,key3:3,key4:3,key_may_exist:0,keyword:0,lambda:0,level0_slowdown_writes_trigg:0,level0_stop_writes_trigg:0,librocksdb:[],like:0,list:0,lrucach:0,lz4_compress:0,lz4hc_compress:0,make:0,max_background_flush:0,max_open_fil:0,mean:0,memori:0,memtabl:0,memtable_factori:0,method:3,modif:3,modul:1,more:0,move:0,multi:1,multi_get:0,name:0,need:0,newer:0,newtotalorderplaintablefactori:0,next:3,no_block_cach:0,now:0,one:3,onli:0,open:1,oper:3,operatio:3,opt:[1,3],optim:0,optimizelevelstylecompact:1,option:[0,1],org:1,own:0,packag:[],page:[0,1],paramet:0,paranoid_check:0,path:1,per:3,persist:0,pip:[],plaintabl:0,plaintablefactori:0,pointer:0,possibl:[0,3],prefix:0,prefix_extractor:0,prefix_seek:0,print:[0,1],properti:0,publish:0,pull:1,put:[1,3],pybind11:[1,2],pypi:0,pyrocksdb:[0,1,3],python3:1,raw:0,readopt:[0,1,3],realiz:0,recurs:2,reduce_level:0,relat:0,remov:0,renam:0,repair_db:0,represent:0,request:1,requir:[],rm_scan_count_limit:0,rocksdb:0,row_cach:0,search:1,seek:[0,3],seek_for_prev:3,seek_to_first:3,self:0,send:1,set:0,setup:2,singl:3,slightli:3,smart:0,solut:0,sourc:1,sst:0,stai:0,startswith:0,statu:[1,3],style:0,support:0,tabl:0,table_cache_remove_scan_count_limit:0,table_factori:0,takewhil:0,test:1,than:3,thei:3,them:3,thi:0,thread:1,too:0,tracker:1,tutori:1,twmht:2,univers:0,updat:[0,3],use:0,uses:0,using:1,valid:3,valu:[0,3],value1:[1,3],value2:3,value3:3,venv:[],verify_checksums_in_compact:0,version:1,virtualenv:[],walk:0,were:0,which:0,whole_key_filt:0,wiki:0,within:0,work:0,write:[0,3],writebatch:3,writebatchiter:0,writeopt:[1,3],wrtie:1,you:[0,3],your:0},titles:["Changelog","Welcome to python-rocksdb\u2019s documentation!","Installing","Basic Usage of python-rocksdb"],titleterms:{"new":0,With:[],backward:0,basic:3,batch:3,build:2,chang:0,changelog:0,contribut:1,distro:[],document:1,from:2,incompat:0,indic:1,instal:2,iter:3,overview:1,packag:[],pypi:[],python:[1,2,3],rocksdb:[1,2,3],sourc:2,tabl:1,usag:3,version:0,welcom:1,wrtie:3}}) \ No newline at end of file +Search.setIndex({docnames:["changelog","index","installation","tutorial/index"],envversion:{"sphinx.domains.c":1,"sphinx.domains.changeset":1,"sphinx.domains.cpp":1,"sphinx.domains.javascript":1,"sphinx.domains.math":2,"sphinx.domains.python":1,"sphinx.domains.rst":1,"sphinx.domains.std":1,"sphinx.ext.todo":1,"sphinx.ext.viewcode":1,sphinx:56},filenames:["changelog.rst","index.rst","installation.rst","tutorial/index.rst"],objects:{},objnames:{},objtypes:{},terms:{"default":[0,3],"import":[0,1],"new":3,"true":[0,1,3],Added:0,For:0,With:[],access:0,accord:0,activ:[],add:0,advanc:0,all:0,allow:0,allow_mmap_read:0,allow_mmap_writ:0,also:[0,3],alwai:0,anymor:0,api:0,append:3,appli:3,apt:[],argument:0,assert:[1,3],automat:0,avail:0,batch:1,becaus:0,behav:3,bin:[],bind:1,blob:[1,3],block_restart_interv:0,block_siz:0,block_size_devi:0,blockbasedtablefactori:0,bloom_bits_per_kei:0,bloom_bits_per_prefix:0,bottommost_level_compact:0,builder:0,bunch:0,call:[0,3],can:1,cfd1:3,cfd2:3,cfd:3,cfh:3,change_level:0,changelog:1,clone:2,close:[1,3],code:0,collect:3,column:1,columnfamilydescriptor:3,columnfamilyopt:3,com:[0,2],compact:0,compact_rang:0,compaction_options_univers:0,compaction_styl:0,compactrang:0,compressiontyp:0,copt:3,could:0,creat:[1,3],create_column_famili:3,create_if_miss:[1,3],data:[1,3],databas:0,db_opt:3,db_stats_log_interv:0,dboption:3,defaultcolumnfamilynam:3,del:3,delet:[1,3],dev:[],dict:0,differ:3,disable_seek_compact:0,distro:[],document:0,drop:0,enabl:0,end:0,ensur:0,expect:3,facebook:0,fals:0,famili:1,feel:1,first:3,fix:0,follow:0,fork:1,format:0,found:1,free:1,from:[0,1],gather:3,get:[0,1,3],get_nam:3,get_properti:0,git:2,github:[0,1,2],handl:3,have:[0,3],how:[0,1],http:[0,1,2],increaseparallel:1,index:1,init:0,initi:0,instal:1,instruct:1,interfac:1,is_not_found:3,issu:[0,1],item:[0,3],iter:[0,1],iteritem:0,iterkei:0,itertool:0,itervalu:0,its:3,kei:[0,3],key0:3,key1:[1,3],key2:3,key3:3,key4:3,key_may_exist:0,keyword:0,lambda:0,len:3,level0_slowdown_writes_trigg:0,level0_stop_writes_trigg:0,librocksdb:[],like:0,list:0,lrucach:0,lz4_compress:0,lz4hc_compress:0,make:0,max_background_flush:0,max_open_fil:0,mean:0,memori:0,memtabl:0,memtable_factori:0,method:3,modif:3,modul:1,more:0,move:0,multi:1,multi_get:0,name:0,need:0,new_cf:3,newer:0,newtotalorderplaintablefactori:0,next:3,no_block_cach:0,now:0,one:3,onli:0,open:[1,3],oper:3,operatio:3,opt:[1,3],optim:0,optimizelevelstylecompact:1,option:[0,1,3],org:1,own:0,packag:[],page:[0,1],paramet:0,paranoid_check:0,path:[1,3],per:3,persist:0,pip:[],plaintabl:0,plaintablefactori:0,pointer:0,possibl:[0,3],prefix:0,prefix_extractor:0,prefix_seek:0,print:[0,1],properti:0,publish:0,pull:1,put:[1,3],pybind11:[1,2],pypi:0,pyrocksdb:[0,1,3],python3:1,raw:0,readopt:[0,1,3],realiz:0,recurs:2,reduce_level:0,relat:0,remov:0,renam:0,repair_db:0,represent:0,request:1,requir:[],rm_scan_count_limit:0,rocksdb:0,ropt:3,row_cach:0,search:1,seek:[0,3],seek_for_prev:3,seek_to_first:3,self:0,send:1,set:0,setup:2,singl:3,slightli:3,smart:0,solut:0,sourc:1,sst:0,stai:0,startswith:0,statu:[1,3],style:0,support:[0,3],tabl:0,table_cache_remove_scan_count_limit:0,table_factori:0,takewhil:0,test:1,than:3,thei:3,them:3,thi:0,thread:1,too:0,tracker:1,tutori:1,twmht:2,univers:0,updat:[0,3],use:0,uses:0,using:1,valid:3,valu:[0,3],value1:[1,3],value2:3,value3:3,vectorcolumnfamilydescriptor:3,venv:[],verify_checksums_in_compact:0,version:1,virtualenv:[],walk:0,were:0,which:0,whole_key_filt:0,wiki:0,within:0,wopt:3,work:0,write:[0,3],writebatch:3,writebatchiter:0,writeopt:[1,3],wrtie:1,you:[0,3],your:0},titles:["Changelog","Welcome to python-rocksdb\u2019s documentation!","Installing","Basic Usage of python-rocksdb"],titleterms:{"new":0,With:[],backward:0,basic:3,batch:3,build:2,chang:0,changelog:0,column:3,contribut:1,distro:[],document:1,famili:3,from:2,incompat:0,indic:1,instal:2,iter:3,overview:1,packag:[],pypi:[],python:[1,2,3],rocksdb:[1,2,3],sourc:2,tabl:1,usag:3,version:0,welcom:1,wrtie:3}}) \ No newline at end of file diff --git a/tutorial/index.html b/tutorial/index.html index 6e18914..655a0ec 100644 --- a/tutorial/index.html +++ b/tutorial/index.html @@ -34,6 +34,81 @@

    Basic Usage of python-rocksdb

    +
    +

    Column Family

    +

    python-rocksdb also supports column family

    +
    db = pyrocksdb.DB()
    +opts = pyrocksdb.Options()
    +opts.create_if_missing = True
    +s = db.open(opts, 'path/to/db')
    +# create new column family
    +copts = pyrocksdb.ColumnFamilyOptions()
    +s, cf = db.create_column_family(copts, "new_cf")
    +del cf
    +db.close()
    +# open db with the column families
    +cfd1 = pyrocksdb.ColumnFamilyDescriptor(pyrocksdb.DefaultColumnFamilyName, pyrocksdb.ColumnFamilyOptions())
    +cfd2 = pyrocksdb.ColumnFamilyDescriptor("new_cf", pyrocksdb.ColumnFamilyOptions())
    +cfds = pyrocksdb.VectorColumnFamilyDescriptor()
    +cfds.append(cfd1)
    +cfds.append(cfd2)
    +db_opts = pyrocksdb.DBOptions()
    +# column family handles
    +s, cfhs = db.open(db_opts, 'path/to/db', cfds)
    +assert(s.ok())
    +assert(len(cfhs) == 2)
    +assert(cfhs[0].get_name() == pyrocksdb.DefaultColumnFamilyName)
    +assert(cfhs[1].get_name() =='new_cf')
    +
    +wopts = pyrocksdb.WriteOptions()
    +ropts = pyrocksdb.ReadOptions()
    +s = db.put(wopts, cfhs[0], b'key', b'value')
    +assert(s.ok())
    +b = db.get(ropts, cfhs[0], b'key')
    +assert(b.status.ok())
    +assert(b.data == b'value')
    +b = db.get(ropts, cfhs[1], b'key')
    +assert(b.status.is_not_found())
    +
    +s = db.put(wopts, cfhs[1], b'key', b'value2')
    +assert(s.ok())
    +b = db.get(ropts, cfhs[1], b'key')
    +assert(b.status.ok())
    +assert(b.data == b'value2')
    +
    +b = db.get(ropts, cfhs[0], b'key')
    +assert(b.status.ok())
    +assert(b.data == b'value')
    +
    +s = db.delete(wopts, cfhs[0], b'key')
    +assert(s.ok())
    +b = db.get(ropts, cfhs[0], b'key')
    +assert(b.status.is_not_found())
    +
    +s = db.delete(wopts, cfhs[1], b'key')
    +assert(s.ok())
    +b = db.get(ropts, cfhs[1], b'key')
    +assert(b.status.is_not_found())
    +
    +# write batch
    +update = pyrocksdb.WriteBatch()
    +update.put(cfhs[0], b'key1', b'value1')
    +update.put(cfhs[0], b'key2', b'value2')
    +update.delete(cfhs[0], 'key1')
    +s = db.write(wopts, update)
    +assert(s.ok())
    +b = db.get(ropts, cfhs[0], b'key1')
    +assert(b.status.is_not_found())
    +b = db.get(ropts, cfhs[0], b'key2')
    +assert(b.status.ok())
    +assert(b.data == b'value2')
    +
    +for cfh in cfhs:
    +    del cfh
    +db.close()
    +
    +
    +

    Wrtie Batch

    It is also possible to gather modifications and @@ -123,6 +198,7 @@ valid. So you have to call one of its seek methods first