mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
s/table/collection/g
This commit is contained in:
parent
83afab4958
commit
ca49718d7e
@ -64,7 +64,7 @@ class MongoDBConnection(Connection):
|
|||||||
time.sleep(2**i)
|
time.sleep(2**i)
|
||||||
|
|
||||||
|
|
||||||
def table(name):
|
def collection(name):
|
||||||
return Lazy()[name]
|
return Lazy()[name]
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ from pymongo import errors
|
|||||||
from bigchaindb import backend
|
from bigchaindb import backend
|
||||||
from bigchaindb.common.exceptions import CyclicBlockchainError
|
from bigchaindb.common.exceptions import CyclicBlockchainError
|
||||||
from bigchaindb.backend.utils import module_dispatch_registrar
|
from bigchaindb.backend.utils import module_dispatch_registrar
|
||||||
from bigchaindb.backend.mongodb.connection import MongoDBConnection, table
|
from bigchaindb.backend.mongodb.connection import MongoDBConnection, collection
|
||||||
|
|
||||||
|
|
||||||
register_query = module_dispatch_registrar(backend.query)
|
register_query = module_dispatch_registrar(backend.query)
|
||||||
@ -19,7 +19,7 @@ register_query = module_dispatch_registrar(backend.query)
|
|||||||
def write_transaction(conn, signed_transaction):
|
def write_transaction(conn, signed_transaction):
|
||||||
try:
|
try:
|
||||||
return conn.run(
|
return conn.run(
|
||||||
table('backlog')
|
collection('backlog')
|
||||||
.insert_one(signed_transaction))
|
.insert_one(signed_transaction))
|
||||||
except errors.DuplicateKeyError:
|
except errors.DuplicateKeyError:
|
||||||
return
|
return
|
||||||
@ -30,7 +30,7 @@ def update_transaction(conn, transaction_id, doc):
|
|||||||
# with mongodb we need to add update operators to the doc
|
# with mongodb we need to add update operators to the doc
|
||||||
doc = {'$set': doc}
|
doc = {'$set': doc}
|
||||||
return conn.run(
|
return conn.run(
|
||||||
table('backlog')
|
collection('backlog')
|
||||||
.find_one_and_update(
|
.find_one_and_update(
|
||||||
{'id': transaction_id},
|
{'id': transaction_id},
|
||||||
doc,
|
doc,
|
||||||
@ -40,14 +40,14 @@ def update_transaction(conn, transaction_id, doc):
|
|||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def delete_transaction(conn, *transaction_id):
|
def delete_transaction(conn, *transaction_id):
|
||||||
return conn.run(
|
return conn.run(
|
||||||
table('backlog')
|
collection('backlog')
|
||||||
.delete_many({'id': {'$in': transaction_id}}))
|
.delete_many({'id': {'$in': transaction_id}}))
|
||||||
|
|
||||||
|
|
||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def get_stale_transactions(conn, reassign_delay):
|
def get_stale_transactions(conn, reassign_delay):
|
||||||
return conn.run(
|
return conn.run(
|
||||||
table('backlog')
|
collection('backlog')
|
||||||
.find({'assignment_timestamp': {'$lt': time() - reassign_delay}},
|
.find({'assignment_timestamp': {'$lt': time() - reassign_delay}},
|
||||||
projection={'_id': False}))
|
projection={'_id': False}))
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ def get_stale_transactions(conn, reassign_delay):
|
|||||||
def get_transaction_from_block(conn, transaction_id, block_id):
|
def get_transaction_from_block(conn, transaction_id, block_id):
|
||||||
try:
|
try:
|
||||||
return conn.run(
|
return conn.run(
|
||||||
table('bigchain')
|
collection('bigchain')
|
||||||
.aggregate([
|
.aggregate([
|
||||||
{'$match': {'id': block_id}},
|
{'$match': {'id': block_id}},
|
||||||
{'$project': {
|
{'$project': {
|
||||||
@ -82,7 +82,7 @@ def get_transaction_from_block(conn, transaction_id, block_id):
|
|||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def get_transaction_from_backlog(conn, transaction_id):
|
def get_transaction_from_backlog(conn, transaction_id):
|
||||||
return conn.run(
|
return conn.run(
|
||||||
table('backlog')
|
collection('backlog')
|
||||||
.find_one({'id': transaction_id},
|
.find_one({'id': transaction_id},
|
||||||
projection={'_id': False,
|
projection={'_id': False,
|
||||||
'assignee': False,
|
'assignee': False,
|
||||||
@ -92,7 +92,7 @@ def get_transaction_from_backlog(conn, transaction_id):
|
|||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def get_blocks_status_from_transaction(conn, transaction_id):
|
def get_blocks_status_from_transaction(conn, transaction_id):
|
||||||
return conn.run(
|
return conn.run(
|
||||||
table('bigchain')
|
collection('bigchain')
|
||||||
.find({'block.transactions.id': transaction_id},
|
.find({'block.transactions.id': transaction_id},
|
||||||
projection=['id', 'block.voters']))
|
projection=['id', 'block.voters']))
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ def get_blocks_status_from_transaction(conn, transaction_id):
|
|||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def get_asset_by_id(conn, asset_id):
|
def get_asset_by_id(conn, asset_id):
|
||||||
cursor = conn.run(
|
cursor = conn.run(
|
||||||
table('bigchain')
|
collection('bigchain')
|
||||||
.aggregate([
|
.aggregate([
|
||||||
{'$match': {
|
{'$match': {
|
||||||
'block.transactions.id': asset_id,
|
'block.transactions.id': asset_id,
|
||||||
@ -121,7 +121,7 @@ def get_asset_by_id(conn, asset_id):
|
|||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def get_spent(conn, transaction_id, output):
|
def get_spent(conn, transaction_id, output):
|
||||||
cursor = conn.run(
|
cursor = conn.run(
|
||||||
table('bigchain').aggregate([
|
collection('bigchain').aggregate([
|
||||||
{'$unwind': '$block.transactions'},
|
{'$unwind': '$block.transactions'},
|
||||||
{'$match': {
|
{'$match': {
|
||||||
'block.transactions.inputs.fulfills.txid': transaction_id,
|
'block.transactions.inputs.fulfills.txid': transaction_id,
|
||||||
@ -136,7 +136,7 @@ def get_spent(conn, transaction_id, output):
|
|||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def get_owned_ids(conn, owner):
|
def get_owned_ids(conn, owner):
|
||||||
cursor = conn.run(
|
cursor = conn.run(
|
||||||
table('bigchain')
|
collection('bigchain')
|
||||||
.aggregate([
|
.aggregate([
|
||||||
{'$unwind': '$block.transactions'},
|
{'$unwind': '$block.transactions'},
|
||||||
{'$match': {
|
{'$match': {
|
||||||
@ -153,7 +153,7 @@ def get_owned_ids(conn, owner):
|
|||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def get_votes_by_block_id(conn, block_id):
|
def get_votes_by_block_id(conn, block_id):
|
||||||
return conn.run(
|
return conn.run(
|
||||||
table('votes')
|
collection('votes')
|
||||||
.find({'vote.voting_for_block': block_id},
|
.find({'vote.voting_for_block': block_id},
|
||||||
projection={'_id': False}))
|
projection={'_id': False}))
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ def get_votes_by_block_id(conn, block_id):
|
|||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def get_votes_by_block_id_and_voter(conn, block_id, node_pubkey):
|
def get_votes_by_block_id_and_voter(conn, block_id, node_pubkey):
|
||||||
return conn.run(
|
return conn.run(
|
||||||
table('votes')
|
collection('votes')
|
||||||
.find({'vote.voting_for_block': block_id,
|
.find({'vote.voting_for_block': block_id,
|
||||||
'node_pubkey': node_pubkey},
|
'node_pubkey': node_pubkey},
|
||||||
projection={'_id': False}))
|
projection={'_id': False}))
|
||||||
@ -170,14 +170,14 @@ def get_votes_by_block_id_and_voter(conn, block_id, node_pubkey):
|
|||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def write_block(conn, block):
|
def write_block(conn, block):
|
||||||
return conn.run(
|
return conn.run(
|
||||||
table('bigchain')
|
collection('bigchain')
|
||||||
.insert_one(block.to_dict()))
|
.insert_one(block.to_dict()))
|
||||||
|
|
||||||
|
|
||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def get_block(conn, block_id):
|
def get_block(conn, block_id):
|
||||||
return conn.run(
|
return conn.run(
|
||||||
table('bigchain')
|
collection('bigchain')
|
||||||
.find_one({'id': block_id},
|
.find_one({'id': block_id},
|
||||||
projection={'_id': False}))
|
projection={'_id': False}))
|
||||||
|
|
||||||
@ -185,27 +185,27 @@ def get_block(conn, block_id):
|
|||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def has_transaction(conn, transaction_id):
|
def has_transaction(conn, transaction_id):
|
||||||
return bool(conn.run(
|
return bool(conn.run(
|
||||||
table('bigchain')
|
collection('bigchain')
|
||||||
.find_one({'block.transactions.id': transaction_id})))
|
.find_one({'block.transactions.id': transaction_id})))
|
||||||
|
|
||||||
|
|
||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def count_blocks(conn):
|
def count_blocks(conn):
|
||||||
return conn.run(
|
return conn.run(
|
||||||
table('bigchain')
|
collection('bigchain')
|
||||||
.count())
|
.count())
|
||||||
|
|
||||||
|
|
||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def count_backlog(conn):
|
def count_backlog(conn):
|
||||||
return conn.run(
|
return conn.run(
|
||||||
table('backlog')
|
collection('backlog')
|
||||||
.count())
|
.count())
|
||||||
|
|
||||||
|
|
||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def write_vote(conn, vote):
|
def write_vote(conn, vote):
|
||||||
conn.run(table('votes').insert_one(vote))
|
conn.run(collection('votes').insert_one(vote))
|
||||||
vote.pop('_id')
|
vote.pop('_id')
|
||||||
return vote
|
return vote
|
||||||
|
|
||||||
@ -213,7 +213,7 @@ def write_vote(conn, vote):
|
|||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def get_genesis_block(conn):
|
def get_genesis_block(conn):
|
||||||
return conn.run(
|
return conn.run(
|
||||||
table('bigchain')
|
collection('bigchain')
|
||||||
.find_one(
|
.find_one(
|
||||||
{'block.transactions.0.operation': 'GENESIS'},
|
{'block.transactions.0.operation': 'GENESIS'},
|
||||||
{'_id': False}
|
{'_id': False}
|
||||||
@ -223,7 +223,7 @@ def get_genesis_block(conn):
|
|||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def get_last_voted_block(conn, node_pubkey):
|
def get_last_voted_block(conn, node_pubkey):
|
||||||
last_voted = conn.run(
|
last_voted = conn.run(
|
||||||
table('votes')
|
collection('votes')
|
||||||
.find({'node_pubkey': node_pubkey},
|
.find({'node_pubkey': node_pubkey},
|
||||||
sort=[('vote.timestamp', -1)]))
|
sort=[('vote.timestamp', -1)]))
|
||||||
|
|
||||||
@ -254,7 +254,7 @@ def get_last_voted_block(conn, node_pubkey):
|
|||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def get_unvoted_blocks(conn, node_pubkey):
|
def get_unvoted_blocks(conn, node_pubkey):
|
||||||
return conn.run(
|
return conn.run(
|
||||||
table('bigchain').aggregate([
|
collection('bigchain').aggregate([
|
||||||
{'$lookup': {
|
{'$lookup': {
|
||||||
'from': 'votes',
|
'from': 'votes',
|
||||||
'localField': 'id',
|
'localField': 'id',
|
||||||
@ -279,7 +279,7 @@ def get_txids_filtered(conn, asset_id, operation=None):
|
|||||||
match['block.transactions.operation'] = operation
|
match['block.transactions.operation'] = operation
|
||||||
|
|
||||||
cursor = conn.run(
|
cursor = conn.run(
|
||||||
table('bigchain')
|
collection('bigchain')
|
||||||
.aggregate([
|
.aggregate([
|
||||||
{'$match': match},
|
{'$match': match},
|
||||||
{'$unwind': '$block.transactions'},
|
{'$unwind': '$block.transactions'},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user