Db_Query Class
This class lets you create and use Db queries.
Item Index
Methods
applyHash
-
$value
-
[$hash='normalize']
-
[$len=self::HASH_LEN]
Calculates hash of the value
Parameters:
-
$value
String -
[$hash='normalize']
String optional -
[$len=self::HASH_LEN]
Integer optional
Returns:
hashed
-
$value
-
[$hash=null]
Calculate hash of the value
Parameters:
-
$value
String -
[$hash=null]
String optionalHash is one of 'md5' or 'normalize' optionally followed by '%' and number
Returns:
map_shard
-
$a
Make partition from array of points
Parameters:
-
$a
Array
Returns:
shard
-
[$upcoming=null]
-
[$criteria=null]
Analyzes the query's criteria and decides where to execute the query. 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:
-
[$upcoming=null]
Array optionalTemporary config to use in sharding. Used during shard split process only
-
[$criteria=null]
Array optionalOverrides the sharding criteria for the query. Rarely used unless testing what shards the query would be executed on.
Returns:
Returns an array of ($shardName => $query) pairs, where $shardName can be the name of a shard, '' for just the main shard, or "*" to have the query run on all the shards.
shard_internal
-
$index
-
$hashed
does a depth first search and returns the array of shardname => $query pairs corresponding to which shards are affected
Parameters:
-
$index
Array -
$hashed
String
Returns:
slice_partitions
-
$partition
-
$j
-
$hashed
-
[$adjust=false]
Narrows the partition list according to hashes
Parameters:
-
$partition
Array -
$j
IntegerCurrently processed hashed array member
-
$hashed
Array -
[$adjust=false]
Boolean optional
Returns:
Properties
$cache
Array
Class cache
$expression
String
The expression as a string
$mapping
Array
private
Actual points mapping depending if partition is plain or associative array
$parameters
Array
protected
The parameters to bind with the expression
HASH_LEN
Integer
final
Default length of the hash used for sharding
Default: 7
TYPE_DELETE
Integer
final
Delete query
TYPE_INSERT
Integer
final
Insert query
TYPE_RAW
Integer
final
Raw query
TYPE_ROLLBACK
Integer
final
Rollback query
TYPE_SELECT
Integer
final
Select query
TYPE_UPDATE
Integer
final
Update query