update
This commit is contained in:
parent
381bcf92a3
commit
30ecbd2141
4 changed files with 154 additions and 1 deletions
|
@ -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
|
||||
===========
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@
|
|||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="tutorial/index.html">Tutorial</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="tutorial/index.html#column-family">Column Family</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="tutorial/index.html#wrtie-batch">Wrtie Batch</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="tutorial/index.html#iteration">Iteration</a></li>
|
||||
</ul>
|
||||
|
|
|
@ -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}})
|
||||
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}})
|
|
@ -34,6 +34,81 @@
|
|||
|
||||
<div class="section" id="basic-usage-of-python-rocksdb">
|
||||
<h1>Basic Usage of python-rocksdb<a class="headerlink" href="#basic-usage-of-python-rocksdb" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="section" id="column-family">
|
||||
<h2>Column Family<a class="headerlink" href="#column-family" title="Permalink to this headline">¶</a></h2>
|
||||
<p>python-rocksdb also supports column family</p>
|
||||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">db</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">DB</span><span class="p">()</span>
|
||||
<span class="n">opts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">Options</span><span class="p">()</span>
|
||||
<span class="n">opts</span><span class="o">.</span><span class="n">create_if_missing</span> <span class="o">=</span> <span class="kc">True</span>
|
||||
<span class="n">s</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="s1">'path/to/db'</span><span class="p">)</span>
|
||||
<span class="c1"># create new column family</span>
|
||||
<span class="n">copts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">ColumnFamilyOptions</span><span class="p">()</span>
|
||||
<span class="n">s</span><span class="p">,</span> <span class="n">cf</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">create_column_family</span><span class="p">(</span><span class="n">copts</span><span class="p">,</span> <span class="s2">"new_cf"</span><span class="p">)</span>
|
||||
<span class="k">del</span> <span class="n">cf</span>
|
||||
<span class="n">db</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
|
||||
<span class="c1"># open db with the column families</span>
|
||||
<span class="n">cfd1</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">ColumnFamilyDescriptor</span><span class="p">(</span><span class="n">pyrocksdb</span><span class="o">.</span><span class="n">DefaultColumnFamilyName</span><span class="p">,</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">ColumnFamilyOptions</span><span class="p">())</span>
|
||||
<span class="n">cfd2</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">ColumnFamilyDescriptor</span><span class="p">(</span><span class="s2">"new_cf"</span><span class="p">,</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">ColumnFamilyOptions</span><span class="p">())</span>
|
||||
<span class="n">cfds</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">VectorColumnFamilyDescriptor</span><span class="p">()</span>
|
||||
<span class="n">cfds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cfd1</span><span class="p">)</span>
|
||||
<span class="n">cfds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cfd2</span><span class="p">)</span>
|
||||
<span class="n">db_opts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">DBOptions</span><span class="p">()</span>
|
||||
<span class="c1"># column family handles</span>
|
||||
<span class="n">s</span><span class="p">,</span> <span class="n">cfhs</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">db_opts</span><span class="p">,</span> <span class="s1">'path/to/db'</span><span class="p">,</span> <span class="n">cfds</span><span class="p">)</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">cfhs</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">)</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">cfhs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">get_name</span><span class="p">()</span> <span class="o">==</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">DefaultColumnFamilyName</span><span class="p">)</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">cfhs</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">get_name</span><span class="p">()</span> <span class="o">==</span><span class="s1">'new_cf'</span><span class="p">)</span>
|
||||
|
||||
<span class="n">wopts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">WriteOptions</span><span class="p">()</span>
|
||||
<span class="n">ropts</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">ReadOptions</span><span class="p">()</span>
|
||||
<span class="n">s</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">wopts</span><span class="p">,</span> <span class="n">cfhs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="sa">b</span><span class="s1">'key'</span><span class="p">,</span> <span class="sa">b</span><span class="s1">'value'</span><span class="p">)</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span>
|
||||
<span class="n">b</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">ropts</span><span class="p">,</span> <span class="n">cfhs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="sa">b</span><span class="s1">'key'</span><span class="p">)</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">data</span> <span class="o">==</span> <span class="sa">b</span><span class="s1">'value'</span><span class="p">)</span>
|
||||
<span class="n">b</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">ropts</span><span class="p">,</span> <span class="n">cfhs</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="sa">b</span><span class="s1">'key'</span><span class="p">)</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">is_not_found</span><span class="p">())</span>
|
||||
|
||||
<span class="n">s</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">wopts</span><span class="p">,</span> <span class="n">cfhs</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="sa">b</span><span class="s1">'key'</span><span class="p">,</span> <span class="sa">b</span><span class="s1">'value2'</span><span class="p">)</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span>
|
||||
<span class="n">b</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">ropts</span><span class="p">,</span> <span class="n">cfhs</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="sa">b</span><span class="s1">'key'</span><span class="p">)</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">data</span> <span class="o">==</span> <span class="sa">b</span><span class="s1">'value2'</span><span class="p">)</span>
|
||||
|
||||
<span class="n">b</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">ropts</span><span class="p">,</span> <span class="n">cfhs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="sa">b</span><span class="s1">'key'</span><span class="p">)</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">data</span> <span class="o">==</span> <span class="sa">b</span><span class="s1">'value'</span><span class="p">)</span>
|
||||
|
||||
<span class="n">s</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">wopts</span><span class="p">,</span> <span class="n">cfhs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="sa">b</span><span class="s1">'key'</span><span class="p">)</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span>
|
||||
<span class="n">b</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">ropts</span><span class="p">,</span> <span class="n">cfhs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="sa">b</span><span class="s1">'key'</span><span class="p">)</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">is_not_found</span><span class="p">())</span>
|
||||
|
||||
<span class="n">s</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">wopts</span><span class="p">,</span> <span class="n">cfhs</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="sa">b</span><span class="s1">'key'</span><span class="p">)</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span>
|
||||
<span class="n">b</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">ropts</span><span class="p">,</span> <span class="n">cfhs</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="sa">b</span><span class="s1">'key'</span><span class="p">)</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">is_not_found</span><span class="p">())</span>
|
||||
|
||||
<span class="c1"># write batch</span>
|
||||
<span class="n">update</span> <span class="o">=</span> <span class="n">pyrocksdb</span><span class="o">.</span><span class="n">WriteBatch</span><span class="p">()</span>
|
||||
<span class="n">update</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">cfhs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="sa">b</span><span class="s1">'key1'</span><span class="p">,</span> <span class="sa">b</span><span class="s1">'value1'</span><span class="p">)</span>
|
||||
<span class="n">update</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">cfhs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="sa">b</span><span class="s1">'key2'</span><span class="p">,</span> <span class="sa">b</span><span class="s1">'value2'</span><span class="p">)</span>
|
||||
<span class="n">update</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">cfhs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s1">'key1'</span><span class="p">)</span>
|
||||
<span class="n">s</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">wopts</span><span class="p">,</span> <span class="n">update</span><span class="p">)</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span>
|
||||
<span class="n">b</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">ropts</span><span class="p">,</span> <span class="n">cfhs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="sa">b</span><span class="s1">'key1'</span><span class="p">)</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">is_not_found</span><span class="p">())</span>
|
||||
<span class="n">b</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">ropts</span><span class="p">,</span> <span class="n">cfhs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="sa">b</span><span class="s1">'key2'</span><span class="p">)</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">status</span><span class="o">.</span><span class="n">ok</span><span class="p">())</span>
|
||||
<span class="k">assert</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">data</span> <span class="o">==</span> <span class="sa">b</span><span class="s1">'value2'</span><span class="p">)</span>
|
||||
|
||||
<span class="k">for</span> <span class="n">cfh</span> <span class="ow">in</span> <span class="n">cfhs</span><span class="p">:</span>
|
||||
<span class="k">del</span> <span class="n">cfh</span>
|
||||
<span class="n">db</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="wrtie-batch">
|
||||
<h2>Wrtie Batch<a class="headerlink" href="#wrtie-batch" title="Permalink to this headline">¶</a></h2>
|
||||
<p>It is also possible to gather modifications and
|
||||
|
@ -123,6 +198,7 @@ valid. So you have to call one of its seek methods first</p>
|
|||
<ul class="current">
|
||||
<li class="toctree-l1"><a class="reference internal" href="../installation.html">Instructions how to install</a></li>
|
||||
<li class="toctree-l1 current"><a class="current reference internal" href="#">Tutorial</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#column-family">Column Family</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#wrtie-batch">Wrtie Batch</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#iteration">Iteration</a></li>
|
||||
</ul>
|
||||
|
|
Loading…
Reference in a new issue