hive_sql 1.0.0.pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +58 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +41 -0
  5. data/Rakefile +538 -0
  6. data/bin/hive_sql +23 -0
  7. data/hive_sql.gemspec +41 -0
  8. data/lib/hive_sql.rb +101 -0
  9. data/lib/hive_sql/models/account.rb +119 -0
  10. data/lib/hive_sql/models/block.rb +18 -0
  11. data/lib/hive_sql/models/comment.rb +142 -0
  12. data/lib/hive_sql/models/community.rb +78 -0
  13. data/lib/hive_sql/models/community_role.rb +37 -0
  14. data/lib/hive_sql/models/community_subscriber.rb +23 -0
  15. data/lib/hive_sql/models/connection.rb +18 -0
  16. data/lib/hive_sql/models/dynamic_global_properties.rb +45 -0
  17. data/lib/hive_sql/models/follower.rb +17 -0
  18. data/lib/hive_sql/models/reblog.rb +20 -0
  19. data/lib/hive_sql/models/sql_base.rb +28 -0
  20. data/lib/hive_sql/models/tag.rb +15 -0
  21. data/lib/hive_sql/models/token.rb +27 -0
  22. data/lib/hive_sql/models/transaction.rb +76 -0
  23. data/lib/hive_sql/models/tx/account_create.rb +26 -0
  24. data/lib/hive_sql/models/tx/account_recover.rb +20 -0
  25. data/lib/hive_sql/models/tx/account_update.rb +22 -0
  26. data/lib/hive_sql/models/tx/account_witness_proxy.rb +31 -0
  27. data/lib/hive_sql/models/tx/account_witness_vote.rb +22 -0
  28. data/lib/hive_sql/models/tx/claim_reward_balance.rb +21 -0
  29. data/lib/hive_sql/models/tx/comment.rb +24 -0
  30. data/lib/hive_sql/models/tx/comments_option.rb +23 -0
  31. data/lib/hive_sql/models/tx/convert.rb +20 -0
  32. data/lib/hive_sql/models/tx/custom.rb +25 -0
  33. data/lib/hive_sql/models/tx/custom/community.rb +32 -0
  34. data/lib/hive_sql/models/tx/custom/follow.rb +48 -0
  35. data/lib/hive_sql/models/tx/custom/reblog.rb +22 -0
  36. data/lib/hive_sql/models/tx/custom/witness.rb +11 -0
  37. data/lib/hive_sql/models/tx/delegate_vesting_share.rb +20 -0
  38. data/lib/hive_sql/models/tx/delete_comment.rb +19 -0
  39. data/lib/hive_sql/models/tx/escrow_approve.rb +23 -0
  40. data/lib/hive_sql/models/tx/escrow_dispute.rb +22 -0
  41. data/lib/hive_sql/models/tx/escrow_release.rb +25 -0
  42. data/lib/hive_sql/models/tx/escrow_transfer.rb +28 -0
  43. data/lib/hive_sql/models/tx/feed.rb +20 -0
  44. data/lib/hive_sql/models/tx/limit_order.rb +26 -0
  45. data/lib/hive_sql/models/tx/pow.rb +19 -0
  46. data/lib/hive_sql/models/tx/transfer.rb +24 -0
  47. data/lib/hive_sql/models/tx/update_proposal_vote.rb +31 -0
  48. data/lib/hive_sql/models/tx/vote.rb +21 -0
  49. data/lib/hive_sql/models/tx/withdraw.rb +19 -0
  50. data/lib/hive_sql/models/tx/withdraw_vesting_route.rb +21 -0
  51. data/lib/hive_sql/models/tx/witness_update.rb +24 -0
  52. data/lib/hive_sql/models/vo/author_reward.rb +22 -0
  53. data/lib/hive_sql/models/vo/comment_benefactor_reward.rb +23 -0
  54. data/lib/hive_sql/models/vo/curation_reward.rb +21 -0
  55. data/lib/hive_sql/models/vo/fill_convert_request.rb +21 -0
  56. data/lib/hive_sql/models/vo/fill_order.rb +23 -0
  57. data/lib/hive_sql/models/vo/fill_transfer_from_savings.rb +23 -0
  58. data/lib/hive_sql/models/vo/fill_vesting_withdraw.rb +21 -0
  59. data/lib/hive_sql/models/vo/interest.rb +19 -0
  60. data/lib/hive_sql/models/vo/liquidity_reward.rb +19 -0
  61. data/lib/hive_sql/models/vo/producer_reward.rb +19 -0
  62. data/lib/hive_sql/models/vo/proposal_pay.rb +20 -0
  63. data/lib/hive_sql/models/vo/return_vesting_delegation.rb +20 -0
  64. data/lib/hive_sql/models/vo/shutdown_witness.rb +18 -0
  65. data/lib/hive_sql/models/vo/sps_fund.rb +18 -0
  66. data/lib/hive_sql/models/witness.rb +48 -0
  67. data/lib/hive_sql/version.rb +3 -0
  68. metadata +413 -0
@@ -0,0 +1,22 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class AccountUpdate < HiveSQL::SqlBase
4
+
5
+ self.table_name = :TxAccountUpdates
6
+
7
+ end
8
+ end
9
+ end
10
+
11
+ # Structure
12
+ #
13
+ # HiveSQL::Tx::AccountUpdate(
14
+ # ID: integer,
15
+ # tx_id: integer,
16
+ # account: varchar,
17
+ # key_auth1: varchar,
18
+ # key_auth2: varchar,
19
+ # memo_key: varchar_max,
20
+ # json_metadata: varchar_max,
21
+ # timestamp: datetime
22
+ # )
@@ -0,0 +1,31 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class AccountWitnessProxy < HiveSQL::SqlBase
4
+
5
+ self.table_name = :TxAccountWitnessProxies
6
+
7
+ scope :active, lambda { |account = nil|
8
+ active = all
9
+ active = active.where(proxy: account) if !!account
10
+
11
+ ids = active.map do |p|
12
+ p.id unless AccountWitnessProxy.where(account: p.account).
13
+ where.not(proxy: p.Proxy).
14
+ where('timestamp > ?', p.timestamp).exists?
15
+ end
16
+
17
+ where(id: ids)
18
+ }
19
+ end
20
+ end
21
+ end
22
+
23
+ # Structure
24
+ #
25
+ # HiveSQL::Tx::AccountWitnessProxy(
26
+ # ID: integer,
27
+ # tx_id: integer,
28
+ # account: varchar,
29
+ # Proxy: varchar,
30
+ # timestamp: datetime
31
+ # )
@@ -0,0 +1,22 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class AccountWitnessVote < HiveSQL::SqlBase
4
+ belongs_to :account_record, foreign_key: :account, primary_key: :name, class_name: 'HiveSQL::Account'
5
+ belongs_to :witness_record, foreign_key: :witness, primary_key: :name, class_name: 'HiveSQL::Account'
6
+
7
+ self.table_name = :TxAccountWitnessVotes
8
+
9
+ end
10
+ end
11
+ end
12
+
13
+ # Structure
14
+ #
15
+ # HiveSQL::Tx::AccountWitnessVote(
16
+ # ID: integer,
17
+ # tx_id: integer,
18
+ # account: varchar,
19
+ # witness: varchar,
20
+ # approve: boolean,
21
+ # timestamp: datetime
22
+ # )
@@ -0,0 +1,21 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class ClaimRewardBalance < HiveSQL::SqlBase
4
+
5
+ self.table_name = :TxClaimRewardBalances
6
+
7
+ end
8
+ end
9
+ end
10
+
11
+ # Structure
12
+ #
13
+ # HiveSQL::Tx::ClaimRewardBalance(
14
+ # ID: integer,
15
+ # tx_id: integer,
16
+ # account: varchar,
17
+ # reward_steem: money,
18
+ # reward_sbd: money,
19
+ # reward_vests: money,
20
+ # timestamp: datetime
21
+ # )
@@ -0,0 +1,24 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class Comment < HiveSQL::SqlBase
4
+
5
+ self.table_name = :TxComments
6
+
7
+ end
8
+ end
9
+ end
10
+
11
+ # Structure
12
+ #
13
+ # HiveSQL::Tx::Comment(
14
+ # ID: integer,
15
+ # tx_id: integer,
16
+ # author: varchar,
17
+ # permlink: varchar,
18
+ # parent_author: varchar,
19
+ # parent_permlink: varchar,
20
+ # title: text,
21
+ # body: text,
22
+ # json_metadata: varchar_max,
23
+ # timestamp: datetime
24
+ # )
@@ -0,0 +1,23 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class CommentsOption < HiveSQL::SqlBase
4
+
5
+ self.table_name = :TxCommentsOptions
6
+
7
+ end
8
+ end
9
+ end
10
+
11
+ # Structure
12
+ #
13
+ # HiveSQL::Tx::CommentsOption(
14
+ # ID: integer,
15
+ # tx_id: integer,
16
+ # author: varchar,
17
+ # permlink: varchar,
18
+ # max_accepted_payout: money,
19
+ # percent_steem_dollars: integer,
20
+ # allow_votes: boolean,
21
+ # allow_curation_rewards: boolean,
22
+ # timestamp: datetime
23
+ # )
@@ -0,0 +1,20 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class Convert < HiveSQL::SqlBase
4
+
5
+ self.table_name = :TxConverts
6
+
7
+ end
8
+ end
9
+ end
10
+
11
+ # Structure
12
+ #
13
+ # HiveSQL::Tx::Convert(
14
+ # ID: integer,
15
+ # tx_id: integer,
16
+ # owner: varchar,
17
+ # requestid: integer,
18
+ # amount: money,
19
+ # timestamp: datetime
20
+ # )
@@ -0,0 +1,25 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class Custom < HiveSQL::SqlBase
4
+
5
+ self.table_name = :TxCustoms
6
+
7
+ scope :any_required_auths, lambda { |required_auth|
8
+ where("? IN(JSON_VALUE(required_auths, '$'))", required_auth)
9
+ }
10
+ scope :any_required_posting_auths, lambda { |required_posting_auth|
11
+ where("? IN(JSON_VALUE(required_posting_auths, '$'))", required_posting_auth)
12
+ }
13
+ end
14
+ end
15
+ end
16
+
17
+ # Structure
18
+ #
19
+ # HiveSQL::Tx::Custom(
20
+ # ID: integer,
21
+ # tx_id: integer,
22
+ # tid: varchar,
23
+ # json_metadata: varchar_max,
24
+ # timestamp: datetime
25
+ # )
@@ -0,0 +1,32 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class Custom::Community < HiveSQL::Tx::Custom
4
+ default_scope { where(tid: :community) }
5
+
6
+ scope :normalized_json, -> { where("ISJSON([TxCustoms].[json_metadata]) > 0") }
7
+ scope :op, lambda { |op| normalized_json.where("JSON_VALUE([TxCustoms].[json_metadata], '$[0]') = ?", op) }
8
+ scope :community, lambda { |community| normalized_json.where("JSON_VALUE([TxCustoms].[json_metadata], '$[1].community') = ?", community) }
9
+ scope :role, lambda { |role| normalized_json.where("JSON_VALUE([TxCustoms].[json_metadata], '$[1].role') = ?", role) }
10
+ scope :language, lambda { |language| normalized_json.where("JSON_VALUE([TxCustoms].[json_metadata], '$[1].language') = ?", language) }
11
+ scope :nsfw, lambda { |nsfw = true| normalized_json.where("JSON_VALUE([TxCustoms].[json_metadata], '$[1].is_nsfw') = ?", nsfw) }
12
+ scope :account, lambda { |account|
13
+ account = [account].flatten
14
+ normalized_json.where("required_auth IN(?) OR required_posting_auth IN(?) OR JSON_VALUE([TxCustoms].[json_metadata], '$[1].account') IN(?)", account, account, account)
15
+ }
16
+ scope :permlink, lambda { |permlink|
17
+ normalized_json.where("JSON_VALUE([TxCustoms].[json_metadata], '$[1].permlink') = ?", permlink)
18
+ }
19
+ scope :slug, lambda { |slug|
20
+ normalized_json.where("JSON_VALUE([TxCustoms].[json_metadata], '$[1].account') = ? AND JSON_VALUE([TxCustoms].[json_metadata], '$[1].permlink') = ?", *slug.split('/'))
21
+ }
22
+
23
+ def self.ops
24
+ distinct.normalized_json.pluck(Arel.sql "JSON_VALUE([TxCustoms].[json_metadata], '$[0]') AS ops")
25
+ end
26
+
27
+ def payload
28
+ JSON[json_metadata][1] rescue nil
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,48 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class Custom::Follow < HiveSQL::Tx::Custom
4
+ default_scope {
5
+ where(tid: :follow).
6
+ where("JSON_VALUE(json_metadata, '$[0]') = 'follow'")
7
+ }
8
+
9
+ scope :mode, lambda { |mode, options = {invert: false}|
10
+ invert = options[:invert] || false
11
+
12
+ if invert
13
+ where("JSON_VALUE(json_metadata, '$[1].what[0]') <> ?", mode)
14
+ else
15
+ where("JSON_VALUE(json_metadata, '$[1].what[0]') = ?", mode)
16
+ end
17
+ }
18
+
19
+ scope :blog, -> { mode('blog') }
20
+ scope :ignore, -> { mode('ignore') }
21
+ scope :clear, -> { mode('') }
22
+
23
+ scope :follower, lambda { |follower|
24
+ blog.where("JSON_VALUE(json_metadata, '$[1].follower') = ?", follower)
25
+ }
26
+
27
+ scope :following, lambda { |following|
28
+ blog.where("JSON_VALUE(json_metadata, '$[1].following') = ?", following)
29
+ }
30
+
31
+ scope :decorate_metadata, -> {
32
+ previous_select = if all.select_values.none?
33
+ Arel.star
34
+ else
35
+ all.select_values
36
+ end
37
+
38
+ r = select(previous_select)
39
+
40
+ %w(follower following what).each do |key|
41
+ r = r.select("JSON_VALUE(json_metadata, '$[1].#{key}') AS metadata_#{key}")
42
+ end
43
+
44
+ r
45
+ }
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,22 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class Custom::Reblog < HiveSQL::Tx::Custom
4
+ default_scope {
5
+ where(tid: :follow).
6
+ where("JSON_VALUE(json_metadata, '$[0]') = 'reblog'")
7
+ }
8
+
9
+ scope :account, lambda { |account|
10
+ where("JSON_VALUE(json_metadata, '$[1].account') = ?", account)
11
+ }
12
+
13
+ scope :author, lambda { |author|
14
+ where("JSON_VALUE(json_metadata, '$[1].author') = ?", author)
15
+ }
16
+
17
+ scope :permlink, lambda { |permlink|
18
+ where("JSON_VALUE(json_metadata, '$[1].permlink') = ?", permlink)
19
+ }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class Custom::Witness < HiveSQL::Tx::Custom
4
+ default_scope { where(tid: :witness) }
5
+
6
+ scope :account, lambda { |account|
7
+ where("JSON_VALUE(json_metadata, '$[1].account') = ?", account)
8
+ }
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class DelegateVestingShare < HiveSQL::SqlBase
4
+
5
+ self.table_name = :TxDelegateVestingShares
6
+
7
+ end
8
+ end
9
+ end
10
+
11
+ # Structure
12
+ #
13
+ # HiveSQL::Tx::DelegateVestingShare(
14
+ # ID: integer,
15
+ # tx_id: integer,
16
+ # delegator: varchar,
17
+ # delegatee: varchar,
18
+ # vesting_shares: money,
19
+ # timestamp: datetime
20
+ # )
@@ -0,0 +1,19 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class DeleteComment < HiveSQL::SqlBase
4
+
5
+ self.table_name = :TxDeleteComments
6
+
7
+ end
8
+ end
9
+ end
10
+
11
+ # Structure
12
+ #
13
+ # HiveSQL::Tx::DeleteComment(
14
+ # ID: integer,
15
+ # tx_id: integer,
16
+ # author: varchar,
17
+ # permlink: varchar_max,
18
+ # timestamp: datetime
19
+ # )
@@ -0,0 +1,23 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class EscrowApprove < HiveSQL::SqlBase
4
+
5
+ self.table_name = :TxEscrowApproves
6
+
7
+ end
8
+ end
9
+ end
10
+
11
+ # Structure
12
+ #
13
+ # HiveSQL::Tx::EscrowApprove(
14
+ # ID: integer,
15
+ # tx_id: integer,
16
+ # from: varchar,
17
+ # to: varchar,
18
+ # agent: varchar,
19
+ # who: varchar,
20
+ # escrow_id: integer,
21
+ # approve: boolean,
22
+ # timestamp: datetime
23
+ # )
@@ -0,0 +1,22 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class EscrowDispute < HiveSQL::SqlBase
4
+
5
+ self.table_name = :TxEscrowDisputes
6
+
7
+ end
8
+ end
9
+ end
10
+
11
+ # Structure
12
+ #
13
+ # HiveSQL::Tx::EscrowDispute(
14
+ # ID: integer,
15
+ # tx_id: integer,
16
+ # from: varchar,
17
+ # to: varchar,
18
+ # agent: varchar,
19
+ # who: varchar,
20
+ # escrow_id: integer,
21
+ # timestamp: datetime
22
+ # )
@@ -0,0 +1,25 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class EscrowRelease < HiveSQL::SqlBase
4
+
5
+ self.table_name = :TxEscrowReleases
6
+
7
+ end
8
+ end
9
+ end
10
+
11
+ # Structure
12
+ #
13
+ # HiveSQL::Tx::EscrowRelease(
14
+ # ID: integer,
15
+ # tx_id: integer,
16
+ # from: varchar,
17
+ # to: varchar,
18
+ # agent: varchar,
19
+ # who: varchar,
20
+ # receiver: varchar,
21
+ # escrow_id: integer,
22
+ # sdb_amount: money,
23
+ # steem_amount: money,
24
+ # timestamp: datetime
25
+ # )
@@ -0,0 +1,28 @@
1
+ module HiveSQL
2
+ module Tx
3
+ class EscrowTransfer < HiveSQL::SqlBase
4
+
5
+ self.table_name = :TxEscrowTransfers
6
+
7
+ end
8
+ end
9
+ end
10
+
11
+ # Structure
12
+ #
13
+ # HiveSQL::Tx::EscrowTransfer(
14
+ # ID: integer,
15
+ # tx_id: integer,
16
+ # from: varchar,
17
+ # to: varchar,
18
+ # sdb_amount: money,
19
+ # steem_amount: money,
20
+ # escrow_id: integer,
21
+ # agent: varchar,
22
+ # fee: money,
23
+ # fee_symbol: varchar,
24
+ # json_meta: varchar_max,
25
+ # ratification_deadline: datetime,
26
+ # escrow_expiration: datetime,
27
+ # timestamp: datetime
28
+ # )