有了Python列表我可以這樣做:RethinkDB表中的特定ID如何?
if 'myfakeuser' in list_of_usernames:
print "This user exists"
我怎樣才能做到這一點與Rethinkdb? r.db('mydb').table('users').get('myfakeuser')。run()不會返回任何內容或在沒有id設置myfakeuser時引發錯誤。
有了Python列表我可以這樣做:RethinkDB表中的特定ID如何?
if 'myfakeuser' in list_of_usernames:
print "This user exists"
我怎樣才能做到這一點與Rethinkdb? r.db('mydb').table('users').get('myfakeuser')。run()不會返回任何內容或在沒有id設置myfakeuser時引發錯誤。
Python驅動程序的行爲與Ruby驅動程序的行爲相同。如果該鍵不存在,它將返回無。
>>> my_profile = r.table('foo').get('myname').run(conn)
>>> print my_profile
>>> None
您也可以使用is_empty方法,該方法將返回True如果值不存在值,或者如果此值不存在,它將返回False。
>>> doesnt_exist = r.table('foo').get_all('myname').is_empty().run(conn)
>>> print doesnt_exist
>>> True
如果查詢是正確的,並且沒有錯,則不會返回錯誤,但會返回一個零值。想想SQL,它會返回一個空的行集合,而不是拋出錯誤,因爲查詢和服務器連接都沒有錯。
我不知道Python,但在JavaScript或紅寶石,一個null
/nil
值將在數據Exploer返回
運行此,你會得到一個null
結果
r.table('foo').get('anivalidprimarykey')
或者在JavaScript :
r.table('foo').get('anivalidprimarykey').run(connection)
.then(function(result) {
console.log('r=', result)
})
.error(function(err) {
console.log('e=', err)
})
你會得到一個null
值result
VAR iable。
與Ruby相同的東西,雖然你得到了nil
值。
require 'rethinkdb'
include RethinkDB::Shortcuts
r.connect.repl
r.table(:foo).get('an_in_valid_key').run
nil
所以我假設Python驅動程序會做同樣的事情,在你的語言中返回一個零值。