Show:

Db.Query Class

Module: Db

Database query class

Constructor

Db.Query

(
  • db
  • type
  • [clauses={}]
  • [bind={}]
)

Parameters:

Methods

applyHash

(
  • value
  • hash
  • len
)
String private

Parameters:

Returns:

copy

() Db.Query

make a copy of all the sub-objects, including the clauses, parameters, etc.

Returns:

copy

() Db.Query

Used to determine if there is a shardIndex to be used for this type of class

Returns:

shard

(
  • [index={}]
)
Object

Calculates which shards the query should be issued to, based on those "WHERE" criteria that were specified in a structured way. Used mostly by .execute(), but you can call it too, to see how a query would be executed. Here is sample shards config:

NOTE: "fields" shall be an object with keys as fields names and values containing hash definition in the format "type%length" where type is one of 'md5' or 'normalize' and length is hash length hash definition can be empty string or false. In such case 'md5%7' is used

NOTE: "partition" can be an array. In such case shards shall be named after partition points

"Streams": {
    "prefix": "streams_",
    "dsn": "mysql:host=127.0.0.1;dbname=DBNAME",
    "username": "USER",
    "password": "PASSWORD",
    "driver_options": {
        "3": 2
    },
    "shards": {
        "alpha": {
            "prefix": "alpha_",
            "dsn": "mysql:host=127.0.0.1;dbname=SHARDDBNAME",
            "username": "USER",
            "password": "PASSWORD",
            "driver_options": {
                "3": 2
            }
        },
        "betta": {
            "prefix": "betta_",
            "dsn": "mysql:host=127.0.0.1;dbname=SHARDDBNAME",
            "username": "USER",
            "password": "PASSWORD",
            "driver_options": {
                "3": 2
            }
        },
        "gamma": {
            "prefix": "gamma_",
            "dsn": "mysql:host=127.0.0.1;dbname=SHARDDBNAME",
            "username": "USER",
            "password": "PASSWORD",
            "driver_options": {
                "3": 2
            }
        },
        "delta": {
            "prefix": "delta_",
            "dsn": "mysql:host=127.0.0.1;dbname=SHARDDBNAME",
            "username": "USER",
            "password": "PASSWORD",
            "driver_options": {
                "3": 2
            }
        }
    },
    "indexes": {
        "Stream": {
            "fields": {"publisherId": "md5", "name": "normalize"},
            "partition": {
                "0000000.       ": "alpha",
                "0000000.sample_": "betta",
                "4000000.       ": "gamma",
                "4000000.sample_": "delta",
                "8000000.       ": "alpha",
                "8000000.sample_": "betta",
                "c000000.       ": "gamma",
                "c000000.sample_": "delta"
            }
        }
    }
}

Parameters:

  • [index={}] Object optional

    Used internally to override configuration setting for sharding

Returns:

Object:

Returns a hash of shardName => query pairs, where shardName can be the name of a shard, or "*" to have the query run on all the shards.

Properties

TYPE_DELETE

Integer final

Delete query

Default: 5

TYPE_INSERT

Integer final

Insert query

Default: 3

TYPE_RAW

Integer final

Raw query

Default: 1

TYPE_ROLLBACK

Integer final

Rollback query

Default: 6

TYPE_SELECT

Integer final

Select query

Default: 2

TYPE_UPDATE

Integer final

Update query

Default: 4