Git Product home page Git Product logo

activerecord-postgresql-arrays's Introduction

PostgresArrays

This library adds ability to use PostgreSQL array types with ActiveRecord.

> User.find(:all, :conditions=>['arr @> ?', [1,2,3].pg])
  SELECT * FROM "users" WHERE ('arr' @> E'{"1", "2", "3"}')
> User.find(:all, :conditions=>['arr @> ?', [1,2,3].pg(:integer)])
  SELECT * FROM "users" WHERE (arr @> '{1,2,3}')
> User.find(:all, :conditions=>['arr @> ?', [1,2,3].pg(:float)])
  SELECT * FROM "users" WHERE (arr @> '{1.0,2.0,3.0}')
> u = User.find(1)
  SELECT * FROM "users" WHERE ("users"."id" = 1)
  => #<User id: 1, ..., arr: [1,2]>
> u.arr = [3,4]
> u.save
  UPDATE "users" SET "db_ar" = '{3.0,4.0}' WHERE "id" = 19
> User.find(:all, :conditions=>{:arr=>[3,4].pg})
  SELECT * FROM "users" WHERE ("users"."arr" = E'{"3", "4"}')
> User.find(:all, :conditions=>{:arr=>[3,4].search_any(:float)})
  SELECT * FROM "users" WHERE ("users"."arr" && '{3.0,4.0}')
> User.find(:all, :conditions=>{:arr=>[3,4].search_all(:integer)})
  SELECT * FROM "users" WHERE ("users"."arr" @> '{3,4}')
> User.find(:all, :conditions=>{:arr=>[3,4].search_subarray(:safe)})
  SELECT * FROM "users" WHERE ("users"."arr" <@ '{3,4}')
  
  class U < ActiveRecord::Migration
    def self.up
      create_table :users do |t|
        t.integer_array :int_ar
      end
      add_column :users, :fl_ar, :float_array
    end
  end

Installation

gem install ar_pg_array

Changelog

0.9.13

Since version 0.9.13 ar_pg_array will try to detect arrays changed inplace.
And parsed arrays are now cached in @attributes_cache.
Thanks to Romain Beauxis (https://github.com/toots ) for being insistent about this.

Copyright (c) 2010 Sokolov Yura aka funny_falcon, released under the MIT license

activerecord-postgresql-arrays's People

Contributors

dmitryn avatar funny-falcon avatar jcoleman avatar toots avatar twopoint718 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.