File: pg_inet_ops.rb [sequel-4.26.0 Documentation]

Last Modified
  2015-09-28 18:31:14 +0000
Requires
  - ipaddr

## Description

The pg_inet_ops extension adds support to Sequel's DSL to make it easier to call PostgreSQL inet functions and operators.

To load the extension:

    Sequel.extension :pg_inet_ops

The most common usage is passing an expression to Sequel.pg_inet_op:

    r = Sequel.pg_inet_op(:inet)

Also, on most Sequel expression objects, you can call the pg_inet method:

    r = Sequel.expr(:ip).pg_inet

If you have loaded the core_extensions extension, or you have loaded the core_refinements extension and have activated refinements for the file, you can also use Symbol#pg_inet:

    r = :inet.pg_inet

This creates a Sequel::Postgres::InetOp object that can be used for easier querying:

    ~r                                 # ~inet
    r & other                          # inet & other
    r | other                          # inet | other
    r << :other                        # inet << other
    r >> :other                        # inet >> other

    r.contained_by(:other)             # inet << other
    r.contained_by_or_equals(:other)   # inet <<= other
    r.contains(:other)                 # inet >> other
    r.contains_or_equals(:other)       # inet >>= other
    r.contains_or_contained_by(:other) # inet && other

    r.abbrev           # abbrev(inet)
    r.broadcast        # broadcast(inet)
    r.family           # family(inet)
    r.host             # host(inet)
    r.hostmask         # hostmask(inet)
    r.masklen          # masklen(inet)
    r.netmask          # netmask(inet)
    r.network          # network(inet)
    r.set_masklen(16)  # set_masklen(inet, 16)
    r.text             # text(inet)

If a String or IPAddr instance is passed to Sequel.pg_inet_op, it will automatically be cast to `inet`. To treat the object as a `cidr`, you must cast it before passing it to Sequel.pg_inet_op:

    r = Sequel.pg_inet_op(Sequel.cast('1.2.3.4', :cidr))

See the PostgreSQL network function and operator documentation for more details on what these functions and operators do.