{"id":20272295,"url":"https://github.com/steemit/hivemind-ruby","last_synced_at":"2025-04-11T04:42:03.185Z","repository":{"id":56876465,"uuid":"144059499","full_name":"steemit/hivemind-ruby","owner":"steemit","description":"Ruby Object Relational Mapping for Hivemind","archived":false,"fork":false,"pushed_at":"2018-09-27T02:53:00.000Z","size":22,"stargazers_count":4,"open_issues_count":0,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-11T04:41:59.491Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/steemit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-08T19:36:18.000Z","updated_at":"2023-02-11T05:18:37.000Z","dependencies_parsed_at":"2022-08-20T23:10:27.418Z","dependency_job_id":null,"html_url":"https://github.com/steemit/hivemind-ruby","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steemit%2Fhivemind-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steemit%2Fhivemind-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steemit%2Fhivemind-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steemit%2Fhivemind-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/steemit","download_url":"https://codeload.github.com/steemit/hivemind-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345281,"owners_count":21088242,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T12:42:46.506Z","updated_at":"2025-04-11T04:42:03.166Z","avatar_url":"https://github.com/steemit.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Gem Version](https://badge.fury.io/rb/hivemind-ruby.svg)](https://badge.fury.io/rb/hivemind-ruby)\n[![Inline docs](http://inch-ci.org/github/steemit/hivemind-ruby.svg?branch=master\u0026style=shields)](http://inch-ci.org/github/steemit/hivemind-ruby)\n\n# `hivemind-ruby` - Object Relational Mapping for Hivemind\n\nIf you run your own `hivemind` node, you can leverage your local subset of the blockchain you've synchronized to Postgres using ActiveRecord.\n\nWhat does that mean?  It means if, for example, you have an existing Rails application, you can use this gem to access your `hivemind` node and access all of the data stored there.\n\nFull documentation: http://www.rubydoc.info/gems/hivemind-ruby\n\n## Overview\n\n##### What problem does this tool solve?\n\nIt allows you to bypass `steemd` and access a representation of the blockchain maintained by `hivemind` for certain types of queries.\n\n##### Why would I want to bypass `steemd`?  Isn't that the authoritative way to access the blockchain?\n\nYes, `steemd` is authoritative.  But for certain kinds of queries, there are alternatives.  For example, if you wanted to find all users that have the letter `z` in their account name, `steemd` is not the best tool.\n\nInstead, we can use an SQL statement like:\n\n```sql\nSELECT \"hive_accounts\".*\nFROM   \"hive_accounts\"\nWHERE  (name LIKE '%z%');\n```\n\nBut, you don't have to write this SQL.  You can let ActiveRecord do it instead:\n\n```ruby\nHive::Account.where(\"name LIKE ?\", '%z%')\n```\n\nTo do this query comprehensively with `steemd` would require hours of API calls to find accounts that match.  But using SQL, it takes less than a second.\n\n##### What can I query with `hivemind`?\n\nThe focus of `hivemind` is on communities:\n\n[Developer-friendly microservice powering social networks on the Steem blockchain.\n](https://github.com/steemit/hivemind#developer-friendly-microservice-powering-social-networks-on-the-steem-blockchain)\n\n\u003e Hive is a \"consensus interpretation\" layer for the Steem blockchain, maintaining the state of social features such as post feeds, follows, and communities. Written in Python, it synchronizes an SQL database with chain state, providing developers with a more flexible/extensible alternative to the raw steemd API.\n\nYou should refer to the main `hivemind` [purpose](https://github.com/steemit/hivemind#purpose) to determine specifically what blockchain data it will index.\n\nThis tool will allow rubyists to access the same database that `hivemind` maintains.\n\n## Getting Started\n\nThe hivemind-ruby gem is compatible with Ruby 2.2.5 or later.  Also targets [ActiveRecord 5.2](https://github.com/rails/rails/blob/v5.2.0/activerecord/CHANGELOG.md#rails-520-april-09-2018), but older versions may work as well.\n\n## Installation\n\n*(Assuming that [Ruby is installed](https://www.ruby-lang.org/en/downloads/) on your computer, as well as [RubyGems](http://rubygems.org/pages/download))*\n\nFirst, you need your own [`hivemind`](https://github.com/steemit/hivemind) node.  A `hivemind` node requires at least 310GB of HDD storage for the database (as of August of 2018).\n\nAlso install the minimal set of `PostgreSQL` binaries and headers requried for building 3rd-party applications:\n\n### Linux\n\n```bash\n$ apt-get install libpq-dev\n```\n\n### macOS\n\nShould already be provided if you have `PostgreSQL` provided by homebrew.\n\n### Verify psql\n\nOnce it's running and all synced, just make sure you can access Postgres locally, e.g.:\n\n```bash\npsql hive\n```\n\nIf that works, you can use this gem.  Keep in mind, if you stop the sync, your Postgres database will fall behind the head block.  Once you resume, `hivemind` will pick up where it left off.\n\n*It's that easy!*\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'hivemind-ruby', require: 'hive'\n```\n\nAnd then execute:\n```bash\n$ bundle install\n```\n\nOr install it yourself as:\n```bash\n$ gem install hivemind-ruby\n```\n\n## Usage\n\nIf you've already installed the gem, to check on your configuration, use this command from the terminal:\n\n```bash\nexport DATABASE_URL=postgresql://user:pass@localhost:5432/hive\nhivmind-ruby\n```\n\nOr, if you'd like to use the interactive ruby console with `hive` already required:\n\n```bash\nhivmind-ruby console\n```\n\nHere are a bunch of ActiveRecord queries you can do in your app (or from the interactive console).\n\nThis will return the number of accounts currently synced:\n\n```ruby\nHive::Account.count\n```\n\nTo do the same as accounts, but for posts, this counts everything, including root posts and comments:\n\n```ruby\nHive::Post.count\n```\n\nThis counts just the number of root posts (not comments):\n\n```ruby\nHive::Post.root_posts.count\n```\n\nThis counts just the number of comments (not root posts):\n\n```ruby\nHive::Post.replies.count\nHive::Post.replies(parent_author: 'alice').count # just replies to alice\nHive::Post.replies(parent_author: %w(alice bob)).count # just replies to alice or bob\n```\n\nThis will report the number of accounts with `z` in their name:\n\n```ruby\naccounts = Hive::Account.where(\"name LIKE ?\", '%z%')\naccounts.count\n```\n\nThis will show you the number of root posts by `alice`:\n\n```ruby\nalice = Hive::Account.find_by_name 'alice'\nalice.posts.root_posts.count\n```\n\nThis will show you the number of reblogs by `alice`:\n\n```ruby\nalice = Hive::Account.find_by_name 'alice'\nalice.reblogged_posts.count\n```\n\nThis is the number of accounts that `alice` follows:\n\n```ruby\nalice = Hive::Account.find_by_name 'alice'\nalice.following.count\n```\n\nThis is the number of accounts that follow `alice`:\n\n```ruby\nalice = Hive::Account.find_by_name 'alice'\nalice.followers.count\n```\n\nThe entire feed for `alice` (all content created by accounts `alice` follows, roughly analogous to https://steemit.com/@alice/feed):\n\n```ruby\nalice = Hive::Account.find_by_name 'alice'\nalice.feed.count\n```\n\nThis is the entire discussion for the first post on the Steem platform (e.g.: https://steemit.com/@steemit/firstpost):\n\n```ruby\nfirstpost = Hive::Post.first\nfirstpost.discussion.count\n```\n\nTo get the direct children of a post:\n\n```ruby\nfirstpost = Hive::Post.first\nfirstpost.children.count\n```\n\n### Tests\n\n* Clone the client repository into a directory of your choice:\n  * `git clone https://github.com/steemit/hivemind-ruby.git`\n* Navigate into the new folder\n  * `cd hivemind-ruby`\n* All tests can be invoked as follows:\n  * `DATABASE_URL=postgresql://user:pass@localhost:5432/hive bundle exec rake test`\n\n## Contributions\n\nPatches are welcome! Contributors are listed in the `hivemind-ruby.gemspec` file. Please run the tests (`rake test`) before opening a pull request and make sure that you are passing all of them. If you would like to contribute, but don't know what to work on, check the issues list.\n\n## Issues\n\nWhen you find issues, please report them!\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteemit%2Fhivemind-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsteemit%2Fhivemind-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteemit%2Fhivemind-ruby/lists"}