2019-11-07 20:39:22 +01:00
const mysql = require ( 'mysql' ) ;
const pool = mysql . createPool ( {
connectionLimit : 100 ,
host : 'chainquery.lbry.com' ,
user : 'lbrytv' ,
password : process . env . CHAINQUERY _MYSQL _PASSWORD ,
database : 'chainquery' ,
} ) ;
function queryPool ( sql , params ) {
return new Promise ( resolve => {
pool . query ( sql , params , ( error , rows ) => {
if ( error ) {
2020-12-01 18:56:59 +01:00
console . log ( 'error' , error ) ; // eslint-disable-line
2020-05-25 06:39:14 +02:00
resolve ( ) ;
return ;
2019-11-07 20:39:22 +01:00
}
resolve ( rows ) ;
} ) ;
} ) ;
}
module . exports . getClaim = async function getClaim ( claimName , claimId , channelName , channelClaimId ) {
let params = [ claimName ] ;
let sql =
2020-07-28 03:47:32 +02:00
'SELECT channel_claim.name as channel, claim.claim_id, claim.name, claim.description, claim.language, claim.thumbnail_url, claim.title, claim.source_media_type, claim.frame_width, claim.frame_height, claim.fee, claim.release_time, claim.duration, claim.audio_duration, ' +
2020-07-28 21:28:51 +02:00
'repost_channel.name as repost_channel, reposted_claim.claim_id as reposted_claim_id, reposted_claim.name as reposted_name, reposted_claim.description as reposted_description, reposted_claim.language as reposted_language, reposted_claim.thumbnail_url as reposted_thumbnail_url, reposted_claim.title as reposted_title, reposted_claim.source_media_type as reposted_source_media_type, reposted_claim.frame_width as reposted_frame_width, reposted_claim.frame_height as reposted_frame_height, reposted_claim.fee as reposted_fee ' +
2019-11-07 20:39:22 +01:00
'FROM claim ' +
'LEFT JOIN claim channel_claim on claim.publisher_id = channel_claim.claim_id ' +
2020-07-28 21:28:51 +02:00
'LEFT JOIN claim as reposted_claim on reposted_claim.claim_id = claim.claim_reference ' +
2020-12-21 22:16:05 +01:00
'AND (reposted_claim.bid_state in ("controlling", "active", "accepted", "spent")) ' +
2020-07-28 21:28:51 +02:00
'LEFT JOIN claim as repost_channel on repost_channel.claim_id = reposted_claim.publisher_id ' +
2019-11-07 20:39:22 +01:00
'WHERE claim.name = ?' ;
if ( claimId ) {
sql += ' AND claim.claim_id LIKE ?' ;
params . push ( claimId + '%' ) ;
}
2020-12-21 21:42:55 +01:00
sql += ' AND claim.bid_state in ("controlling", "active", "accepted", "spent")' ;
2020-07-28 21:28:51 +02:00
2019-11-07 20:39:22 +01:00
if ( claimName [ 0 ] !== '@' && channelName ) {
sql += ' AND channel_claim.name = ?' ;
params . push ( '@' + channelName ) ;
if ( channelClaimId ) {
sql += ' AND channel_claim.claim_id LIKE ?' ;
params . push ( channelClaimId + '%' ) ;
} else {
2020-12-21 21:42:55 +01:00
sql += ' AND channel_claim.bid_state in ("controlling", "active", "accepted", "spent")' ;
2019-11-07 20:39:22 +01:00
}
}
2020-08-12 14:59:31 +02:00
sql += ' ORDER BY claim.bid_state DESC LIMIT 1' ;
2019-11-07 20:39:22 +01:00
return queryPool ( sql , params ) ;
} ;