项目作者: sharshenov

项目描述 :
[bɪtheks] Store hex strings as bit strings in PostgreSQL.
高级语言: Ruby
项目地址: git://github.com/sharshenov/bithex.git
创建时间: 2018-12-21T08:34:53Z
项目社区:https://github.com/sharshenov/bithex

开源协议:MIT License

下载


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:

  1. gem 'bithex'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install bithex

Usage

Create column

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

Define bithex attributes

  1. class Upload < ActiveRecord::Base
  2. bithex :digest
  3. # if you have multiple attributes to store as bit string
  4. # bithex :foo, :bar, :baz
  5. 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)

  1. upload = Upload.new
  2. upload.digest = Digest::SHA1.hexdigest('foo bar baz') # c7567e8b39e2428e38bf9c9226ac68de4c67dc39
  3. 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.