# HiveSQL for Ruby developers

[@inertia](https://peakd.com/@inertia) is developing and maintaining a library for Ruby developers

Gem repository: <https://github.com/inertia186/hive_sql>

{% hint style="info" %}
To use this gem, you must an active [@hivesql](https://peakd.com/@hivesql) subscription and store the credentials as environment variables. Read [Register your HiveSQL acount](https://docs.hivesql.io/register-your-hivesql-acount) to find out about HiveSQL accounts
{% endhint %}

#### Installation <a href="#installation" id="installation"></a>

First, install ruby. One way to do this is install [rvm](https://rvm.io/install). Once ruby is installed, install `hive_sql` with the `gem` command:

```
gem install hive_sql
```

Or, add it to your `Gemfile`:

```
gem 'hive_sql'
```

#### How To Use (Standalone) <a href="#how-to-use-standalone" id="how-to-use-standalone"></a>

```
gem install hive_sql
export HIVESQL_HOST=<your hivesql host>
export HIVESQL_USERNAME=<your hivesql username>
export HIVESQL_PASSWORD=<your hivesql password>
hive_sql top upvoted
```

The above example will query the top upvoted content for the last 7 days.

#### Models <a href="#models" id="models"></a>

* Account
* Block
  * Transaction
    * *various operations*
* Comment
* Community
  * Role
  * Subscriber
* Follower
* Reblog
* Tag
* Token
* Witness

#### Followers <a href="#followers" id="followers"></a>

How to query today's followers:

```
followers = HiveSQL::Tx::Custom::Follow
followers.following(:alice).today.count
```

#### Reblog <a href="#reblog" id="reblog"></a>

How to query today's reblogs:

```
reblogs = HiveSQL::Tx::Custom::Reblog
reblogs.author(:alice).today.count
```

#### Account Witness Proxy <a href="#account-witness-proxy" id="account-witness-proxy"></a>

How to query current accounts that are actively using a proxy:

```
proxied = HiveSQL::Tx::AccountWitnessProxy.active('alice')
proxied.pluck(:account)
```

#### Applications <a href="#applications" id="applications"></a>

How to query comments by application:

```
comments = HiveSQL::Comment.app('esteem').where(author: 'good-karma')
```

### License <a href="#license" id="license"></a>

HiveSQL gem is licensed under a Creative Commons CC0 License.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hivesql.io/tutorials/hivesql-for-ruby-developers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
