forked from LBRYCommunity/lbry-sdk
coalesce null balance
This commit is contained in:
parent
6764d52634
commit
d8f5b11158
1 changed files with 9 additions and 13 deletions
|
@ -545,25 +545,21 @@ def get_balance(account_ids):
|
||||||
txi_address_check = TXI.c.address.in_(my_addresses)
|
txi_address_check = TXI.c.address.in_(my_addresses)
|
||||||
query = (
|
query = (
|
||||||
select(
|
select(
|
||||||
func.sum(TXO.c.amount).label("total"),
|
func.coalesce(func.sum(TXO.c.amount), 0).label("total"),
|
||||||
func.sum(case(
|
func.coalesce(func.sum(case(
|
||||||
[(TXO.c.txo_type != TXO_TYPES["other"], TXO.c.amount)],
|
[(TXO.c.txo_type != TXO_TYPES["other"], TXO.c.amount)],
|
||||||
else_=0
|
)), 0).label("reserved"),
|
||||||
)).label("reserved"),
|
func.coalesce(func.sum(case(
|
||||||
func.sum(case(
|
|
||||||
[(where_txo_type_in(CLAIM_TYPE_CODES), TXO.c.amount)],
|
[(where_txo_type_in(CLAIM_TYPE_CODES), TXO.c.amount)],
|
||||||
else_=0
|
)), 0).label("claims"),
|
||||||
)).label("claims"),
|
func.coalesce(func.sum(case(
|
||||||
func.sum(case(
|
|
||||||
[(where_txo_type_in(TXO_TYPES["support"]), TXO.c.amount)],
|
[(where_txo_type_in(TXO_TYPES["support"]), TXO.c.amount)],
|
||||||
else_=0
|
)), 0).label("supports"),
|
||||||
)).label("supports"),
|
func.coalesce(func.sum(case(
|
||||||
func.sum(case(
|
|
||||||
[(where_txo_type_in(TXO_TYPES["support"]) & (
|
[(where_txo_type_in(TXO_TYPES["support"]) & (
|
||||||
(TXI.c.address.isnot(None)) & txi_address_check
|
(TXI.c.address.isnot(None)) & txi_address_check
|
||||||
), TXO.c.amount)],
|
), TXO.c.amount)],
|
||||||
else_=0
|
)), 0).label("my_supports"),
|
||||||
)).label("my_supports"),
|
|
||||||
)
|
)
|
||||||
.where((TXO.c.spent_height == 0) & txo_address_check)
|
.where((TXO.c.spent_height == 0) & txo_address_check)
|
||||||
.select_from(
|
.select_from(
|
||||||
|
|
Loading…
Reference in a new issue