Project

bithex

0.0
No release in over 3 years
Low commit activity in last 3 years
Store hex strings as bit strings in PostgreSQL
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
>= 0
~> 10.0
>= 0

Runtime

 Project Readme

Bithex Build Status Gem Version

Store hex strings as PostgreSQL bit strings to reduce column size 2x.

Installation

Add this line to your application's Gemfile:

gem 'bithex'

And then execute:

$ bundle

Or install it yourself as:

$ gem install bithex

Usage

Create column

create_table :uploads do |t|
  t.column :digest, "bit(160)" # For SHA1 limit is 160, for MD5 limit is 128
end

Define bithex attributes

class Upload < ActiveRecord::Base
  bithex :digest

  # if you have multiple attributes to store as bit string
  # bithex :foo, :bar, :baz
end

Treat you bithex attribute as usual string, but remember: string length is hardcoded by limit of bit column (40 for SHA1, 32 for MD5)

upload = Upload.new
upload.digest = Digest::SHA1.hexdigest('foo bar baz') # c7567e8b39e2428e38bf9c9226ac68de4c67dc39
upload.save

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/sharshenov/bithex.

License

The gem is available as open source under the terms of the MIT License.