├── README.md ├── bootstrap ├── css │ ├── bootstrap-theme.css │ ├── bootstrap-theme.css.map │ ├── bootstrap-theme.min.css │ ├── bootstrap.css │ ├── bootstrap.css.map │ └── bootstrap.min.css ├── dashboard.css ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ ├── glyphicons-halflings-regular.woff │ └── glyphicons-halflings-regular.woff2 ├── jquery.min.js └── js │ ├── bootstrap.js │ ├── bootstrap.min.js │ └── npm.js ├── config.php ├── index.php ├── rdb2 ├── connection.php ├── datum.php ├── function.php ├── global.php ├── misc.php ├── pb4php_pb_proto_ql2.php ├── ql2.proto ├── queries.php ├── queries │ ├── aggregations.php │ ├── control.php │ ├── dates.php │ ├── dbs.php │ ├── geo.php │ ├── index.php │ ├── joins.php │ ├── manipulation.php │ ├── math.php │ ├── misc.php │ ├── selecting.php │ ├── tables.php │ ├── transformations.php │ └── writing.php ├── rdb.php ├── util.php └── version.php ├── safereval ├── class.safereval.php └── config.safereval.php └── src ├── check_json.php ├── connect_db.php ├── databases.php ├── doc.php ├── docs.php ├── query.php └── tables.php /README.md: -------------------------------------------------------------------------------- 1 | # phpReAdmin 0.3.1 2 | 3 | ##PHP RethinkDB Admin## 4 | phpMyAdmin for Rethinkdb 5 | 6 | ###This project can:### 7 | - Create/Drop Rethinkdb Databases 8 | - Create/Rename/Drop Rethinkdb Tables 9 | - Create/Update/Delete Rethinkdb Docs (realtime json validation check!) 10 | - Execute Rethinkdb php Querys (with query history!) 11 | 12 | ###Uses:### 13 | - Bootstrap (design) 14 | - PHP-RQL https://github.com/danielmewes/php-rql by Daniel Mewes 15 | 16 | 17 | ###License: FREE!### 18 | 19 | ###Creator:### 20 | billbarsch@gmail.com 21 | 22 | ###TODO### 23 | Find some way to convert json datetime values to RethinkDB datetime format and vice versa. 24 | 25 | php Re Admin 1

26 | php Re Admin 2

27 | php Re Admin 3

28 | php Re Admin 4

29 | php Re Admin 5

30 | -------------------------------------------------------------------------------- /bootstrap/css/bootstrap-theme.min.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap v3.3.2 (http://getbootstrap.com) 3 | * Copyright 2011-2015 Twitter, Inc. 4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) 5 | */.btn-danger,.btn-default,.btn-info,.btn-primary,.btn-success,.btn-warning{text-shadow:0 -1px 0 rgba(0,0,0,.2);-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.15),0 1px 1px rgba(0,0,0,.075);box-shadow:inset 0 1px 0 rgba(255,255,255,.15),0 1px 1px rgba(0,0,0,.075)}.btn-danger.active,.btn-danger:active,.btn-default.active,.btn-default:active,.btn-info.active,.btn-info:active,.btn-primary.active,.btn-primary:active,.btn-success.active,.btn-success:active,.btn-warning.active,.btn-warning:active{-webkit-box-shadow:inset 0 3px 5px rgba(0,0,0,.125);box-shadow:inset 0 3px 5px rgba(0,0,0,.125)}.btn-danger .badge,.btn-default .badge,.btn-info .badge,.btn-primary .badge,.btn-success .badge,.btn-warning .badge{text-shadow:none}.btn.active,.btn:active{background-image:none}.btn-default{text-shadow:0 1px 0 #fff;background-image:-webkit-linear-gradient(top,#fff 0,#e0e0e0 100%);background-image:-o-linear-gradient(top,#fff 0,#e0e0e0 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#fff),to(#e0e0e0));background-image:linear-gradient(to bottom,#fff 0,#e0e0e0 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffe0e0e0', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#dbdbdb;border-color:#ccc}.btn-default:focus,.btn-default:hover{background-color:#e0e0e0;background-position:0 -15px}.btn-default.active,.btn-default:active{background-color:#e0e0e0;border-color:#dbdbdb}.btn-default.disabled,.btn-default:disabled,.btn-default[disabled]{background-color:#e0e0e0;background-image:none}.btn-primary{background-image:-webkit-linear-gradient(top,#337ab7 0,#265a88 100%);background-image:-o-linear-gradient(top,#337ab7 0,#265a88 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#265a88));background-image:linear-gradient(to bottom,#337ab7 0,#265a88 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff265a88', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#245580}.btn-primary:focus,.btn-primary:hover{background-color:#265a88;background-position:0 -15px}.btn-primary.active,.btn-primary:active{background-color:#265a88;border-color:#245580}.btn-primary.disabled,.btn-primary:disabled,.btn-primary[disabled]{background-color:#265a88;background-image:none}.btn-success{background-image:-webkit-linear-gradient(top,#5cb85c 0,#419641 100%);background-image:-o-linear-gradient(top,#5cb85c 0,#419641 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#5cb85c),to(#419641));background-image:linear-gradient(to bottom,#5cb85c 0,#419641 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5cb85c', endColorstr='#ff419641', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#3e8f3e}.btn-success:focus,.btn-success:hover{background-color:#419641;background-position:0 -15px}.btn-success.active,.btn-success:active{background-color:#419641;border-color:#3e8f3e}.btn-success.disabled,.btn-success:disabled,.btn-success[disabled]{background-color:#419641;background-image:none}.btn-info{background-image:-webkit-linear-gradient(top,#5bc0de 0,#2aabd2 100%);background-image:-o-linear-gradient(top,#5bc0de 0,#2aabd2 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#5bc0de),to(#2aabd2));background-image:linear-gradient(to bottom,#5bc0de 0,#2aabd2 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de', endColorstr='#ff2aabd2', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#28a4c9}.btn-info:focus,.btn-info:hover{background-color:#2aabd2;background-position:0 -15px}.btn-info.active,.btn-info:active{background-color:#2aabd2;border-color:#28a4c9}.btn-info.disabled,.btn-info:disabled,.btn-info[disabled]{background-color:#2aabd2;background-image:none}.btn-warning{background-image:-webkit-linear-gradient(top,#f0ad4e 0,#eb9316 100%);background-image:-o-linear-gradient(top,#f0ad4e 0,#eb9316 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f0ad4e),to(#eb9316));background-image:linear-gradient(to bottom,#f0ad4e 0,#eb9316 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff0ad4e', endColorstr='#ffeb9316', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#e38d13}.btn-warning:focus,.btn-warning:hover{background-color:#eb9316;background-position:0 -15px}.btn-warning.active,.btn-warning:active{background-color:#eb9316;border-color:#e38d13}.btn-warning.disabled,.btn-warning:disabled,.btn-warning[disabled]{background-color:#eb9316;background-image:none}.btn-danger{background-image:-webkit-linear-gradient(top,#d9534f 0,#c12e2a 100%);background-image:-o-linear-gradient(top,#d9534f 0,#c12e2a 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#d9534f),to(#c12e2a));background-image:linear-gradient(to bottom,#d9534f 0,#c12e2a 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9534f', endColorstr='#ffc12e2a', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-color:#b92c28}.btn-danger:focus,.btn-danger:hover{background-color:#c12e2a;background-position:0 -15px}.btn-danger.active,.btn-danger:active{background-color:#c12e2a;border-color:#b92c28}.btn-danger.disabled,.btn-danger:disabled,.btn-danger[disabled]{background-color:#c12e2a;background-image:none}.img-thumbnail,.thumbnail{-webkit-box-shadow:0 1px 2px rgba(0,0,0,.075);box-shadow:0 1px 2px rgba(0,0,0,.075)}.dropdown-menu>li>a:focus,.dropdown-menu>li>a:hover{background-color:#e8e8e8;background-image:-webkit-linear-gradient(top,#f5f5f5 0,#e8e8e8 100%);background-image:-o-linear-gradient(top,#f5f5f5 0,#e8e8e8 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f5f5f5),to(#e8e8e8));background-image:linear-gradient(to bottom,#f5f5f5 0,#e8e8e8 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5', endColorstr='#ffe8e8e8', GradientType=0);background-repeat:repeat-x}.dropdown-menu>.active>a,.dropdown-menu>.active>a:focus,.dropdown-menu>.active>a:hover{background-color:#2e6da4;background-image:-webkit-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-o-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#2e6da4));background-image:linear-gradient(to bottom,#337ab7 0,#2e6da4 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff2e6da4', GradientType=0);background-repeat:repeat-x}.navbar-default{background-image:-webkit-linear-gradient(top,#fff 0,#f8f8f8 100%);background-image:-o-linear-gradient(top,#fff 0,#f8f8f8 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#fff),to(#f8f8f8));background-image:linear-gradient(to bottom,#fff 0,#f8f8f8 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#fff8f8f8', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x;border-radius:4px;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.15),0 1px 5px rgba(0,0,0,.075);box-shadow:inset 0 1px 0 rgba(255,255,255,.15),0 1px 5px rgba(0,0,0,.075)}.navbar-default .navbar-nav>.active>a,.navbar-default .navbar-nav>.open>a{background-image:-webkit-linear-gradient(top,#dbdbdb 0,#e2e2e2 100%);background-image:-o-linear-gradient(top,#dbdbdb 0,#e2e2e2 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#dbdbdb),to(#e2e2e2));background-image:linear-gradient(to bottom,#dbdbdb 0,#e2e2e2 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffdbdbdb', endColorstr='#ffe2e2e2', GradientType=0);background-repeat:repeat-x;-webkit-box-shadow:inset 0 3px 9px rgba(0,0,0,.075);box-shadow:inset 0 3px 9px rgba(0,0,0,.075)}.navbar-brand,.navbar-nav>li>a{text-shadow:0 1px 0 rgba(255,255,255,.25)}.navbar-inverse{background-image:-webkit-linear-gradient(top,#3c3c3c 0,#222 100%);background-image:-o-linear-gradient(top,#3c3c3c 0,#222 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#3c3c3c),to(#222));background-image:linear-gradient(to bottom,#3c3c3c 0,#222 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff3c3c3c', endColorstr='#ff222222', GradientType=0);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-repeat:repeat-x}.navbar-inverse .navbar-nav>.active>a,.navbar-inverse .navbar-nav>.open>a{background-image:-webkit-linear-gradient(top,#080808 0,#0f0f0f 100%);background-image:-o-linear-gradient(top,#080808 0,#0f0f0f 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#080808),to(#0f0f0f));background-image:linear-gradient(to bottom,#080808 0,#0f0f0f 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff080808', endColorstr='#ff0f0f0f', GradientType=0);background-repeat:repeat-x;-webkit-box-shadow:inset 0 3px 9px rgba(0,0,0,.25);box-shadow:inset 0 3px 9px rgba(0,0,0,.25)}.navbar-inverse .navbar-brand,.navbar-inverse .navbar-nav>li>a{text-shadow:0 -1px 0 rgba(0,0,0,.25)}.navbar-fixed-bottom,.navbar-fixed-top,.navbar-static-top{border-radius:0}@media (max-width:767px){.navbar .navbar-nav .open .dropdown-menu>.active>a,.navbar .navbar-nav .open .dropdown-menu>.active>a:focus,.navbar .navbar-nav .open .dropdown-menu>.active>a:hover{color:#fff;background-image:-webkit-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-o-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#2e6da4));background-image:linear-gradient(to bottom,#337ab7 0,#2e6da4 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff2e6da4', GradientType=0);background-repeat:repeat-x}}.alert{text-shadow:0 1px 0 rgba(255,255,255,.2);-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.25),0 1px 2px rgba(0,0,0,.05);box-shadow:inset 0 1px 0 rgba(255,255,255,.25),0 1px 2px rgba(0,0,0,.05)}.alert-success{background-image:-webkit-linear-gradient(top,#dff0d8 0,#c8e5bc 100%);background-image:-o-linear-gradient(top,#dff0d8 0,#c8e5bc 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#dff0d8),to(#c8e5bc));background-image:linear-gradient(to bottom,#dff0d8 0,#c8e5bc 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffdff0d8', endColorstr='#ffc8e5bc', GradientType=0);background-repeat:repeat-x;border-color:#b2dba1}.alert-info{background-image:-webkit-linear-gradient(top,#d9edf7 0,#b9def0 100%);background-image:-o-linear-gradient(top,#d9edf7 0,#b9def0 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#d9edf7),to(#b9def0));background-image:linear-gradient(to bottom,#d9edf7 0,#b9def0 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9edf7', endColorstr='#ffb9def0', GradientType=0);background-repeat:repeat-x;border-color:#9acfea}.alert-warning{background-image:-webkit-linear-gradient(top,#fcf8e3 0,#f8efc0 100%);background-image:-o-linear-gradient(top,#fcf8e3 0,#f8efc0 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#fcf8e3),to(#f8efc0));background-image:linear-gradient(to bottom,#fcf8e3 0,#f8efc0 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffcf8e3', endColorstr='#fff8efc0', GradientType=0);background-repeat:repeat-x;border-color:#f5e79e}.alert-danger{background-image:-webkit-linear-gradient(top,#f2dede 0,#e7c3c3 100%);background-image:-o-linear-gradient(top,#f2dede 0,#e7c3c3 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f2dede),to(#e7c3c3));background-image:linear-gradient(to bottom,#f2dede 0,#e7c3c3 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff2dede', endColorstr='#ffe7c3c3', GradientType=0);background-repeat:repeat-x;border-color:#dca7a7}.progress{background-image:-webkit-linear-gradient(top,#ebebeb 0,#f5f5f5 100%);background-image:-o-linear-gradient(top,#ebebeb 0,#f5f5f5 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#ebebeb),to(#f5f5f5));background-image:linear-gradient(to bottom,#ebebeb 0,#f5f5f5 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffebebeb', endColorstr='#fff5f5f5', GradientType=0);background-repeat:repeat-x}.progress-bar{background-image:-webkit-linear-gradient(top,#337ab7 0,#286090 100%);background-image:-o-linear-gradient(top,#337ab7 0,#286090 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#286090));background-image:linear-gradient(to bottom,#337ab7 0,#286090 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff286090', GradientType=0);background-repeat:repeat-x}.progress-bar-success{background-image:-webkit-linear-gradient(top,#5cb85c 0,#449d44 100%);background-image:-o-linear-gradient(top,#5cb85c 0,#449d44 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#5cb85c),to(#449d44));background-image:linear-gradient(to bottom,#5cb85c 0,#449d44 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5cb85c', endColorstr='#ff449d44', GradientType=0);background-repeat:repeat-x}.progress-bar-info{background-image:-webkit-linear-gradient(top,#5bc0de 0,#31b0d5 100%);background-image:-o-linear-gradient(top,#5bc0de 0,#31b0d5 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#5bc0de),to(#31b0d5));background-image:linear-gradient(to bottom,#5bc0de 0,#31b0d5 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de', endColorstr='#ff31b0d5', GradientType=0);background-repeat:repeat-x}.progress-bar-warning{background-image:-webkit-linear-gradient(top,#f0ad4e 0,#ec971f 100%);background-image:-o-linear-gradient(top,#f0ad4e 0,#ec971f 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f0ad4e),to(#ec971f));background-image:linear-gradient(to bottom,#f0ad4e 0,#ec971f 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff0ad4e', endColorstr='#ffec971f', GradientType=0);background-repeat:repeat-x}.progress-bar-danger{background-image:-webkit-linear-gradient(top,#d9534f 0,#c9302c 100%);background-image:-o-linear-gradient(top,#d9534f 0,#c9302c 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#d9534f),to(#c9302c));background-image:linear-gradient(to bottom,#d9534f 0,#c9302c 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9534f', endColorstr='#ffc9302c', GradientType=0);background-repeat:repeat-x}.progress-bar-striped{background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent)}.list-group{border-radius:4px;-webkit-box-shadow:0 1px 2px rgba(0,0,0,.075);box-shadow:0 1px 2px rgba(0,0,0,.075)}.list-group-item.active,.list-group-item.active:focus,.list-group-item.active:hover{text-shadow:0 -1px 0 #286090;background-image:-webkit-linear-gradient(top,#337ab7 0,#2b669a 100%);background-image:-o-linear-gradient(top,#337ab7 0,#2b669a 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#2b669a));background-image:linear-gradient(to bottom,#337ab7 0,#2b669a 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff2b669a', GradientType=0);background-repeat:repeat-x;border-color:#2b669a}.list-group-item.active .badge,.list-group-item.active:focus .badge,.list-group-item.active:hover .badge{text-shadow:none}.panel{-webkit-box-shadow:0 1px 2px rgba(0,0,0,.05);box-shadow:0 1px 2px rgba(0,0,0,.05)}.panel-default>.panel-heading{background-image:-webkit-linear-gradient(top,#f5f5f5 0,#e8e8e8 100%);background-image:-o-linear-gradient(top,#f5f5f5 0,#e8e8e8 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f5f5f5),to(#e8e8e8));background-image:linear-gradient(to bottom,#f5f5f5 0,#e8e8e8 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5', endColorstr='#ffe8e8e8', GradientType=0);background-repeat:repeat-x}.panel-primary>.panel-heading{background-image:-webkit-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-o-linear-gradient(top,#337ab7 0,#2e6da4 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#337ab7),to(#2e6da4));background-image:linear-gradient(to bottom,#337ab7 0,#2e6da4 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff337ab7', endColorstr='#ff2e6da4', GradientType=0);background-repeat:repeat-x}.panel-success>.panel-heading{background-image:-webkit-linear-gradient(top,#dff0d8 0,#d0e9c6 100%);background-image:-o-linear-gradient(top,#dff0d8 0,#d0e9c6 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#dff0d8),to(#d0e9c6));background-image:linear-gradient(to bottom,#dff0d8 0,#d0e9c6 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffdff0d8', endColorstr='#ffd0e9c6', GradientType=0);background-repeat:repeat-x}.panel-info>.panel-heading{background-image:-webkit-linear-gradient(top,#d9edf7 0,#c4e3f3 100%);background-image:-o-linear-gradient(top,#d9edf7 0,#c4e3f3 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#d9edf7),to(#c4e3f3));background-image:linear-gradient(to bottom,#d9edf7 0,#c4e3f3 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9edf7', endColorstr='#ffc4e3f3', GradientType=0);background-repeat:repeat-x}.panel-warning>.panel-heading{background-image:-webkit-linear-gradient(top,#fcf8e3 0,#faf2cc 100%);background-image:-o-linear-gradient(top,#fcf8e3 0,#faf2cc 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#fcf8e3),to(#faf2cc));background-image:linear-gradient(to bottom,#fcf8e3 0,#faf2cc 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffcf8e3', endColorstr='#fffaf2cc', GradientType=0);background-repeat:repeat-x}.panel-danger>.panel-heading{background-image:-webkit-linear-gradient(top,#f2dede 0,#ebcccc 100%);background-image:-o-linear-gradient(top,#f2dede 0,#ebcccc 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#f2dede),to(#ebcccc));background-image:linear-gradient(to bottom,#f2dede 0,#ebcccc 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff2dede', endColorstr='#ffebcccc', GradientType=0);background-repeat:repeat-x}.well{background-image:-webkit-linear-gradient(top,#e8e8e8 0,#f5f5f5 100%);background-image:-o-linear-gradient(top,#e8e8e8 0,#f5f5f5 100%);background-image:-webkit-gradient(linear,left top,left bottom,from(#e8e8e8),to(#f5f5f5));background-image:linear-gradient(to bottom,#e8e8e8 0,#f5f5f5 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffe8e8e8', endColorstr='#fff5f5f5', GradientType=0);background-repeat:repeat-x;border-color:#dcdcdc;-webkit-box-shadow:inset 0 1px 3px rgba(0,0,0,.05),0 1px 0 rgba(255,255,255,.1);box-shadow:inset 0 1px 3px rgba(0,0,0,.05),0 1px 0 rgba(255,255,255,.1)} -------------------------------------------------------------------------------- /bootstrap/dashboard.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Base structure 3 | */ 4 | 5 | /* Move down content because we have a fixed navbar that is 50px tall */ 6 | body { 7 | padding-top: 50px; 8 | } 9 | 10 | 11 | /* 12 | * Global add-ons 13 | */ 14 | 15 | .sub-header { 16 | padding-bottom: 10px; 17 | border-bottom: 1px solid #eee; 18 | } 19 | 20 | /* 21 | * Top navigation 22 | * Hide default border to remove 1px line. 23 | */ 24 | .navbar-fixed-top { 25 | border: 0; 26 | } 27 | 28 | /* 29 | * Sidebar 30 | */ 31 | 32 | /* Hide for mobile, show later */ 33 | .sidebar { 34 | display: none; 35 | } 36 | @media (min-width: 768px) { 37 | .sidebar { 38 | position: fixed; 39 | top: 51px; 40 | bottom: 0; 41 | left: 0; 42 | z-index: 1000; 43 | display: block; 44 | padding: 20px; 45 | overflow-x: hidden; 46 | overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */ 47 | background-color: #f5f5f5; 48 | border-right: 1px solid #eee; 49 | } 50 | } 51 | 52 | /* Sidebar navigation */ 53 | .nav-sidebar { 54 | margin-right: -21px; /* 20px padding + 1px border */ 55 | margin-bottom: 20px; 56 | margin-left: -20px; 57 | } 58 | .nav-sidebar > li > a { 59 | padding-right: 20px; 60 | padding-left: 20px; 61 | } 62 | .nav-sidebar > .active > a, 63 | .nav-sidebar > .active > a:hover, 64 | .nav-sidebar > .active > a:focus { 65 | color: #fff; 66 | background-color: #428bca; 67 | } 68 | 69 | 70 | /* 71 | * Main content 72 | */ 73 | 74 | .main { 75 | padding: 20px; 76 | } 77 | @media (min-width: 768px) { 78 | .main { 79 | padding-right: 40px; 80 | padding-left: 40px; 81 | } 82 | } 83 | .main .page-header { 84 | margin-top: 0; 85 | } 86 | 87 | 88 | /* 89 | * Placeholder dashboard ideas 90 | */ 91 | 92 | .placeholders { 93 | margin-bottom: 30px; 94 | text-align: center; 95 | } 96 | .placeholders h4 { 97 | margin-bottom: 0; 98 | } 99 | .placeholder { 100 | margin-bottom: 20px; 101 | } 102 | .placeholder img { 103 | display: inline-block; 104 | border-radius: 50%; 105 | } 106 | -------------------------------------------------------------------------------- /bootstrap/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/billbarsch/phpReAdmin/e04c795545b8144dee1f8fb31f9d6cb4770d20ce/bootstrap/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /bootstrap/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/billbarsch/phpReAdmin/e04c795545b8144dee1f8fb31f9d6cb4770d20ce/bootstrap/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /bootstrap/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/billbarsch/phpReAdmin/e04c795545b8144dee1f8fb31f9d6cb4770d20ce/bootstrap/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /bootstrap/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/billbarsch/phpReAdmin/e04c795545b8144dee1f8fb31f9d6cb4770d20ce/bootstrap/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /bootstrap/js/npm.js: -------------------------------------------------------------------------------- 1 | // This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment. 2 | require('../../js/transition.js') 3 | require('../../js/alert.js') 4 | require('../../js/button.js') 5 | require('../../js/carousel.js') 6 | require('../../js/collapse.js') 7 | require('../../js/dropdown.js') 8 | require('../../js/modal.js') 9 | require('../../js/tooltip.js') 10 | require('../../js/popover.js') 11 | require('../../js/scrollspy.js') 12 | require('../../js/tab.js') 13 | require('../../js/affix.js') -------------------------------------------------------------------------------- /config.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 27 | 28 | 29 | 30 | 31 | phpReAdmin 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 70 |
71 |
72 | 75 | 102 | 105 |
106 | 144 |
145 |
146 |
147 | 148 | 149 | -------------------------------------------------------------------------------- /rdb2/connection.php: -------------------------------------------------------------------------------- 1 | host = $host; 14 | $this->port = $port; 15 | if (!isset($apiKey)) 16 | $apiKey = ""; 17 | $this->apiKey = $apiKey; 18 | $this->timeout = null; 19 | 20 | if (isset($db)) 21 | $this->useDb($db); 22 | if (isset($timeout)) 23 | $this->setTimeout($timeout); 24 | 25 | $this->connect(); 26 | } 27 | 28 | public function __destruct() { 29 | if ($this->isOpen()) 30 | $this->close(false); 31 | } 32 | 33 | public function close($noreplyWait = true) { 34 | if (!$this->isOpen()) throw new RqlDriverError("Not connected."); 35 | 36 | if ($noreplyWait) { 37 | $this->noreplyWait(); 38 | } 39 | 40 | fclose($this->socket); 41 | $this->socket = null; 42 | $this->activeTokens = null; 43 | } 44 | 45 | public function reconnect($noreplyWait = true) { 46 | if ($this->isOpen()) 47 | $this->close($noreplyWait); 48 | $this->connect(); 49 | } 50 | 51 | public function isOpen() { 52 | return isset($this->socket); 53 | } 54 | 55 | public function useDb($dbName) { 56 | if (!is_string($dbName)) throw new RqlDriverError("Database must be a string."); 57 | $this->defaultDb = new Db($dbName); 58 | } 59 | 60 | public function setTimeout($timeout) { 61 | if (!is_numeric($timeout)) throw new RqlDriverError("Timeout must be a number."); 62 | $this->applyTimeout($timeout); 63 | $this->timeout = $timeout; 64 | } 65 | 66 | public function noreplyWait() { 67 | if (!$this->isOpen()) throw new RqlDriverError("Not connected."); 68 | 69 | // Generate a token for the request 70 | $token = $this->generateToken(); 71 | 72 | // Send the request 73 | $jsonQuery = array(pb\Query_QueryType::PB_NOREPLY_WAIT); 74 | $this->sendQuery($token, $jsonQuery); 75 | 76 | // Await the response 77 | $response = $this->receiveResponse($token); 78 | 79 | if ($response['t'] != pb\Response_ResponseType::PB_WAIT_COMPLETE) { 80 | throw new RqlDriverError("Unexpected response type to noreplyWait query."); 81 | } 82 | } 83 | 84 | public function _run(Query $query, $options, &$profile) { 85 | if (isset($options) && !is_array($options)) throw new RqlDriverError("Options must be an array."); 86 | if (!$this->isOpen()) throw new RqlDriverError("Not connected."); 87 | 88 | // Grab PHP-RQL specific options 89 | $toNativeOptions = array(); 90 | foreach (array('binaryFormat', 'timeFormat') as $opt) { 91 | if (isset($options) && isset($options[$opt])) { 92 | $toNativeOptions[$opt] = $options[$opt]; 93 | unset($options[$opt]); 94 | } 95 | } 96 | 97 | // Generate a token for the request 98 | $token = $this->generateToken(); 99 | 100 | // Send the request 101 | $jsonTerm = $query->_getJSONTerm(); 102 | $globalOptargs = array(); 103 | if (isset($this->defaultDb)) { 104 | $globalOptargs['db'] = $this->defaultDb->_getJSONTerm(); 105 | } 106 | if (isset($options)) { 107 | foreach ($options as $key => $value) { 108 | $globalOptargs[$key] = nativeToDatum($value)->_getJSONTerm(); 109 | } 110 | } 111 | $jsonQuery = array(pb\Query_QueryType::PB_START, $jsonTerm, (Object)$globalOptargs); 112 | $this->sendQuery($token, $jsonQuery); 113 | 114 | if (isset($options) && isset($options['noreply']) && $options['noreply'] === true) { 115 | return null; 116 | } else { 117 | // Await the response 118 | $response = $this->receiveResponse($token, $query); 119 | 120 | if ($response['t'] == pb\Response_ResponseType::PB_SUCCESS_PARTIAL) { 121 | $this->activeTokens[$token] = true; 122 | } 123 | 124 | if (isset($response['p'])) { 125 | $profile = decodedJSONToDatum($response['p'])->toNative($toNativeOptions); 126 | } 127 | 128 | if ($response['t'] == pb\Response_ResponseType::PB_SUCCESS_ATOM) { 129 | return $this->createDatumFromResponse($response)->toNative($toNativeOptions); 130 | } else { 131 | return $this->createCursorFromResponse($response, $token, $response['n'], $toNativeOptions); 132 | } 133 | } 134 | } 135 | 136 | public function _continueQuery($token) { 137 | if (!$this->isOpen()) throw new RqlDriverError("Not connected."); 138 | if (!is_numeric($token)) throw new RqlDriverError("Token must be a number."); 139 | 140 | // Send the request 141 | $jsonQuery = array(pb\Query_QueryType::PB_CONTINUE); 142 | $this->sendQuery($token, $jsonQuery); 143 | 144 | // Await the response 145 | $response = $this->receiveResponse($token); 146 | 147 | if ($response['t'] != pb\Response_ResponseType::PB_SUCCESS_PARTIAL) { 148 | unset($this->activeTokens[$token]); 149 | } 150 | 151 | return $response; 152 | } 153 | 154 | public function _stopQuery($token) { 155 | if (!$this->isOpen()) throw new RqlDriverError("Not connected."); 156 | if (!is_numeric($token)) throw new RqlDriverError("Token must be a number."); 157 | 158 | // Send the request 159 | $jsonQuery = array(pb\Query_QueryType::PB_STOP); 160 | $this->sendQuery($token, $jsonQuery); 161 | 162 | // Await the response (but don't check for errors. the stop response doesn't even have a type) 163 | $response = $this->receiveResponse($token, null, true); 164 | 165 | unset($this->activeTokens[$token]); 166 | 167 | return $response; 168 | } 169 | 170 | private function generateToken() { 171 | $tries = 0; 172 | $maxToken = 1 << 30; 173 | do { 174 | $token = \rand(0, $maxToken); 175 | $haveCollision = isset($this->activeTokens[$token]); 176 | } while ($haveCollision && $tries++ < 1024); 177 | if ($haveCollision) { 178 | throw new RqlDriverError("Unable to generate a unique token for the query."); 179 | } 180 | return $token; 181 | } 182 | 183 | private function receiveResponse($token, $query = null, $noChecks = false) { 184 | $responseHeader = $this->receiveStr(4 + 8); 185 | $responseHeader = unpack("Vtoken/Vtoken2/Vsize", $responseHeader); 186 | $responseToken = $responseHeader['token']; 187 | if ($responseHeader['token2'] != 0) { 188 | throw new RqlDriverError("Invalid response from server: Invalid token."); 189 | } 190 | $responseSize = $responseHeader['size']; 191 | $responseBuf = $this->receiveStr($responseSize); 192 | 193 | $response = json_decode($responseBuf); 194 | if (json_last_error() != JSON_ERROR_NONE) { 195 | throw new RqlDriverError("Unable to decode JSON response (error code " . json_last_error() . ")"); 196 | } 197 | if (!is_object($response)) { 198 | throw new RqlDriverError("Invalid response from server: Not an object."); 199 | } 200 | $response = (array)$response; 201 | if (!$noChecks) 202 | $this->checkResponse($response, $responseToken, $token, $query); 203 | 204 | return $response; 205 | } 206 | 207 | private function checkResponse($response, $responseToken, $token, $query = null) { 208 | if (!isset($response['t'])) throw new RqlDriverError("Response message has no type."); 209 | 210 | if ($response['t'] == pb\Response_ResponseType::PB_CLIENT_ERROR) { 211 | throw new RqlDriverError("Server says PHP-RQL is buggy: " . $response['r'][0]); 212 | } 213 | 214 | if ($responseToken != $token) { 215 | throw new RqlDriverError("Received wrong token. Response does not match the request. Expected $token, received " . $responseToken); 216 | } 217 | 218 | if ($response['t'] == pb\Response_ResponseType::PB_COMPILE_ERROR) { 219 | $backtrace = null; 220 | if (isset($response['b'])) 221 | $backtrace = Backtrace::_fromJSON($response['b']); 222 | throw new RqlServerError("Compile error: " . $response['r'][0], $query, $backtrace); 223 | } 224 | else if ($response['t'] == pb\Response_ResponseType::PB_RUNTIME_ERROR) { 225 | $backtrace = null; 226 | if (isset($response['b'])) 227 | $backtrace = Backtrace::_fromJSON($response['b']); 228 | throw new RqlServerError("Runtime error: " . $response['r'][0], $query, $backtrace); 229 | } 230 | } 231 | 232 | private function createCursorFromResponse($response, $token, $notes, $toNativeOptions) { 233 | return new Cursor($this, $response, $token, $notes, $toNativeOptions); 234 | } 235 | 236 | private function createDatumFromResponse($response) { 237 | $datum = $response['r'][0]; 238 | return decodedJSONToDatum($datum); 239 | } 240 | 241 | private function sendQuery($token, $json) { 242 | // PHP by default loses some precision when encoding floats, so we temporarily 243 | // bump up the `precision` option to avoid this. 244 | // The 17 assumes IEEE-754 double precision numbers. 245 | // Source: http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html 246 | // "The same argument applied to double precision shows that 17 decimal 247 | // digits are required to recover a double precision number." 248 | $previousPrecision = ini_set("precision", 17); 249 | $request = json_encode($json); 250 | if ($previousPrecision !== false) { 251 | ini_set("precision", $previousPrecision); 252 | } 253 | if ($request === false) throw new RqlDriverError("Failed to encode query as JSON: " . json_last_error()); 254 | 255 | $requestSize = pack("V", strlen($request)); 256 | $binaryToken = pack("V", $token) . pack("V", 0); 257 | $this->sendStr($binaryToken . $requestSize . $request); 258 | } 259 | 260 | private function applyTimeout($timeout) { 261 | if ($this->isOpen()) { 262 | if (!stream_set_timeout($this->socket, $timeout)) { 263 | throw new RqlDriverError("Could not set timeout"); 264 | } 265 | } 266 | } 267 | 268 | private function connect() { 269 | if ($this->isOpen()) throw new RqlDriverError("Already connected"); 270 | 271 | $this->socket = stream_socket_client("tcp://" . $this->host . ":" . $this->port, $errno, $errstr); 272 | if ($errno != 0 || $this->socket === false) { 273 | $this->socket = null; 274 | throw new RqlDriverError("Unable to connect: " . $errstr); 275 | } 276 | if ($this->timeout) { 277 | $this->applyTimeout($this->timeout); 278 | } 279 | 280 | $this->sendHandshake(); 281 | $this->receiveHandshakeResponse(); 282 | } 283 | 284 | private function sendHandshake() { 285 | if (!$this->isOpen()) throw new RqlDriverError("Not connected"); 286 | 287 | $binaryVersion = pack("V", pb\VersionDummy_Version::PB_V0_3); // "V" is little endian, 32 bit unsigned integer 288 | $handshake = $binaryVersion; 289 | 290 | $binaryKeyLength = pack("V", strlen($this->apiKey)); 291 | $handshake .= $binaryKeyLength . $this->apiKey; 292 | 293 | $binaryProtocol = pack("V", pb\VersionDummy_Protocol::PB_JSON); 294 | $handshake .= $binaryProtocol; 295 | 296 | $this->sendStr($handshake); 297 | } 298 | 299 | private function receiveHandshakeResponse() { 300 | if (!$this->isOpen()) throw new RqlDriverError("Not connected"); 301 | 302 | $response = ""; 303 | while (true) { 304 | $ch = stream_get_contents($this->socket, 1); 305 | if ($ch === false || strlen($ch) < 1) { 306 | $this->close(false); 307 | throw new RqlDriverError("Unable to read from socket during handshake. Disconnected."); 308 | } 309 | if ($ch === chr(0)) 310 | break; 311 | else 312 | $response .= $ch; 313 | } 314 | 315 | if ($response != "SUCCESS") { 316 | $this->close(false); 317 | throw new RqlDriverError("Handshake failed: $response Disconnected."); 318 | } 319 | } 320 | 321 | private function sendStr($s) { 322 | $bytesWritten = 0; 323 | while ($bytesWritten < strlen($s)) { 324 | $result = fwrite($this->socket, substr($s, $bytesWritten)); 325 | if ($result === false || $result === 0) { 326 | $metaData = stream_get_meta_data($this->socket); 327 | $this->close(false); 328 | if ($metaData['timed_out']) { 329 | throw new RqlDriverError("Timed out while writing to socket. Disconnected. Call setTimeout(seconds) on the connection to change the timeout."); 330 | } 331 | throw new RqlDriverError("Unable to write to socket. Disconnected."); 332 | } 333 | $bytesWritten += $result; 334 | } 335 | } 336 | 337 | private function receiveStr($length) { 338 | $s = ""; 339 | while (strlen($s) < $length) { 340 | $partialS = stream_get_contents($this->socket, $length - strlen($s)); 341 | if ($partialS === false) { 342 | $metaData = stream_get_meta_data($this->socket); 343 | $this->close(false); 344 | if ($metaData['timed_out']) { 345 | throw new RqlDriverError("Timed out while reading from socket. Disconnected. Call setTimeout(seconds) on the connection to change the timeout."); 346 | } 347 | throw new RqlDriverError("Unable to read from socket. Disconnected."); 348 | } 349 | $s = $s . $partialS; 350 | } 351 | return $s; 352 | } 353 | 354 | 355 | private $socket; 356 | private $host; 357 | private $port; 358 | private $defaultDb; 359 | private $apiKey; 360 | private $activeTokens; 361 | private $timeout; 362 | } 363 | 364 | ?> 365 | -------------------------------------------------------------------------------- /rdb2/datum.php: -------------------------------------------------------------------------------- 1 | $val) { 18 | if (!is_numeric($key) && !is_string($key)) throw new RqlDriverError("Key must be a string."); 19 | if ((is_object($val) && is_subclass_of($val, "\\r\\Query")) && !(is_object($val) && is_subclass_of($val, "\\r\\Datum"))) { 20 | $subDatum = $val; 21 | $mustUseMakeTerm = true; 22 | } else { 23 | $subDatum = nativeToDatum($val); 24 | if (!is_subclass_of($subDatum, "\\r\\Datum")) 25 | $mustUseMakeTerm = true; 26 | } 27 | if (is_string($key)) { 28 | $hasNonNumericKey = true; 29 | $datumArray[$key] = $subDatum; 30 | } else { 31 | $datumArray[$key] = $subDatum; 32 | } 33 | } 34 | 35 | // Note: In the case of $hasNonNumericKey === false, we cannot 36 | // know if we should convert to an array or an object. We 37 | // currently assume array, but this is not overly clean. 38 | // Of course the user always has the option to wrap data 39 | // into a Datum manually. 40 | // We use this behavior because it is consistent to json_encode, 41 | // which we sometimes use as a transparent replacement for 42 | // nativeToDatum(). 43 | if ($hasNonNumericKey) { 44 | if ($mustUseMakeTerm) { 45 | return new MakeObject($datumArray); 46 | } else { 47 | return new ObjectDatum($datumArray); 48 | } 49 | } else { 50 | if ($mustUseMakeTerm) { 51 | return new MakeArray($datumArray); 52 | } else { 53 | return new ArrayDatum($datumArray); 54 | } 55 | } 56 | } 57 | else if (is_null($v)) { 58 | return new NullDatum(); 59 | } 60 | else if (is_bool($v)) { 61 | return new BoolDatum($v); 62 | } 63 | else if (is_int($v) || is_float($v)) { 64 | return new NumberDatum($v); 65 | } 66 | else if (is_string($v)) { 67 | return new StringDatum($v); 68 | } else if (is_object($v) && is_subclass_of($v, "\\r\\Query")) { 69 | return $v; 70 | } else if (is_object($v) && (is_subclass_of($v, "DateTimeInterface") || is_a($v, "DateTime"))) { 71 | // PHP prior to 5.5.0 doens't have DateTimeInterface, so we test for DateTime directly as well ^^^^^ 72 | $iso8601 = $v->format(\DateTime::ISO8601); 73 | return new Iso8601($iso8601); 74 | } else { 75 | throw new RqlDriverError("Unhandled type " . get_class($v)); 76 | } 77 | } 78 | 79 | // ------------- Helpers ------------- 80 | function decodedJSONToDatum($json) { 81 | if (is_null($json)) return NullDatum::_fromJSON($json); 82 | if (is_bool($json)) return BoolDatum::_fromJSON($json); 83 | if (is_int($json) || is_float($json)) return NumberDatum::_fromJSON($json); 84 | if (is_string($json)) return StringDatum::_fromJSON($json); 85 | if (is_array($json)) return ArrayDatum::_fromJSON($json); 86 | if (is_object($json)) return ObjectDatum::_fromJSON($json); 87 | 88 | throw new RqlDriverError("Unhandled type " . get_class($json)); 89 | } 90 | 91 | function tryEncodeAsJson($v) { 92 | if (canEncodeAsJson($v)) { 93 | // PHP by default loses some precision when encoding floats, so we temporarily 94 | // bump up the `precision` option to avoid this. 95 | // The 17 assumes IEEE-754 double precision numbers. 96 | // Source: http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html 97 | // "The same argument applied to double precision shows that 17 decimal 98 | // digits are required to recover a double precision number." 99 | $previousPrecision = ini_set("precision", 17); 100 | $json = json_encode($v); 101 | if ($previousPrecision !== false) { 102 | ini_set("precision", $previousPrecision); 103 | } 104 | if ($json === false) throw new RqlDriverError("Failed to encode document as JSON: " . json_last_error()); 105 | return $json; 106 | } else { 107 | return false; 108 | } 109 | } 110 | 111 | function canEncodeAsJson($v) { 112 | if (is_array($v)) { 113 | foreach($v as $key => $val) { 114 | if (!is_numeric($key) && !is_string($key)) return false; 115 | if (!canEncodeAsJson($val)) return false; 116 | } 117 | return true; 118 | } 119 | else if (is_null($v)) { 120 | return true; 121 | } 122 | else if (is_bool($v)) { 123 | return true; 124 | } 125 | else if (is_int($v) || is_float($v)) { 126 | return true; 127 | } 128 | else if (is_string($v)) { 129 | return true; 130 | } 131 | else { 132 | return false; 133 | } 134 | } 135 | 136 | // ------------- RethinkDB make queries ------------- 137 | class MakeArray extends ValuedQuery 138 | { 139 | public function __construct($value) { 140 | if (!is_array($value)) throw new RqlDriverError("Value must be an array."); 141 | $i = 0; 142 | foreach($value as $val) { 143 | $this->setPositionalArg($i++, $val); 144 | } 145 | } 146 | 147 | protected function getTermType() { 148 | return pb\Term_TermType::PB_MAKE_ARRAY; 149 | } 150 | } 151 | 152 | class MakeObject extends ValuedQuery 153 | { 154 | public function __construct($value) { 155 | if (!is_array($value)) throw new RqlDriverError("Value must be an array."); 156 | foreach($value as $key => $val) { 157 | $this->setOptionalArg($key, $val); 158 | } 159 | } 160 | 161 | protected function getTermType() { 162 | return pb\Term_TermType::PB_MAKE_OBJ; 163 | } 164 | } 165 | 166 | // ------------- RethinkDB datum types ------------- 167 | abstract class Datum extends ValuedQuery 168 | { 169 | public function __construct($value = null) { 170 | if (isset($value)) { 171 | $this->setValue($value); 172 | } 173 | } 174 | 175 | protected function getTermType() { 176 | return pb\Term_TermType::PB_DATUM; 177 | } 178 | 179 | public function toNative($opts) { 180 | return $this->getValue(); 181 | } 182 | 183 | public function __toString() { 184 | return "" . $this->getValue(); 185 | } 186 | 187 | public function _toString(&$backtrace) { 188 | $result = $this->__toString(); 189 | if (is_null($backtrace)) return $result; 190 | else { 191 | if ($backtrace === false) return str_repeat(" ", strlen($result)); 192 | $backtraceFrame = $backtrace->_consumeFrame(); 193 | if ($backtraceFrame !== false) throw new RqlDriverError("Internal Error: The backtrace says that we should have an argument in a Datum. This is not possible."); 194 | return str_repeat("~", strlen($result)); 195 | } 196 | } 197 | 198 | public function getValue() { 199 | return $this->value; 200 | } 201 | public function setValue($val) { 202 | $this->value = $val; 203 | } 204 | private $value; 205 | } 206 | 207 | class NullDatum extends Datum 208 | { 209 | public function _getJSONTerm() { 210 | return null; 211 | } 212 | 213 | static public function _fromJSON($json) { 214 | $result = new NullDatum(); 215 | $result->setValue(null); 216 | return $result; 217 | } 218 | 219 | public function setValue($val) { 220 | if (!is_null($val)) throw new RqlDriverError("Not null: " . $val); 221 | parent::setValue($val); 222 | } 223 | 224 | public function __toString() { 225 | return "null"; 226 | } 227 | } 228 | 229 | class BoolDatum extends Datum 230 | { 231 | public function _getJSONTerm() { 232 | return (bool)$this->getValue(); 233 | } 234 | 235 | static public function _fromJSON($json) { 236 | $result = new BoolDatum(); 237 | $result->setValue((bool)$json); 238 | return $result; 239 | } 240 | 241 | public function __toString() { 242 | if ($this->getValue()) return "true"; 243 | else return "false"; 244 | } 245 | 246 | public function setValue($val) { 247 | if (is_numeric($val)) $val = (($val == 0) ? false : true); 248 | if (!is_bool($val)) throw new RqlDriverError("Not a boolean: " . $val); 249 | parent::setValue($val); 250 | } 251 | } 252 | 253 | class NumberDatum extends Datum 254 | { 255 | public function _getJSONTerm() { 256 | return (float)$this->getValue(); 257 | } 258 | 259 | static public function _fromJSON($json) { 260 | $result = new NumberDatum(); 261 | $result->setValue((float)$json); 262 | return $result; 263 | } 264 | 265 | public function setValue($val) { 266 | if (!is_numeric($val)) throw new RqlDriverError("Not a number: " . $val); 267 | parent::setValue($val); 268 | } 269 | } 270 | 271 | class StringDatum extends Datum 272 | { 273 | public function _getJSONTerm() { 274 | return (string)$this->getValue(); 275 | } 276 | 277 | static public function _fromJSON($json) { 278 | $result = new StringDatum(); 279 | $result->setValue((string)$json); 280 | return $result; 281 | } 282 | 283 | public function setValue($val) { 284 | if (!is_string($val)) throw new RqlDriverError("Not a string"); 285 | parent::setValue($val); 286 | } 287 | 288 | public function __toString() { 289 | return "'" . $this->getValue() . "'"; 290 | } 291 | } 292 | 293 | class ArrayDatum extends Datum 294 | { 295 | public function _getJSONTerm() { 296 | $term = new MakeArray(array_values($this->getValue())); 297 | return $term->_getJSONTerm(); 298 | } 299 | 300 | static public function _fromJSON($json) { 301 | $jsonArray = array_values((array)$json); 302 | foreach ($jsonArray as &$val) { 303 | $val = decodedJSONToDatum($val); 304 | unset($val); 305 | } 306 | $result = new ArrayDatum(); 307 | $result->setValue($jsonArray); 308 | return $result; 309 | } 310 | 311 | public function setValue($val) { 312 | if (!is_array($val)) throw new RqlDriverError("Not an array: " . $val); 313 | foreach($val as $v) { 314 | if (!(is_object($v) && is_subclass_of($v, "\\r\\Query"))) throw new RqlDriverError("Not a Query: " . $v); 315 | } 316 | parent::setValue($val); 317 | } 318 | 319 | public function toNative($opts) { 320 | $native = array(); 321 | foreach ($this->getValue() as $val) { 322 | $native[] = $val->toNative($opts); 323 | } 324 | return $native; 325 | } 326 | 327 | public function __toString() { 328 | $string = 'array('; 329 | $first = true; 330 | foreach ($this->getValue() as $val) { 331 | if (!$first) { 332 | $string .= ", "; 333 | } 334 | $first = false; 335 | $string .= $val; 336 | } 337 | $string .= ')'; 338 | return $string; 339 | } 340 | } 341 | 342 | class ObjectDatum extends Datum 343 | { 344 | public function _getJSONTerm() { 345 | $jsonValue = $this->getValue(); 346 | foreach ($jsonValue as $key => &$val) { 347 | $val = $val->_getJSONTerm(); 348 | unset($val); 349 | } 350 | return (Object)$jsonValue; 351 | } 352 | 353 | static public function _fromJSON($json) { 354 | $jsonObject = (array)$json; 355 | foreach ($jsonObject as $key => &$val) { 356 | $val = decodedJSONToDatum($val); 357 | unset($val); 358 | } 359 | $result = new ObjectDatum(); 360 | $result->setValue($jsonObject); 361 | return $result; 362 | } 363 | 364 | public function setValue($val) { 365 | if (!is_array($val)) throw new RqlDriverError("Not an array: " . $val); 366 | foreach($val as $k => $v) { 367 | if (!is_string($k) && !is_numeric($k)) throw new RqlDriverError("Not a string or number: " . $k); 368 | if (!(is_object($v) && is_subclass_of($v, "\\r\\Query"))) throw new RqlDriverError("Not a Query: " . $v); 369 | } 370 | parent::setValue($val); 371 | } 372 | 373 | public function toNative($opts) { 374 | $native = new \ArrayObject(); 375 | foreach ($this->getValue() as $key => $val) { 376 | $native[$key] = $val->toNative($opts); 377 | } 378 | // Decode BINARY pseudo-type 379 | if ((!isset($opts['binaryFormat']) || $opts['binaryFormat'] == "native") 380 | && isset($native['$reql_type$']) && $native['$reql_type$'] == 'BINARY') { 381 | $decodedStr = base64_decode($native['data'], true); 382 | if ($decodedStr === FALSE) { 383 | throw new RqlDriverError("Failed to Base64 decode r\\binary value '" . $native['data'] . "'"); 384 | } 385 | return $decodedStr; 386 | } 387 | // Decode TIME pseudo-type to DateTime 388 | if ((!isset($opts['timeFormat']) || $opts['timeFormat'] == "native") 389 | && isset($native['$reql_type$']) && $native['$reql_type$'] == 'TIME') { 390 | $time = $native['epoch_time']; 391 | $format = (strpos($time, '.') !== false) ? '!U.u T' : '!U T'; 392 | $datetime = \DateTime::createFromFormat($format, $time . " " . $native['timezone'], new \DateTimeZone('UTC')); 393 | 394 | // This is horrible. Just because in PHP 5.3.something parsing "+01:00" as a date interval doesn't work. :( 395 | $tzSign = $native['timezone'][0]; 396 | $tzHours = $native['timezone'][1] . $native['timezone'][2]; 397 | $tzMinutes = $native['timezone'][4] . $native['timezone'][5]; 398 | if ($tzSign == "+") { 399 | $datetime->add(new \DateInterval("PT" . $tzHours . "H" . $tzMinutes . "M")); 400 | } else if ($tzSign == "-") { 401 | $datetime->sub(new \DateInterval("PT" . $tzHours . "H" . $tzMinutes . "M")); 402 | } else { 403 | throw new RqlDriverError("Timezone not understood: " . $native['timezone']); 404 | } 405 | 406 | return $datetime; 407 | } 408 | return $native; 409 | } 410 | 411 | public function __toString() { 412 | // Handle BINARY pseudo-type 413 | $val = $this->getValue(); 414 | if (isset($val['$reql_type$']) && $val['$reql_type$']->getValue() == 'BINARY') { 415 | $decodedStr = base64_decode($val['data']->getValue(), true); 416 | if ($decodedStr === FALSE) { 417 | return "r\\binary(ERROR)"; 418 | } 419 | return "r\\binary('$decodedStr')"; 420 | } 421 | $string = 'array('; 422 | $first = true; 423 | foreach ($val as $key => $val) { 424 | if (!$first) { 425 | $string .= ", "; 426 | } 427 | $first = false; 428 | $string .= "'" . $key . "' => " . $val; 429 | } 430 | $string .= ')'; 431 | return $string; 432 | } 433 | } 434 | 435 | ?> 436 | -------------------------------------------------------------------------------- /rdb2/function.php: -------------------------------------------------------------------------------- 1 | id = RVar::$nextVarId; 14 | $this->name = $name; 15 | 16 | if (RVar::$nextVarId == (1 << 31) - 1) 17 | RVar::$nextVarId = 0; // TODO: This is not ideal. In very very very rare cases, it could lead to collisions. 18 | else 19 | ++RVar::$nextVarId; 20 | 21 | $this->setPositionalArg(0, new NumberDatum($this->id)); 22 | } 23 | 24 | protected function getTermType() { 25 | return pb\Term_TermType::PB_VAR; 26 | } 27 | 28 | public function getId() { 29 | return $this->id; 30 | } 31 | 32 | private $id; 33 | 34 | private static $nextVarId = 1; 35 | } 36 | 37 | class RFunction extends FunctionQuery { 38 | public function __construct($args, Query $top) { 39 | if (!is_array($args)) throw new RqlDriverError("Arguments must be an array."); 40 | foreach ($args as &$arg) { 41 | if (!is_a($arg, "\\r\\RVar")) throw new RqlDriverError("Arguments must be RVar variables."); 42 | $arg = new NumberDatum($arg->getId()); 43 | unset($arg); 44 | } 45 | 46 | $this->setPositionalArg(0, new ArrayDatum($args)); 47 | $this->setPositionalArg(1, $top); 48 | } 49 | 50 | public function _hasUnwrappedImplicitVar() { 51 | // A function wraps implicit variables 52 | return false; 53 | } 54 | 55 | protected function getTermType() { 56 | return pb\Term_TermType::PB_FUNC; 57 | } 58 | } 59 | 60 | function wrapImplicitVar(Query $q) { 61 | if ($q->_hasUnwrappedImplicitVar()) { 62 | return new RFunction(array(new RVar('_')), $q); 63 | } else { 64 | return $q; 65 | } 66 | } 67 | 68 | function nativeToFunction($f) { 69 | if (is_object($f) && is_subclass_of($f, "\\r\\Query")) { 70 | return wrapImplicitVar($f); 71 | } 72 | 73 | $reflection = new \ReflectionFunction($f); 74 | 75 | $args = array(); 76 | foreach ($reflection->getParameters() as $param) { 77 | $args[] = new RVar($param->getName()); 78 | } 79 | $result = $reflection->invokeArgs($args); 80 | 81 | if (!(is_object($result) && is_subclass_of($result, "\\r\\Query"))) { 82 | if (!isset($result)) { 83 | // In case of null, assume that the user forgot to add a return. 84 | // If null is the intended value, r\expr() should be wrapped around the return value. 85 | throw new RqlDriverError("The function did not evaluate to a query (missing return?)."); 86 | } else { 87 | $result = nativeToDatum($result); 88 | } 89 | } 90 | 91 | return new RFunction($args, $result); 92 | } 93 | 94 | function nativeToDatumOrFunction($f) { 95 | if (!(is_object($f) && is_subclass_of($f, "\\r\\Query"))) { 96 | try { 97 | $f = nativeToDatum($f); 98 | if (!is_subclass_of($f, "\\r\\Datum")) { 99 | // $f is not a simple datum. Wrap it into a function: 100 | $f = new RFunction(array(new RVar('_')), $f); 101 | } 102 | } catch (RqlDriverError $e) { 103 | $f = nativeToFunction($f); 104 | } 105 | } 106 | return wrapImplicitVar($f); 107 | } 108 | 109 | ?> 110 | -------------------------------------------------------------------------------- /rdb2/global.php: -------------------------------------------------------------------------------- 1 | 'BINARY', 'data' => $encodedStr); 90 | return nativeToDatum($pseudo); 91 | } 92 | 93 | function desc($attribute) { 94 | return new Desc($attribute); 95 | } 96 | 97 | function asc($attribute) { 98 | return new Asc($attribute); 99 | } 100 | 101 | function json($json) { 102 | return new Json($json); 103 | } 104 | 105 | function http($url, $opts = null) { 106 | return new Http($url, $opts); 107 | } 108 | 109 | function rObject($object) { 110 | return new RObject($object); 111 | } 112 | 113 | // r\literal can accept 0 or 1 arguments 114 | function literal() { 115 | if (func_num_args() == 0) { 116 | return new Literal(); 117 | } else { 118 | return new Literal(func_get_arg(0)); 119 | } 120 | } 121 | 122 | function add($expr1, $expr2) { 123 | return new Add($expr1, $expr2); 124 | } 125 | function sub($expr1, $expr2) { 126 | return new Sub($expr1, $expr2); 127 | } 128 | function mul($expr1, $expr2) { 129 | return new Mul($expr1, $expr2); 130 | } 131 | function div($expr1, $expr2) { 132 | return new Div($expr1, $expr2); 133 | } 134 | function mod($expr1, $expr2) { 135 | return new Mod($expr1, $expr2); 136 | } 137 | 138 | function rAnd($expr1, $expr2) { 139 | return new RAnd($expr1, $expr2); 140 | } 141 | function rOr($expr1, $expr2) { 142 | return new ROr($expr1, $expr2); 143 | } 144 | 145 | function eq($expr1, $expr2) { 146 | return new Eq($expr1, $expr2); 147 | } 148 | function ne($expr1, $expr2) { 149 | return new Ne($expr1, $expr2); 150 | } 151 | function gt($expr1, $expr2) { 152 | return new Gt($expr1, $expr2); 153 | } 154 | function ge($expr1, $expr2) { 155 | return new Ge($expr1, $expr2); 156 | } 157 | function lt($expr1, $expr2) { 158 | return new Lt($expr1, $expr2); 159 | } 160 | function le($expr1, $expr2) { 161 | return new Le($expr1, $expr2); 162 | } 163 | 164 | function not($expr) { 165 | return new Not($expr); 166 | } 167 | 168 | function random($left = null, $right = null, $opts = null) { 169 | return new Random($left, $right, $opts); 170 | } 171 | 172 | function now() { 173 | return new Now(); 174 | } 175 | 176 | function time($year, $month, $day, $hourOrTimezone = null, $minute = null, $second = null, $timezone = null) { 177 | return new Time($year, $month, $day, $hourOrTimezone, $minute, $second, $timezone); 178 | } 179 | 180 | function epochTime($epochTime) { 181 | return new EpochTime($epochTime); 182 | } 183 | 184 | function iso8601($iso8601Date, $opts = null) { 185 | return new Iso8601($iso8601Date, $opts); 186 | } 187 | 188 | function monday() { 189 | return new Monday(); 190 | } 191 | function tuesday() { 192 | return new Tuesday(); 193 | } 194 | function wednesday() { 195 | return new Wednesday(); 196 | } 197 | function thursday() { 198 | return new Thursday(); 199 | } 200 | function friday() { 201 | return new Friday(); 202 | } 203 | function saturday() { 204 | return new Saturday(); 205 | } 206 | function sunday() { 207 | return new Sunday(); 208 | } 209 | 210 | function january() { 211 | return new January(); 212 | } 213 | function february() { 214 | return new February(); 215 | } 216 | function march() { 217 | return new March(); 218 | } 219 | function april() { 220 | return new April(); 221 | } 222 | function may() { 223 | return new May(); 224 | } 225 | function june() { 226 | return new June(); 227 | } 228 | function july() { 229 | return new July(); 230 | } 231 | function august() { 232 | return new August(); 233 | } 234 | function september() { 235 | return new September(); 236 | } 237 | function october() { 238 | return new October(); 239 | } 240 | function november() { 241 | return new November(); 242 | } 243 | function december() { 244 | return new December(); 245 | } 246 | 247 | function geoJSON($geojson) { 248 | return new GeoJSON($geojson); 249 | } 250 | 251 | function point($lat, $lon) { 252 | return new Point($lat, $lon); 253 | } 254 | 255 | function line($points) { 256 | return new Line($points); 257 | } 258 | 259 | function polygon($points) { 260 | return new Polygon($points); 261 | } 262 | 263 | function circle($center, $radius, $opts = null) { 264 | return new Circle($center, $radius, $opts); 265 | } 266 | 267 | function intersects($g1, $g2) { 268 | return new Intersects($g1, $g2); 269 | } 270 | 271 | function distance($g1, $g2, $opts = null) { 272 | return new Distance($g1, $g2, $opts); 273 | } 274 | 275 | function uuid() { 276 | return new Uuid(); 277 | } 278 | 279 | function minval() { 280 | return new Minval(); 281 | } 282 | 283 | function maxval() { 284 | return new Maxval(); 285 | } 286 | 287 | function range($startOrEndValue = null, $endValue = null) { 288 | return new Range($startOrEndValue, $endValue); 289 | } 290 | 291 | function mapMultiple($sequences, $mappingFunction) { 292 | if (!is_array($sequences)) 293 | $sequences = array($sequences); 294 | if (sizeof($sequences) < 1) 295 | throw new RqlDriverError("At least one sequence must be passed into r\mapMultiple."); 296 | return new MapMultiple($sequences[0], array_slice($sequences, 1), $mappingFunction); 297 | } 298 | 299 | ?> 300 | -------------------------------------------------------------------------------- /rdb2/misc.php: -------------------------------------------------------------------------------- 1 | _hasUnwrappedImplicitVar()) { 12 | $this->unwrappedImplicitVar = true; 13 | } 14 | $this->optionalArgs[$key] = $val; 15 | } 16 | 17 | protected function setPositionalArg($pos, Query $arg) { 18 | if (!is_numeric($pos)) throw new RqlDriverError("Internal driver error: Got a non-numeric position for a positional argument."); 19 | if ($arg->_hasUnwrappedImplicitVar()) { 20 | $this->unwrappedImplicitVar = true; 21 | } 22 | $this->positionalArgs[$pos] = $arg; 23 | } 24 | 25 | public function _hasUnwrappedImplicitVar() { 26 | return $this->unwrappedImplicitVar; 27 | } 28 | 29 | public function _getJSONTerm() { 30 | $args = array(); 31 | foreach ($this->positionalArgs as $i => $arg) { 32 | $args[] = $arg->_getJSONTerm(); 33 | } 34 | $optargs = array(); 35 | foreach ($this->optionalArgs as $key => $val) { 36 | $optargs[$key] = $val->_getJSONTerm(); 37 | } 38 | return array($this->getTermType(), $args, (object)$optargs); 39 | } 40 | 41 | public function run(Connection $connection, $options = null) { 42 | return $connection->_run($this, $options, $profile); 43 | } 44 | 45 | public function profile(Connection $connection, $options = null, &$result = null) { 46 | if (!isset($options)) $options = array(); 47 | $options['profile'] = true; 48 | $result = $connection->_run($this, $options, $profile); 49 | return $profile; 50 | } 51 | 52 | public function info() { 53 | return new Info($this); 54 | } 55 | public function rDefault($defaultCase) 56 | { 57 | return new RDefault($this, $defaultCase); 58 | } 59 | 60 | public function __toString() { 61 | $backtrace = null; 62 | return $this->_toString($backtrace); 63 | } 64 | 65 | public function _toString(&$backtrace) { 66 | // TODO (daniel): This kind of printing backtraces is pretty hacky. Overhaul this. 67 | // Maybe we could generate a PHP backtrace structure... 68 | 69 | $backtraceFrame = null; 70 | if (isset($backtrace) && $backtrace !== false) { 71 | $backtraceFrame = $backtrace->_consumeFrame(); 72 | } 73 | 74 | $types = (new \ReflectionObject(new pb\Term_TermType())); 75 | $types = $types->getConstants(); 76 | $type = "UNKNOWN"; 77 | foreach ($types as $key => $val) { 78 | if (substr($key, 0, 3) != "PB_") continue; 79 | if ($val == $this->getTermType()) { 80 | $type = substr($key, 3); 81 | } 82 | } 83 | 84 | $argList = ""; 85 | foreach ($this->positionalArgs as $i => $arg) { 86 | if ($i > 0) { 87 | if (isset($backtrace)) 88 | $argList .= " "; 89 | else 90 | $argList .= ", "; 91 | } 92 | 93 | $subTrace = is_null($backtrace) ? null : false; 94 | if (is_object($backtraceFrame) && $backtraceFrame->isPositionalArg() && $backtraceFrame->getPositionalArgPosition() == $i) { 95 | $subTrace = $backtrace; 96 | } 97 | $argList .= $arg->_toString($subTrace); 98 | } 99 | 100 | $optArgList = ""; 101 | $firstOptArg = true; 102 | foreach ($this->optionalArgs as $key => $val) { 103 | if (!$firstOptArg) { 104 | if (isset($backtrace)) 105 | $optArgList .= " "; 106 | else 107 | $optArgList .= ", "; 108 | } 109 | $firstOptArg = false; 110 | 111 | $subTrace = is_null($backtrace) ? null : false; 112 | if (is_object($backtraceFrame) && $backtraceFrame->isOptionalArg() && $backtraceFrame->getOptionalArgName() == $key) { 113 | $subTrace = $backtrace; 114 | } 115 | if (isset($backtrace)) 116 | $optArgList .= str_repeat(" ", strlen($key)) . " " . $val->_toString($subTrace); 117 | else 118 | $optArgList .= $key . " => " . $val->_toString($subTrace); 119 | } 120 | 121 | if ($optArgList) { 122 | if (strlen($argList) > 0) { 123 | if (isset($backtrace)) 124 | $argList .= " "; 125 | else 126 | $argList .= ", "; 127 | } 128 | if (isset($backtrace)) 129 | $argList .= " " . $optArgList . " "; 130 | else 131 | $argList .= "OptArgs(" . $optArgList . ")"; 132 | } 133 | 134 | $result = $type . "(" . $argList . ")"; 135 | if (isset($backtrace)) { 136 | if ($backtraceFrame === false) { 137 | // We are the origin of the trouble 138 | return str_repeat("~", strlen($result)); 139 | } 140 | else { 141 | return str_repeat(" ", strlen($type)) . " " . $argList . " "; 142 | } 143 | } else { 144 | return $result; 145 | } 146 | } 147 | 148 | private $positionalArgs = array(); 149 | private $optionalArgs = array(); 150 | private $unwrappedImplicitVar = false; 151 | } 152 | 153 | // This is just any query except for Table and Db at the moment. 154 | // We define all remaining operations on this. 155 | abstract class ValuedQuery extends Query 156 | { 157 | public function update($delta, $opts = null) { 158 | return new Update($this, $delta, $opts); 159 | } 160 | public function delete($opts = null) { 161 | return new Delete($this, $opts); 162 | } 163 | public function replace($delta, $opts = null) { 164 | return new Replace($this, $delta, $opts); 165 | } 166 | public function between($leftBound, $rightBound, $opts = null) { 167 | return new Between($this, $leftBound, $rightBound, $opts); 168 | } 169 | public function filter($predicate, $default = null) { 170 | return new Filter($this, $predicate, $default); 171 | } 172 | public function innerJoin(ValuedQuery $otherSequence, $predicate) { 173 | return new InnerJoin($this, $otherSequence, $predicate); 174 | } 175 | public function outerJoin(ValuedQuery $otherSequence, $predicate) { 176 | return new OuterJoin($this, $otherSequence, $predicate); 177 | } 178 | public function eqJoin($attribute, ValuedQuery $otherSequence, $opts = null) { 179 | return new EqJoin($this, $attribute, $otherSequence, $opts); 180 | } 181 | public function zip() { 182 | return new Zip($this); 183 | } 184 | public function withFields($attributes) { 185 | return new WithFields($this, $attributes); 186 | } 187 | public function map($mappingFunction) { 188 | return new Map($this, $mappingFunction); 189 | } 190 | public function mapMultiple($moreSequences, $mappingFunction) { 191 | return new MapMultiple($this, $moreSequences, $mappingFunction); 192 | } 193 | public function concatMap($mappingFunction) { 194 | return new ConcatMap($this, $mappingFunction); 195 | } 196 | public function orderBy($keys) { 197 | return new OrderBy($this, $keys); 198 | } 199 | public function skip($n) { 200 | return new Skip($this, $n); 201 | } 202 | public function limit($n) { 203 | return new Limit($this, $n); 204 | } 205 | public function slice($startIndex, $endIndex = null, $opts = null) { 206 | return new Slice($this, $startIndex, $endIndex, $opts); 207 | } 208 | public function nth($index) { 209 | return new Nth($this, $index); 210 | } 211 | public function offsetsOf($predicate) { 212 | return new OffsetsOf($this, $predicate); 213 | } 214 | public function isEmpty() { 215 | return new IsEmpty($this); 216 | } 217 | public function union(ValuedQuery $otherSequence) { 218 | return new Union($this, $otherSequence); 219 | } 220 | public function sample($n) { 221 | return new Sample($this, $n); 222 | } 223 | public function reduce($reductionFunction) { 224 | return new Reduce($this, $reductionFunction); 225 | } 226 | public function count($filter = null) { 227 | return new Count($this, $filter); 228 | } 229 | public function distinct($opts = null) { 230 | return new Distinct($this, $opts); 231 | } 232 | public function group($groupOn) { 233 | return new Group($this, $groupOn); 234 | } 235 | public function ungroup() { 236 | return new Ungroup($this); 237 | } 238 | public function avg($attribute = null) { 239 | return new Avg($this, $attribute); 240 | } 241 | public function sum($attribute = null) { 242 | return new Sum($this, $attribute); 243 | } 244 | public function min($attributeOrOpts = null) { 245 | return new Min($this, $attributeOrOpts); 246 | } 247 | public function max($attributeOrOpts = null) { 248 | return new Max($this, $attributeOrOpts); 249 | } 250 | // Note: The API docs suggest that as of 1.6, contains can accept multiple values. 251 | // We do not support that for the time being. 252 | public function contains($value) { 253 | return new Contains($this, $value); 254 | } 255 | public function pluck($attributes) { 256 | return new Pluck($this, $attributes); 257 | } 258 | public function without($attributes) { 259 | return new Without($this, $attributes); 260 | } 261 | public function merge($other) { 262 | return new Merge($this, $other); 263 | } 264 | public function append($value) { 265 | return new Append($this, $value); 266 | } 267 | public function prepend($value) { 268 | return new Prepend($this, $value); 269 | } 270 | public function difference($value) { 271 | return new Difference($this, $value); 272 | } 273 | public function setInsert($value) { 274 | return new SetInsert($this, $value); 275 | } 276 | public function setUnion($value) { 277 | return new SetUnion($this, $value); 278 | } 279 | public function setIntersection($value) { 280 | return new SetIntersection($this, $value); 281 | } 282 | public function setDifference($value) { 283 | return new SetDifference($this, $value); 284 | } 285 | public function __invoke($attributeOrIndex) { 286 | return new Bracket($this, $attributeOrIndex); 287 | } 288 | public function getField($attribute) { 289 | return new GetField($this, $attribute); 290 | } 291 | public function hasFields($attributes) { 292 | return new HasFields($this, $attributes); 293 | } 294 | public function insertAt($index, $value) { 295 | return new InsertAt($this, $index, $value); 296 | } 297 | public function spliceAt($index, $value) { 298 | return new SpliceAt($this, $index, $value); 299 | } 300 | public function deleteAt($index, $endIndex = null) { 301 | return new DeleteAt($this, $index, $endIndex); 302 | } 303 | public function changeAt($index, $value) { 304 | return new changeAt($this, $index, $value); 305 | } 306 | public function keys() { 307 | return new Keys($this); 308 | } 309 | public function add($other) { 310 | return add($this, $other); 311 | } 312 | public function sub($other) { 313 | return sub($this, $other); 314 | } 315 | public function mul($other) { 316 | return mul($this, $other); 317 | } 318 | public function div($other) { 319 | return div($this, $other); 320 | } 321 | public function mod($other) { 322 | return mod($this, $other); 323 | } 324 | public function rAnd($other) { 325 | return rAnd($this, $other); 326 | } 327 | public function rOr($other) { 328 | return rOr($this, $other); 329 | } 330 | public function eq($other) { 331 | return eq($this, $other); 332 | } 333 | public function ne($other) { 334 | return ne($this, $other); 335 | } 336 | public function gt($other) { 337 | return gt($this, $other); 338 | } 339 | public function ge($other) { 340 | return ge($this, $other); 341 | } 342 | public function lt($other) { 343 | return lt($this, $other); 344 | } 345 | public function le($other) { 346 | return le($this, $other); 347 | } 348 | public function not() { 349 | return not($this); 350 | } 351 | public function match($expression) { 352 | return new Match($this, $expression); 353 | } 354 | public function upcase() { 355 | return new Upcase($this); 356 | } 357 | public function downcase() { 358 | return new Downcase($this); 359 | } 360 | public function split($separator = null, $maxSplits = null) { 361 | return new split($this, $separator, $maxSplits); 362 | } 363 | public function rForeach($queryFunction) { 364 | return new RForeach($this, $queryFunction); 365 | } 366 | public function coerceTo($typeName) { 367 | return new CoerceTo($this, $typeName); 368 | } 369 | public function typeOf() { 370 | return new TypeOf($this); 371 | } 372 | public function rDo($inExpr) { 373 | return new RDo($this, $inExpr); 374 | } 375 | public function toEpochTime() { 376 | return new ToEpochTime($this); 377 | } 378 | public function toIso8601() { 379 | return new ToIso8601($this); 380 | } 381 | public function inTimezone($timezone) { 382 | return new InTimezone($this, $timezone); 383 | } 384 | public function timezone() { 385 | return new Timezone($this); 386 | } 387 | public function during($startTime, $endTime, $opts = null) { 388 | return new During($this, $startTime, $endTime, $opts); 389 | } 390 | public function date() { 391 | return new Date($this); 392 | } 393 | public function timeOfDay() { 394 | return new TimeOfDay($this); 395 | } 396 | public function year() { 397 | return new Year($this); 398 | } 399 | public function month() { 400 | return new Month($this); 401 | } 402 | public function day() { 403 | return new Day($this); 404 | } 405 | public function dayOfWeek() { 406 | return new DayOfWeek($this); 407 | } 408 | public function dayOfYear() { 409 | return new DayOfYear($this); 410 | } 411 | public function hours() { 412 | return new Hours($this); 413 | } 414 | public function minutes() { 415 | return new Minutes($this); 416 | } 417 | public function seconds() { 418 | return new Seconds($this); 419 | } 420 | public function changes($opts = null) { 421 | return new Changes($this, $opts); 422 | } 423 | public function toGeoJSON() { 424 | return new ToGeoJSON($this); 425 | } 426 | public function intersects($g2) { 427 | return new Intersects($this, $g2); 428 | } 429 | public function includes($g2) { 430 | return new Includes($this, $g2); 431 | } 432 | public function distance($g2, $opts = null) { 433 | return new Distance($this, $g2, $opts); 434 | } 435 | public function fill() { 436 | return new Fill($this); 437 | } 438 | public function polygonSub($other) { 439 | return new PolygonSub($this, $other); 440 | } 441 | public function toJsonString() { 442 | return new ToJsonString($this); 443 | } 444 | } 445 | 446 | abstract class Ordering extends Query { 447 | } 448 | 449 | class Asc extends Ordering { 450 | public function __construct($attribute) { 451 | $attribute = nativeToDatumOrFunction($attribute); 452 | $this->setPositionalArg(0, $attribute); 453 | } 454 | 455 | protected function getTermType() { 456 | return pb\Term_TermType::PB_ASC; 457 | } 458 | } 459 | 460 | class Desc extends Ordering { 461 | public function __construct($attribute) { 462 | $attribute = nativeToDatumOrFunction($attribute); 463 | $this->setPositionalArg(0, $attribute); 464 | } 465 | 466 | protected function getTermType() { 467 | return pb\Term_TermType::PB_DESC; 468 | } 469 | } 470 | 471 | class ImplicitVar extends ValuedQuery 472 | { 473 | protected function getTermType() { 474 | return pb\Term_TermType::PB_IMPLICIT_VAR; 475 | } 476 | public function _hasUnwrappedImplicitVar() { 477 | // A function wraps implicit variables 478 | return true; 479 | } 480 | } 481 | 482 | class Info extends ValuedQuery { 483 | public function __construct(Query $onQuery) { 484 | $this->setPositionalArg(0, $onQuery); 485 | } 486 | 487 | protected function getTermType() { 488 | return pb\Term_TermType::PB_INFO; 489 | } 490 | } 491 | 492 | class RObject extends ValuedQuery { 493 | public function __construct($object) { 494 | if (!is_array($object)) throw RqlDriverError("Argument to r\\Object must be an array."); 495 | $i = 0; 496 | foreach($object as $v) { 497 | $this->setPositionalArg($i++, nativeToDatum($v)); 498 | } 499 | } 500 | 501 | protected function getTermType() { 502 | return pb\Term_TermType::PB_OBJECT; 503 | } 504 | } 505 | 506 | class Json extends ValuedQuery { 507 | public function __construct($json) { 508 | if (!(is_object($json) && is_subclass_of($json, "\\r\\Query"))) { 509 | if (!is_string($json)) throw new RqlDriverError("JSON must be a string."); 510 | $json = new StringDatum($json); 511 | } 512 | $this->setPositionalArg(0, $json); 513 | } 514 | 515 | protected function getTermType() { 516 | return pb\Term_TermType::PB_JSON; 517 | } 518 | } 519 | 520 | class Literal extends ValuedQuery { 521 | public function __construct() { 522 | if (func_num_args() > 0) { 523 | $value = func_get_arg(0); 524 | if (!(is_object($value) && is_subclass_of($value, "\\r\\Query"))) { 525 | $value = nativeToDatum($value); 526 | } 527 | $this->setPositionalArg(0, $value); 528 | } 529 | } 530 | 531 | protected function getTermType() { 532 | return pb\Term_TermType::PB_LITERAL; 533 | } 534 | } 535 | 536 | class Cursor implements \Iterator 537 | { 538 | // PHP iterator interface 539 | public function rewind() { 540 | if ($this->wasIterated) { 541 | throw new RqlDriverError("Rewind() not supported. You can only iterate over a cursor once."); 542 | } 543 | } 544 | public function next() { 545 | $this->requestMoreIfNecessary(); 546 | if (!$this->valid()) throw new RqlDriverError("No more data available."); 547 | $this->wasIterated = true; 548 | $this->currentIndex++; 549 | } 550 | public function valid() { 551 | $this->requestMoreIfNecessary(); 552 | return !$this->isComplete || ($this->currentIndex < $this->currentSize); 553 | } 554 | public function key() { 555 | return null; 556 | } 557 | public function current() { 558 | $this->requestMoreIfNecessary(); 559 | if (!$this->valid()) throw new RqlDriverError("No more data available."); 560 | return $this->currentData[$this->currentIndex]->toNative($this->toNativeOptions); 561 | } 562 | 563 | public function toArray() { 564 | $result = array(); 565 | foreach ($this as $val) { 566 | $result[] = $val; 567 | } 568 | return $result; 569 | } 570 | 571 | public function close() { 572 | if (!$this->isComplete) { 573 | // Cancel the request 574 | $this->connection->_stopQuery($this->token); 575 | $this->isComplete = true; 576 | } 577 | $this->currentIndex = 0; 578 | $this->currentSize = 0; 579 | $this->currentData = array(); 580 | } 581 | 582 | public function bufferedCount() { 583 | $this->currentSize - $this->currentIndex; 584 | } 585 | 586 | public function getNotes() { 587 | return $this->notes; 588 | } 589 | 590 | public function __toString() { 591 | return "Cursor"; 592 | } 593 | 594 | public function __construct(Connection $connection, $initialResponse, $token, $notes, $toNativeOptions) { 595 | $this->connection = $connection; 596 | $this->token = $token; 597 | $this->notes = $notes; 598 | $this->toNativeOptions = $toNativeOptions; 599 | $this->wasIterated = false; 600 | 601 | $this->setBatch($initialResponse); 602 | } 603 | 604 | public function __destruct() { 605 | if ($this->connection->isOpen()) { 606 | // Cancel the request 607 | $this->close(); 608 | } 609 | } 610 | 611 | private function requestMoreIfNecessary() { 612 | while ($this->currentIndex == $this->currentSize) { 613 | // We are at the end of currentData. Request more if available 614 | if ($this->isComplete) { 615 | return; 616 | } 617 | $this->requestNewBatch(); 618 | } 619 | } 620 | 621 | private function requestNewBatch() { 622 | try { 623 | $response = $this->connection->_continueQuery($this->token); 624 | $this->setBatch($response); 625 | } catch (\Exception $e) { 626 | $this->isComplete = true; 627 | $this->close(); 628 | throw $e; 629 | } 630 | } 631 | 632 | private function setBatch($response) { 633 | $this->isComplete = $response['t'] == pb\Response_ResponseType::PB_SUCCESS_SEQUENCE; 634 | $this->currentIndex = 0; 635 | $this->currentSize = \count($response['r']); 636 | $this->currentData = array(); 637 | foreach ($response['r'] as $row) { 638 | $this->currentData[] = $datum = decodedJSONToDatum($row); 639 | } 640 | } 641 | 642 | private $token; 643 | private $connection; 644 | private $notes; 645 | private $toNativeOptions; 646 | private $currentData; 647 | private $currentSize; 648 | private $currentIndex; 649 | private $isComplete; 650 | private $wasIterated; 651 | } 652 | 653 | ?> 654 | -------------------------------------------------------------------------------- /rdb2/pb4php_pb_proto_ql2.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rdb2/queries.php: -------------------------------------------------------------------------------- 1 | 24 | -------------------------------------------------------------------------------- /rdb2/queries/aggregations.php: -------------------------------------------------------------------------------- 1 | setPositionalArg(0, $sequence); 9 | $this->setPositionalArg(1, $reductionFunction); 10 | } 11 | 12 | protected function getTermType() { 13 | return pb\Term_TermType::PB_REDUCE; 14 | } 15 | } 16 | 17 | class Count extends ValuedQuery 18 | { 19 | public function __construct(ValuedQuery $sequence, $filter = null) { 20 | if (isset($filter)) { 21 | $filter = nativeToDatumOrFunction($filter); 22 | } 23 | 24 | $this->setPositionalArg(0, $sequence); 25 | if (isset($filter)) { 26 | $this->setPositionalArg(1, $filter); 27 | } 28 | } 29 | 30 | protected function getTermType() { 31 | return pb\Term_TermType::PB_COUNT; 32 | } 33 | } 34 | 35 | class Distinct extends ValuedQuery 36 | { 37 | public function __construct(ValuedQuery $sequence, $opts = null) { 38 | $this->setPositionalArg(0, $sequence); 39 | if (isset($opts)) { 40 | foreach ($opts as $opt => $val) { 41 | $this->setOptionalArg($opt, nativeToDatum($val)); 42 | } 43 | } 44 | } 45 | 46 | protected function getTermType() { 47 | return pb\Term_TermType::PB_DISTINCT; 48 | } 49 | } 50 | 51 | class Group extends ValuedQuery 52 | { 53 | public function __construct(ValuedQuery $sequence, $groupOn) { 54 | if (!is_array($groupOn)) { 55 | $groupOn = array($groupOn); 56 | } 57 | if (isset($groupOn['index'])) { 58 | $this->setOptionalArg('index', nativeToDatum($groupOn['index'])); 59 | unset($groupOn['index']); 60 | } 61 | 62 | $this->setPositionalArg(0, $sequence); 63 | $i = 1; 64 | foreach ($groupOn as $g) { 65 | $this->setPositionalArg($i++, nativeToDatumOrFunction($g)); 66 | } 67 | } 68 | 69 | protected function getTermType() { 70 | return pb\Term_TermType::PB_GROUP; 71 | } 72 | } 73 | 74 | class Ungroup extends ValuedQuery 75 | { 76 | public function __construct(ValuedQuery $sequence) { 77 | $this->setPositionalArg(0, $sequence); 78 | } 79 | 80 | protected function getTermType() { 81 | return pb\Term_TermType::PB_UNGROUP; 82 | } 83 | } 84 | 85 | class Sum extends ValuedQuery 86 | { 87 | public function __construct(ValuedQuery $sequence, $attribute = null) { 88 | if (isset($attribute)) { 89 | $attribute = nativeToDatumOrFunction($attribute); 90 | } 91 | 92 | $this->setPositionalArg(0, $sequence); 93 | if (isset($attribute)) { 94 | $this->setPositionalArg(1, $attribute); 95 | } 96 | } 97 | 98 | protected function getTermType() { 99 | return pb\Term_TermType::PB_SUM; 100 | } 101 | } 102 | 103 | class Avg extends ValuedQuery 104 | { 105 | public function __construct(ValuedQuery $sequence, $attribute = null) { 106 | if (isset($attribute)) { 107 | $attribute = nativeToDatumOrFunction($attribute); 108 | } 109 | 110 | $this->setPositionalArg(0, $sequence); 111 | if (isset($attribute)) { 112 | $this->setPositionalArg(1, $attribute); 113 | } 114 | } 115 | 116 | protected function getTermType() { 117 | return pb\Term_TermType::PB_AVG; 118 | } 119 | } 120 | 121 | class Min extends ValuedQuery 122 | { 123 | public function __construct(ValuedQuery $sequence, $attributeOrOpts = null) { 124 | $this->setPositionalArg(0, $sequence); 125 | if (isset($attributeOrOpts)) { 126 | if (is_array($attributeOrOpts)) { 127 | foreach ($attributeOrOpts as $opt => $val) { 128 | $this->setOptionalArg($opt, nativeToDatum($val)); 129 | } 130 | } else { 131 | $attribute = nativeToDatumOrFunction($attributeOrOpts); 132 | $this->setPositionalArg(1, $attribute); 133 | } 134 | } 135 | } 136 | 137 | protected function getTermType() { 138 | return pb\Term_TermType::PB_MIN; 139 | } 140 | } 141 | 142 | class Max extends ValuedQuery 143 | { 144 | public function __construct(ValuedQuery $sequence, $attributeOrOpts = null) { 145 | $this->setPositionalArg(0, $sequence); 146 | if (isset($attributeOrOpts)) { 147 | if (is_array($attributeOrOpts)) { 148 | foreach ($attributeOrOpts as $opt => $val) { 149 | $this->setOptionalArg($opt, nativeToDatum($val)); 150 | } 151 | } else { 152 | $attribute = nativeToDatumOrFunction($attributeOrOpts); 153 | $this->setPositionalArg(1, $attribute); 154 | } 155 | } 156 | } 157 | 158 | protected function getTermType() { 159 | return pb\Term_TermType::PB_MAX; 160 | } 161 | } 162 | 163 | class Contains extends ValuedQuery 164 | { 165 | public function __construct(ValuedQuery $sequence, $value) { 166 | $value = nativeToDatumOrFunction($value); 167 | 168 | $this->setPositionalArg(0, $sequence); 169 | $this->setPositionalArg(1, $value); 170 | } 171 | 172 | protected function getTermType() { 173 | return pb\Term_TermType::PB_CONTAINS; 174 | } 175 | } 176 | 177 | ?> 178 | -------------------------------------------------------------------------------- /rdb2/queries/control.php: -------------------------------------------------------------------------------- 1 | setPositionalArg(0, $inExpr); 8 | 9 | $i = 1; 10 | if (!is_array($args)) $args = array($args); 11 | foreach ($args as &$arg) { 12 | if (!(is_object($arg) && is_subclass_of($arg, "\\r\\Query"))) { 13 | $arg = nativeToDatum($arg); 14 | } 15 | $this->setPositionalArg($i++, $arg); 16 | unset($arg); 17 | } 18 | } 19 | 20 | protected function getTermType() { 21 | return pb\Term_TermType::PB_FUNCALL; 22 | } 23 | } 24 | 25 | class Branch extends ValuedQuery 26 | { 27 | public function __construct(Query $test, $trueBranch, $falseBranch) { 28 | $trueBranch = nativeToDatumOrFunction($trueBranch); 29 | $falseBranch = nativeToDatumOrFunction($falseBranch); 30 | 31 | $this->setPositionalArg(0, $test); 32 | $this->setPositionalArg(1, $trueBranch); 33 | $this->setPositionalArg(2, $falseBranch); 34 | } 35 | 36 | protected function getTermType() { 37 | return pb\Term_TermType::PB_BRANCH; 38 | } 39 | } 40 | 41 | class RForeach extends ValuedQuery 42 | { 43 | public function __construct(ValuedQuery $sequence, $queryFunction) { 44 | $queryFunction = nativeToFunction($queryFunction); 45 | $this->setPositionalArg(0, $sequence); 46 | $this->setPositionalArg(1, $queryFunction); 47 | } 48 | 49 | protected function getTermType() { 50 | return pb\Term_TermType::PB_FOR_EACH; 51 | } 52 | } 53 | 54 | class Error extends ValuedQuery 55 | { 56 | public function __construct($message = null) { 57 | if (isset($message)) { 58 | if (!(is_object($message) && is_subclass_of($message, "\\r\\Query"))) 59 | $message = new StringDatum($message); 60 | $this->setPositionalArg(0, $message); 61 | } 62 | } 63 | 64 | protected function getTermType() { 65 | return pb\Term_TermType::PB_ERROR; 66 | } 67 | } 68 | 69 | class RDefault extends ValuedQuery 70 | { 71 | public function __construct(Query $query, $defaultCase) { 72 | $defaultCase = nativeToDatumOrFunction($defaultCase); 73 | 74 | $this->setPositionalArg(0, $query); 75 | $this->setPositionalArg(1, $defaultCase); 76 | } 77 | 78 | protected function getTermType() { 79 | return pb\Term_TermType::PB_DEFAULT; 80 | } 81 | } 82 | 83 | class Js extends FunctionQuery 84 | { 85 | public function __construct($code, $timeout = null) { 86 | if (isset($timeout)) 87 | $timeout = new NumberDatum($timeout); 88 | if (!(is_object($code) && is_subclass_of($code, "\\r\\Query"))) 89 | $code = new StringDatum($code); 90 | 91 | $this->setPositionalArg(0, $code); 92 | if (isset($timeout)) 93 | $this->setOptionalArg('timeout', $timeout); 94 | } 95 | 96 | protected function getTermType() { 97 | return pb\Term_TermType::PB_JAVASCRIPT; 98 | } 99 | } 100 | 101 | class CoerceTo extends ValuedQuery 102 | { 103 | public function __construct(ValuedQuery $value, $typeName) { 104 | if (!(is_object($typeName) && is_subclass_of($typeName, "\\r\\Query"))) 105 | $typeName = new StringDatum($typeName); 106 | 107 | $this->setPositionalArg(0, $value); 108 | $this->setPositionalArg(1, $typeName); 109 | } 110 | 111 | protected function getTermType() { 112 | return pb\Term_TermType::PB_COERCE_TO; 113 | } 114 | } 115 | 116 | class TypeOf extends ValuedQuery 117 | { 118 | public function __construct(ValuedQuery $value) { 119 | $this->setPositionalArg(0, $value); 120 | } 121 | 122 | protected function getTermType() { 123 | return pb\Term_TermType::PB_TYPE_OF; 124 | } 125 | } 126 | 127 | class Http extends ValuedQuery 128 | { 129 | public function __construct($url, $opts = null) { 130 | $this->setPositionalArg(0, nativeToDatum($url)); 131 | if (isset($opts)) { 132 | foreach ($opts as $opt => $val) { 133 | $this->setOptionalArg($opt, nativeToDatum($val)); 134 | } 135 | } 136 | } 137 | 138 | protected function getTermType() { 139 | return pb\Term_TermType::PB_HTTP; 140 | } 141 | } 142 | 143 | class Range extends ValuedQuery 144 | { 145 | public function __construct($startOrEndValue = null, $endValue = null) { 146 | if (isset($startOrEndValue)) { 147 | $this->setPositionalArg(0, nativeToDatum($startOrEndValue)); 148 | if (isset($endValue)) 149 | $this->setPositionalArg(1, nativeToDatum($endValue)); 150 | } 151 | } 152 | 153 | protected function getTermType() { 154 | return pb\Term_TermType::PB_RANGE; 155 | } 156 | } 157 | 158 | class Changes extends ValuedQuery 159 | { 160 | public function __construct(ValuedQuery $src, $opts = null) { 161 | $this->setPositionalArg(0, $src); 162 | if (isset($opts)) { 163 | foreach ($opts as $opt => $val) { 164 | $this->setOptionalArg($opt, nativeToDatum($val)); 165 | } 166 | } 167 | } 168 | 169 | protected function getTermType() { 170 | return pb\Term_TermType::PB_CHANGES; 171 | } 172 | } 173 | 174 | class ToJsonString extends ValuedQuery 175 | { 176 | public function __construct(ValuedQuery $val) { 177 | $this->setPositionalArg(0, $val); 178 | } 179 | 180 | protected function getTermType() { 181 | return pb\Term_TermType::PB_TO_JSON_STRING; 182 | } 183 | } 184 | 185 | ?> 186 | -------------------------------------------------------------------------------- /rdb2/queries/dates.php: -------------------------------------------------------------------------------- 1 | setPositionalArg(0, $year); 28 | $this->setPositionalArg(1, $month); 29 | $this->setPositionalArg(2, $day); 30 | $this->setPositionalArg(3, $hourOrTimezone); 31 | if (isset($minute)) 32 | $this->setPositionalArg(4, $minute); 33 | if (isset($second)) 34 | $this->setPositionalArg(5, $second); 35 | if (isset($timezone)) 36 | $this->setPositionalArg(6, $timezone); 37 | } 38 | 39 | protected function getTermType() { 40 | return pb\Term_TermType::PB_TIME; 41 | } 42 | } 43 | 44 | class EpochTime extends ValuedQuery 45 | { 46 | public function __construct($epochTime) { 47 | $epochTime = nativeToDatum($epochTime); 48 | 49 | $this->setPositionalArg(0, $epochTime); 50 | } 51 | 52 | protected function getTermType() { 53 | return pb\Term_TermType::PB_EPOCH_TIME; 54 | } 55 | } 56 | 57 | class ToEpochTime extends ValuedQuery 58 | { 59 | public function __construct(ValuedQuery $time) { 60 | $this->setPositionalArg(0, $time); 61 | } 62 | 63 | protected function getTermType() { 64 | return pb\Term_TermType::PB_TO_EPOCH_TIME; 65 | } 66 | } 67 | 68 | class Iso8601 extends ValuedQuery 69 | { 70 | public function __construct($iso8601Date, $opts = null) { 71 | $iso8601Date = nativeToDatum($iso8601Date); 72 | 73 | $this->setPositionalArg(0, $iso8601Date); 74 | if (isset($opts)) { 75 | if (!is_array($opts)) throw new RqlDriverError("opts argument must be an array"); 76 | foreach ($opts as $k => $v) { 77 | $this->setOptionalArg($k, nativeToDatum($v)); 78 | } 79 | } 80 | } 81 | 82 | protected function getTermType() { 83 | return pb\Term_TermType::PB_ISO8601; 84 | } 85 | } 86 | 87 | class ToIso8601 extends ValuedQuery 88 | { 89 | public function __construct(ValuedQuery $time) { 90 | $this->setPositionalArg(0, $time); 91 | } 92 | 93 | protected function getTermType() { 94 | return pb\Term_TermType::PB_TO_ISO8601; 95 | } 96 | } 97 | 98 | class InTimezone extends ValuedQuery 99 | { 100 | public function __construct(ValuedQuery $time, $timezone) { 101 | $timezone = nativeToDatum($timezone); 102 | 103 | $this->setPositionalArg(0, $time); 104 | $this->setPositionalArg(1, $timezone); 105 | } 106 | 107 | protected function getTermType() { 108 | return pb\Term_TermType::PB_IN_TIMEZONE; 109 | } 110 | } 111 | 112 | class Timezone extends ValuedQuery 113 | { 114 | public function __construct(ValuedQuery $time) { 115 | $this->setPositionalArg(0, $time); 116 | } 117 | 118 | protected function getTermType() { 119 | return pb\Term_TermType::PB_TIMEZONE; 120 | } 121 | } 122 | 123 | class During extends ValuedQuery 124 | { 125 | public function __construct(ValuedQuery $time, $startTime, $endTime, $opts = null) { 126 | $startTime = nativeToDatum($startTime); 127 | $endTime = nativeToDatum($endTime); 128 | 129 | $this->setPositionalArg(0, $time); 130 | $this->setPositionalArg(1, $startTime); 131 | $this->setPositionalArg(2, $endTime); 132 | if (isset($opts)) { 133 | if (!is_array($opts)) throw new RqlDriverError("opts argument must be an array"); 134 | foreach ($opts as $k => $v) { 135 | $this->setOptionalArg($k, nativeToDatum($v)); 136 | } 137 | } 138 | } 139 | 140 | protected function getTermType() { 141 | return pb\Term_TermType::PB_DURING; 142 | } 143 | } 144 | 145 | class Date extends ValuedQuery 146 | { 147 | public function __construct(ValuedQuery $time) { 148 | $this->setPositionalArg(0, $time); 149 | } 150 | 151 | protected function getTermType() { 152 | return pb\Term_TermType::PB_DATE; 153 | } 154 | } 155 | 156 | class TimeOfDay extends ValuedQuery 157 | { 158 | public function __construct(ValuedQuery $time) { 159 | $this->setPositionalArg(0, $time); 160 | } 161 | 162 | protected function getTermType() { 163 | return pb\Term_TermType::PB_TIME_OF_DAY; 164 | } 165 | } 166 | 167 | class Year extends ValuedQuery 168 | { 169 | public function __construct(ValuedQuery $time) { 170 | $this->setPositionalArg(0, $time); 171 | } 172 | 173 | protected function getTermType() { 174 | return pb\Term_TermType::PB_YEAR; 175 | } 176 | } 177 | 178 | class Month extends ValuedQuery 179 | { 180 | public function __construct(ValuedQuery $time) { 181 | $this->setPositionalArg(0, $time); 182 | } 183 | 184 | protected function getTermType() { 185 | return pb\Term_TermType::PB_MONTH; 186 | } 187 | } 188 | 189 | class Day extends ValuedQuery 190 | { 191 | public function __construct(ValuedQuery $time) { 192 | $this->setPositionalArg(0, $time); 193 | } 194 | 195 | protected function getTermType() { 196 | return pb\Term_TermType::PB_DAY; 197 | } 198 | } 199 | 200 | class DayOfWeek extends ValuedQuery 201 | { 202 | public function __construct(ValuedQuery $time) { 203 | $this->setPositionalArg(0, $time); 204 | } 205 | 206 | protected function getTermType() { 207 | return pb\Term_TermType::PB_DAY_OF_WEEK; 208 | } 209 | } 210 | 211 | class DayOfYear extends ValuedQuery 212 | { 213 | public function __construct(ValuedQuery $time) { 214 | $this->setPositionalArg(0, $time); 215 | } 216 | 217 | protected function getTermType() { 218 | return pb\Term_TermType::PB_DAY_OF_YEAR; 219 | } 220 | } 221 | 222 | class Hours extends ValuedQuery 223 | { 224 | public function __construct(ValuedQuery $time) { 225 | $this->setPositionalArg(0, $time); 226 | } 227 | 228 | protected function getTermType() { 229 | return pb\Term_TermType::PB_HOURS; 230 | } 231 | } 232 | 233 | class Minutes extends ValuedQuery 234 | { 235 | public function __construct(ValuedQuery $time) { 236 | $this->setPositionalArg(0, $time); 237 | } 238 | 239 | protected function getTermType() { 240 | return pb\Term_TermType::PB_MINUTES; 241 | } 242 | } 243 | 244 | class Seconds extends ValuedQuery 245 | { 246 | public function __construct(ValuedQuery $time) { 247 | $this->setPositionalArg(0, $time); 248 | } 249 | 250 | protected function getTermType() { 251 | return pb\Term_TermType::PB_SECONDS; 252 | } 253 | } 254 | 255 | // Constants 256 | class Monday extends ValuedQuery { 257 | protected function getTermType() { 258 | return pb\Term_TermType::PB_MONDAY; 259 | } 260 | } 261 | class Tuesday extends ValuedQuery { 262 | protected function getTermType() { 263 | return pb\Term_TermType::PB_TUESDAY; 264 | } 265 | } 266 | class Wednesday extends ValuedQuery { 267 | protected function getTermType() { 268 | return pb\Term_TermType::PB_WEDNESDAY; 269 | } 270 | } 271 | class Thursday extends ValuedQuery { 272 | protected function getTermType() { 273 | return pb\Term_TermType::PB_THURSDAY; 274 | } 275 | } 276 | class Friday extends ValuedQuery { 277 | protected function getTermType() { 278 | return pb\Term_TermType::PB_FRIDAY; 279 | } 280 | } 281 | class Saturday extends ValuedQuery { 282 | protected function getTermType() { 283 | return pb\Term_TermType::PB_SATURDAY; 284 | } 285 | } 286 | class Sunday extends ValuedQuery { 287 | protected function getTermType() { 288 | return pb\Term_TermType::PB_SUNDAY; 289 | } 290 | } 291 | 292 | class January extends ValuedQuery { 293 | protected function getTermType() { 294 | return pb\Term_TermType::PB_JANUARY; 295 | } 296 | } 297 | class February extends ValuedQuery { 298 | protected function getTermType() { 299 | return pb\Term_TermType::PB_FEBRUARY; 300 | } 301 | } 302 | class March extends ValuedQuery { 303 | protected function getTermType() { 304 | return pb\Term_TermType::PB_MARCH; 305 | } 306 | } 307 | class April extends ValuedQuery { 308 | protected function getTermType() { 309 | return pb\Term_TermType::PB_APRIL; 310 | } 311 | } 312 | class May extends ValuedQuery { 313 | protected function getTermType() { 314 | return pb\Term_TermType::PB_MAY; 315 | } 316 | } 317 | class June extends ValuedQuery { 318 | protected function getTermType() { 319 | return pb\Term_TermType::PB_JUNE; 320 | } 321 | } 322 | class July extends ValuedQuery { 323 | protected function getTermType() { 324 | return pb\Term_TermType::PB_JULY; 325 | } 326 | } 327 | class August extends ValuedQuery { 328 | protected function getTermType() { 329 | return pb\Term_TermType::PB_AUGUST; 330 | } 331 | } 332 | class September extends ValuedQuery { 333 | protected function getTermType() { 334 | return pb\Term_TermType::PB_SEPTEMBER; 335 | } 336 | } 337 | class October extends ValuedQuery { 338 | protected function getTermType() { 339 | return pb\Term_TermType::PB_OCTOBER; 340 | } 341 | } 342 | class November extends ValuedQuery { 343 | protected function getTermType() { 344 | return pb\Term_TermType::PB_NOVEMBER; 345 | } 346 | } 347 | class December extends ValuedQuery { 348 | protected function getTermType() { 349 | return pb\Term_TermType::PB_DECEMBER; 350 | } 351 | } 352 | 353 | ?> 354 | -------------------------------------------------------------------------------- /rdb2/queries/dbs.php: -------------------------------------------------------------------------------- 1 | setPositionalArg(0, $dbName); 31 | } 32 | 33 | protected function getTermType() { 34 | return pb\Term_TermType::PB_DB; 35 | } 36 | } 37 | 38 | class DbCreate extends ValuedQuery 39 | { 40 | public function __construct($dbName) { 41 | $dbName = nativeToDatum($dbName); 42 | $this->setPositionalArg(0, $dbName); 43 | } 44 | 45 | protected function getTermType() { 46 | return pb\Term_TermType::PB_DB_CREATE; 47 | } 48 | } 49 | 50 | class DbDrop extends ValuedQuery 51 | { 52 | public function __construct($dbName) { 53 | $dbName = nativeToDatum($dbName); 54 | $this->setPositionalArg(0, $dbName); 55 | } 56 | 57 | protected function getTermType() { 58 | return pb\Term_TermType::PB_DB_DROP; 59 | } 60 | } 61 | 62 | class DbList extends ValuedQuery 63 | { 64 | protected function getTermType() { 65 | return pb\Term_TermType::PB_DB_LIST; 66 | } 67 | } 68 | 69 | ?> 70 | -------------------------------------------------------------------------------- /rdb2/queries/geo.php: -------------------------------------------------------------------------------- 1 | setPositionalArg(0, nativeToDatum($geojson)); 7 | } 8 | 9 | protected function getTermType() { 10 | return pb\Term_TermType::PB_GEOJSON; 11 | } 12 | } 13 | 14 | class ToGeoJSON extends ValuedQuery 15 | { 16 | public function __construct($geometry) { 17 | $this->setPositionalArg(0, nativeToDatum($geometry)); 18 | } 19 | 20 | protected function getTermType() { 21 | return pb\Term_TermType::PB_TO_GEOJSON; 22 | } 23 | } 24 | 25 | class Point extends ValuedQuery 26 | { 27 | public function __construct($lat, $lon) { 28 | $this->setPositionalArg(0, nativeToDatum($lat)); 29 | $this->setPositionalArg(1, nativeToDatum($lon)); 30 | } 31 | 32 | protected function getTermType() { 33 | return pb\Term_TermType::PB_POINT; 34 | } 35 | } 36 | 37 | class Line extends ValuedQuery 38 | { 39 | public function __construct($points) { 40 | if (!is_array($points)) { 41 | throw new RqlDriverError("Points must be an array."); 42 | } 43 | $i = 0; 44 | foreach ($points as $point) { 45 | $this->setPositionalArg($i++, nativeToDatum($point)); 46 | } 47 | } 48 | 49 | protected function getTermType() { 50 | return pb\Term_TermType::PB_LINE; 51 | } 52 | } 53 | 54 | class Polygon extends ValuedQuery 55 | { 56 | public function __construct($points) { 57 | if (!is_array($points)) { 58 | throw new RqlDriverError("Points must be an array."); 59 | } 60 | $i = 0; 61 | foreach ($points as $point) { 62 | $this->setPositionalArg($i++, nativeToDatum($point)); 63 | } 64 | } 65 | 66 | protected function getTermType() { 67 | return pb\Term_TermType::PB_POLYGON; 68 | } 69 | } 70 | 71 | class Circle extends ValuedQuery 72 | { 73 | public function __construct($center, $radius, $opts) { 74 | $this->setPositionalArg(0, nativeToDatum($center)); 75 | $this->setPositionalArg(1, nativeToDatum($radius)); 76 | if (isset($opts)) { 77 | if (!is_array($opts)) throw new RqlDriverError("opts argument must be an array"); 78 | foreach ($opts as $k => $v) { 79 | $this->setOptionalArg($k, nativeToDatum($v)); 80 | } 81 | } 82 | } 83 | 84 | protected function getTermType() { 85 | return pb\Term_TermType::PB_CIRCLE; 86 | } 87 | } 88 | 89 | class Intersects extends ValuedQuery 90 | { 91 | public function __construct($g1, $g2) { 92 | $this->setPositionalArg(0, nativeToDatum($g1)); 93 | $this->setPositionalArg(1, nativeToDatum($g2)); 94 | } 95 | 96 | protected function getTermType() { 97 | return pb\Term_TermType::PB_INTERSECTS; 98 | } 99 | } 100 | 101 | class Includes extends ValuedQuery 102 | { 103 | public function __construct($g1, $g2) { 104 | $this->setPositionalArg(0, nativeToDatum($g1)); 105 | $this->setPositionalArg(1, nativeToDatum($g2)); 106 | } 107 | 108 | protected function getTermType() { 109 | return pb\Term_TermType::PB_INCLUDES; 110 | } 111 | } 112 | 113 | class Distance extends ValuedQuery 114 | { 115 | public function __construct($g1, $g2, $opts = null) { 116 | $this->setPositionalArg(0, nativeToDatum($g1)); 117 | $this->setPositionalArg(1, nativeToDatum($g2)); 118 | if (isset($opts)) { 119 | if (!is_array($opts)) throw new RqlDriverError("opts argument must be an array"); 120 | foreach ($opts as $k => $v) { 121 | $this->setOptionalArg($k, nativeToDatum($v)); 122 | } 123 | } 124 | } 125 | 126 | protected function getTermType() { 127 | return pb\Term_TermType::PB_DISTANCE; 128 | } 129 | } 130 | 131 | class GetIntersecting extends ValuedQuery 132 | { 133 | public function __construct(Table $table, $geo, $opts = null) { 134 | $geo = nativeToDatum($geo); 135 | 136 | $this->setPositionalArg(0, $table); 137 | $this->setPositionalArg(1, $geo); 138 | if (isset($opts)) { 139 | if (!is_array($opts)) throw new RqlDriverError("opts argument must be an array"); 140 | foreach ($opts as $k => $v) { 141 | $this->setOptionalArg($k, nativeToDatum($v)); 142 | } 143 | } 144 | } 145 | 146 | protected function getTermType() { 147 | return pb\Term_TermType::PB_GET_INTERSECTING; 148 | } 149 | } 150 | 151 | class GetNearest extends ValuedQuery 152 | { 153 | public function __construct(Table $table, $center, $opts = null) { 154 | $center = nativeToDatum($center); 155 | 156 | $this->setPositionalArg(0, $table); 157 | $this->setPositionalArg(1, $center); 158 | if (isset($opts)) { 159 | if (!is_array($opts)) throw new RqlDriverError("opts argument must be an array"); 160 | foreach ($opts as $k => $v) { 161 | $this->setOptionalArg($k, nativeToDatum($v)); 162 | } 163 | } 164 | } 165 | 166 | protected function getTermType() { 167 | return pb\Term_TermType::PB_GET_NEAREST; 168 | } 169 | } 170 | 171 | class Fill extends ValuedQuery 172 | { 173 | public function __construct($g1) { 174 | $this->setPositionalArg(0, nativeToDatum($g1)); 175 | } 176 | 177 | protected function getTermType() { 178 | return pb\Term_TermType::PB_FILL; 179 | } 180 | } 181 | 182 | class PolygonSub extends ValuedQuery 183 | { 184 | public function __construct($p1, $p2) { 185 | $this->setPositionalArg(0, nativeToDatum($p1)); 186 | $this->setPositionalArg(1, nativeToDatum($p2)); 187 | } 188 | 189 | protected function getTermType() { 190 | return pb\Term_TermType::PB_POLYGON_SUB; 191 | } 192 | } 193 | 194 | ?> 195 | -------------------------------------------------------------------------------- /rdb2/queries/index.php: -------------------------------------------------------------------------------- 1 | setPositionalArg(0, $table); 7 | } 8 | 9 | protected function getTermType() { 10 | return pb\Term_TermType::PB_INDEX_LIST; 11 | } 12 | } 13 | 14 | class IndexCreate extends ValuedQuery 15 | { 16 | public function __construct(Table $table, $indexName, $keyFunction = null, $options = null) { 17 | $indexName = nativeToDatum($indexName); 18 | if (isset($keyFunction)) { 19 | $keyFunction = nativeToFunction($keyFunction); 20 | } 21 | if (isset($options)) { 22 | if (!is_array($options)) throw new RqlDriverError("Options must be an array."); 23 | foreach ($options as $key => &$val) { 24 | if (!is_string($key)) throw new RqlDriverError("Option keys must be strings."); 25 | if (!(is_object($val) && is_subclass_of($val, "\\r\\Query"))) { 26 | $val = nativeToDatum($val); 27 | } 28 | unset($val); 29 | } 30 | } 31 | 32 | $this->setPositionalArg(0, $table); 33 | $this->setPositionalArg(1, $indexName); 34 | if (isset($keyFunction)) 35 | $this->setPositionalArg(2, $keyFunction); 36 | if (isset($options)) { 37 | foreach ($options as $key => $val) { 38 | $this->setOptionalArg($key, $val); 39 | } 40 | } 41 | } 42 | 43 | protected function getTermType() { 44 | return pb\Term_TermType::PB_INDEX_CREATE; 45 | } 46 | } 47 | 48 | class IndexDrop extends ValuedQuery 49 | { 50 | public function __construct(Table $table, $indexName) { 51 | $indexName = nativeToDatum($indexName); 52 | $this->setPositionalArg(0, $table); 53 | $this->setPositionalArg(1, $indexName); 54 | } 55 | 56 | protected function getTermType() { 57 | return pb\Term_TermType::PB_INDEX_DROP; 58 | } 59 | } 60 | 61 | class IndexStatus extends ValuedQuery 62 | { 63 | public function __construct(Table $table, $indexNames = null) { 64 | if (isset($indexNames) && !is_array($indexNames)) $indexNames = array($indexNames); 65 | 66 | $this->setPositionalArg(0, $table); 67 | if (isset($indexNames)) { 68 | $pos = 1; 69 | foreach ($indexNames as $v) { 70 | $this->setPositionalArg($pos++, nativeToDatum($v)); 71 | } 72 | } 73 | } 74 | 75 | protected function getTermType() { 76 | return pb\Term_TermType::PB_INDEX_STATUS; 77 | } 78 | } 79 | 80 | class IndexWait extends ValuedQuery 81 | { 82 | public function __construct(Table $table, $indexNames = null) { 83 | if (isset($indexNames) && !is_array($indexNames)) $indexNames = array($indexNames); 84 | 85 | $this->setPositionalArg(0, $table); 86 | if (isset($indexNames)) { 87 | $pos = 1; 88 | foreach ($indexNames as $v) { 89 | $this->setPositionalArg($pos++, nativeToDatum($v)); 90 | } 91 | } 92 | } 93 | 94 | protected function getTermType() { 95 | return pb\Term_TermType::PB_INDEX_WAIT; 96 | } 97 | } 98 | 99 | ?> 100 | -------------------------------------------------------------------------------- /rdb2/queries/joins.php: -------------------------------------------------------------------------------- 1 | setPositionalArg(0, $sequence); 8 | $this->setPositionalArg(1, $otherSequence); 9 | $this->setPositionalArg(2, $predicate); 10 | } 11 | 12 | protected function getTermType() { 13 | return pb\Term_TermType::PB_INNER_JOIN; 14 | } 15 | } 16 | 17 | class OuterJoin extends ValuedQuery 18 | { 19 | public function __construct(ValuedQuery $sequence, ValuedQuery $otherSequence, $predicate) { 20 | $predicate = nativeToFunction($predicate); 21 | $this->setPositionalArg(0, $sequence); 22 | $this->setPositionalArg(1, $otherSequence); 23 | $this->setPositionalArg(2, $predicate); 24 | } 25 | 26 | protected function getTermType() { 27 | return pb\Term_TermType::PB_OUTER_JOIN; 28 | } 29 | } 30 | 31 | class EqJoin extends ValuedQuery 32 | { 33 | public function __construct(ValuedQuery $sequence, $attribute, ValuedQuery $otherSequence, $opts = null) { 34 | $attribute = nativeToDatumOrFunction($attribute); 35 | $this->setPositionalArg(0, $sequence); 36 | $this->setPositionalArg(1, $attribute); 37 | $this->setPositionalArg(2, $otherSequence); 38 | if (isset($opts)) { 39 | if (!is_array($opts)) throw new RqlDriverError("opts argument must be an array"); 40 | foreach ($opts as $k => $v) { 41 | $this->setOptionalArg($k, nativeToDatum($v)); 42 | } 43 | } 44 | } 45 | 46 | protected function getTermType() { 47 | return pb\Term_TermType::PB_EQ_JOIN; 48 | } 49 | } 50 | 51 | class Zip extends ValuedQuery 52 | { 53 | public function __construct(ValuedQuery $sequence) { 54 | $this->setPositionalArg(0, $sequence); 55 | } 56 | 57 | protected function getTermType() { 58 | return pb\Term_TermType::PB_ZIP; 59 | } 60 | } 61 | 62 | ?> 63 | -------------------------------------------------------------------------------- /rdb2/queries/manipulation.php: -------------------------------------------------------------------------------- 1 | true) from a list of field names such as 9 | // array('a', 'b'). 10 | // Luckily it turns out, that the new interface also supports passing in a plain 11 | // ArrayDatum, which will be interpreted correctly. So we can just always 12 | // interpret arrays as patterns. 13 | 14 | if (!is_array($attributes)) 15 | $attributes = array($attributes); 16 | $attributes = nativeToDatum($attributes); 17 | 18 | $this->setPositionalArg(0, $sequence); 19 | $this->setPositionalArg(1, $attributes); 20 | } 21 | 22 | protected function getTermType() { 23 | return pb\Term_TermType::PB_PLUCK; 24 | } 25 | } 26 | 27 | class Without extends ValuedQuery 28 | { 29 | public function __construct(ValuedQuery $sequence, $attributes) { 30 | // See comment above about pluck. The same applies here. 31 | if (!is_array($attributes)) 32 | $attributes = array($attributes); 33 | $attributes = nativeToDatum($attributes); 34 | 35 | $this->setPositionalArg(0, $sequence); 36 | $this->setPositionalArg(1, $attributes); 37 | } 38 | 39 | protected function getTermType() { 40 | return pb\Term_TermType::PB_WITHOUT; 41 | } 42 | } 43 | 44 | class Merge extends ValuedQuery 45 | { 46 | public function __construct(ValuedQuery $sequence, $other) { 47 | $other = nativeToDatumOrFunction($other); 48 | 49 | $this->setPositionalArg(0, $sequence); 50 | $this->setPositionalArg(1, $other); 51 | } 52 | 53 | protected function getTermType() { 54 | return pb\Term_TermType::PB_MERGE; 55 | } 56 | } 57 | 58 | class Append extends ValuedQuery 59 | { 60 | public function __construct(ValuedQuery $sequence, $value) { 61 | $value = nativeToDatum($value); 62 | 63 | $this->setPositionalArg(0, $sequence); 64 | $this->setPositionalArg(1, $value); 65 | } 66 | 67 | protected function getTermType() { 68 | return pb\Term_TermType::PB_APPEND; 69 | } 70 | } 71 | 72 | class Prepend extends ValuedQuery 73 | { 74 | public function __construct(ValuedQuery $sequence, $value) { 75 | $value = nativeToDatum($value); 76 | 77 | $this->setPositionalArg(0, $sequence); 78 | $this->setPositionalArg(1, $value); 79 | } 80 | 81 | protected function getTermType() { 82 | return pb\Term_TermType::PB_PREPEND; 83 | } 84 | } 85 | 86 | class Difference extends ValuedQuery 87 | { 88 | public function __construct(ValuedQuery $sequence, $value) { 89 | $value = nativeToDatum($value); 90 | 91 | $this->setPositionalArg(0, $sequence); 92 | $this->setPositionalArg(1, $value); 93 | } 94 | 95 | protected function getTermType() { 96 | return pb\Term_TermType::PB_DIFFERENCE; 97 | } 98 | } 99 | 100 | class SetInsert extends ValuedQuery 101 | { 102 | public function __construct(ValuedQuery $sequence, $value) { 103 | $value = nativeToDatum($value); 104 | 105 | $this->setPositionalArg(0, $sequence); 106 | $this->setPositionalArg(1, $value); 107 | } 108 | 109 | protected function getTermType() { 110 | return pb\Term_TermType::PB_SET_INSERT; 111 | } 112 | } 113 | 114 | class SetIntersection extends ValuedQuery 115 | { 116 | public function __construct(ValuedQuery $sequence, $value) { 117 | $value = nativeToDatum($value); 118 | 119 | $this->setPositionalArg(0, $sequence); 120 | $this->setPositionalArg(1, $value); 121 | } 122 | 123 | protected function getTermType() { 124 | return pb\Term_TermType::PB_SET_INTERSECTION; 125 | } 126 | } 127 | 128 | class SetDifference extends ValuedQuery 129 | { 130 | public function __construct(ValuedQuery $sequence, $value) { 131 | $value = nativeToDatum($value); 132 | 133 | $this->setPositionalArg(0, $sequence); 134 | $this->setPositionalArg(1, $value); 135 | } 136 | 137 | protected function getTermType() { 138 | return pb\Term_TermType::PB_SET_DIFFERENCE; 139 | } 140 | } 141 | 142 | class SetUnion extends ValuedQuery 143 | { 144 | public function __construct(ValuedQuery $sequence, $value) { 145 | $value = nativeToDatum($value); 146 | 147 | $this->setPositionalArg(0, $sequence); 148 | $this->setPositionalArg(1, $value); 149 | } 150 | 151 | protected function getTermType() { 152 | return pb\Term_TermType::PB_SET_UNION; 153 | } 154 | } 155 | 156 | class GetField extends ValuedQuery 157 | { 158 | public function __construct(ValuedQuery $sequence, $attribute) { 159 | if (!(is_object($attribute) && is_subclass_of($attribute, "\\r\\Query"))) 160 | $attribute = new StringDatum($attribute); 161 | 162 | $this->setPositionalArg(0, $sequence); 163 | $this->setPositionalArg(1, $attribute); 164 | } 165 | 166 | protected function getTermType() { 167 | return pb\Term_TermType::PB_GET_FIELD; 168 | } 169 | } 170 | 171 | class Bracket extends ValuedQuery 172 | { 173 | public function __construct(ValuedQuery $sequence, $attributeOrIndex) { 174 | if (!(is_object($attributeOrIndex) && is_subclass_of($attributeOrIndex, "\\r\\Query"))) 175 | $attributeOrIndex = nativeToDatum($attributeOrIndex); 176 | 177 | $this->setPositionalArg(0, $sequence); 178 | $this->setPositionalArg(1, $attributeOrIndex); 179 | } 180 | 181 | protected function getTermType() { 182 | return pb\Term_TermType::PB_BRACKET; 183 | } 184 | } 185 | 186 | class HasFields extends ValuedQuery 187 | { 188 | public function __construct(ValuedQuery $sequence, $attributes) { 189 | // See comment above about pluck. The same applies here. 190 | if (is_string($attributes)) 191 | $attributes = array($attributes); 192 | $attributes = nativeToDatum($attributes); 193 | 194 | $this->setPositionalArg(0, $sequence); 195 | $this->setPositionalArg(1, $attributes); 196 | } 197 | 198 | protected function getTermType() { 199 | return pb\Term_TermType::PB_HAS_FIELDS; 200 | } 201 | } 202 | 203 | class InsertAt extends ValuedQuery 204 | { 205 | public function __construct(ValuedQuery $sequence, $index, $value) { 206 | $index = nativeToDatum($index); 207 | $value = nativeToDatum($value); 208 | 209 | $this->setPositionalArg(0, $sequence); 210 | $this->setPositionalArg(1, $index); 211 | $this->setPositionalArg(2, $value); 212 | } 213 | 214 | protected function getTermType() { 215 | return pb\Term_TermType::PB_INSERT_AT; 216 | } 217 | } 218 | 219 | class SpliceAt extends ValuedQuery 220 | { 221 | public function __construct(ValuedQuery $sequence, $index, $value) { 222 | $index = nativeToDatum($index); 223 | $value = nativeToDatum($value); 224 | 225 | $this->setPositionalArg(0, $sequence); 226 | $this->setPositionalArg(1, $index); 227 | $this->setPositionalArg(2, $value); 228 | } 229 | 230 | protected function getTermType() { 231 | return pb\Term_TermType::PB_SPLICE_AT; 232 | } 233 | } 234 | 235 | class DeleteAt extends ValuedQuery 236 | { 237 | public function __construct(ValuedQuery $sequence, $index, $endIndex = null) { 238 | $index = nativeToDatum($index); 239 | if (isset($endIndex)) 240 | $endIndex = nativeToDatum($endIndex); 241 | 242 | 243 | $this->setPositionalArg(0, $sequence); 244 | $this->setPositionalArg(1, $index); 245 | if (isset($endIndex)) { 246 | $this->setPositionalArg(2, $endIndex); 247 | } 248 | } 249 | 250 | protected function getTermType() { 251 | return pb\Term_TermType::PB_DELETE_AT; 252 | } 253 | } 254 | 255 | class ChangeAt extends ValuedQuery 256 | { 257 | public function __construct(ValuedQuery $sequence, $index, $value) { 258 | $index = nativeToDatum($index); 259 | $value = nativeToDatum($value); 260 | 261 | $this->setPositionalArg(0, $sequence); 262 | $this->setPositionalArg(1, $index); 263 | $this->setPositionalArg(2, $value); 264 | } 265 | 266 | protected function getTermType() { 267 | return pb\Term_TermType::PB_CHANGE_AT; 268 | } 269 | } 270 | 271 | class Keys extends ValuedQuery 272 | { 273 | public function __construct(ValuedQuery $sequence) { 274 | $this->setPositionalArg(0, $sequence); 275 | } 276 | 277 | protected function getTermType() { 278 | return pb\Term_TermType::PB_KEYS; 279 | } 280 | } 281 | 282 | 283 | ?> 284 | -------------------------------------------------------------------------------- /rdb2/queries/math.php: -------------------------------------------------------------------------------- 1 | termType = $termType; 9 | 10 | $this->setPositionalArg(0, $value); 11 | $this->setPositionalArg(1, $other); 12 | } 13 | 14 | protected function getTermType() { 15 | return $this->termType; 16 | } 17 | 18 | private $termType; 19 | } 20 | 21 | class Add extends BinaryOp { 22 | public function __construct(ValuedQuery $value, $other) { 23 | parent::__construct(pb\Term_TermType::PB_ADD, $value, $other); 24 | } 25 | } 26 | class Sub extends BinaryOp { 27 | public function __construct(ValuedQuery $value, $other) { 28 | parent::__construct(pb\Term_TermType::PB_SUB, $value, $other); 29 | } 30 | } 31 | class Mul extends BinaryOp { 32 | public function __construct(ValuedQuery $value, $other) { 33 | parent::__construct(pb\Term_TermType::PB_MUL, $value, $other); 34 | } 35 | } 36 | class Div extends BinaryOp { 37 | public function __construct(ValuedQuery $value, $other) { 38 | parent::__construct(pb\Term_TermType::PB_DIV, $value, $other); 39 | } 40 | } 41 | class Mod extends BinaryOp { 42 | public function __construct(ValuedQuery $value, $other) { 43 | parent::__construct(pb\Term_TermType::PB_MOD, $value, $other); 44 | } 45 | } 46 | class RAnd extends BinaryOp { 47 | public function __construct(ValuedQuery $value, $other) { 48 | parent::__construct(pb\Term_TermType::PB_AND, $value, $other); 49 | } 50 | } 51 | class ROr extends BinaryOp { 52 | public function __construct(ValuedQuery $value, $other) { 53 | parent::__construct(pb\Term_TermType::PB_OR, $value, $other); 54 | } 55 | } 56 | class Eq extends BinaryOp { 57 | public function __construct(ValuedQuery $value, $other) { 58 | parent::__construct(pb\Term_TermType::PB_EQ, $value, $other); 59 | } 60 | } 61 | class Ne extends BinaryOp { 62 | public function __construct(ValuedQuery $value, $other) { 63 | parent::__construct(pb\Term_TermType::PB_NE, $value, $other); 64 | } 65 | } 66 | class Gt extends BinaryOp { 67 | public function __construct(ValuedQuery $value, $other) { 68 | parent::__construct(pb\Term_TermType::PB_GT, $value, $other); 69 | } 70 | } 71 | class Ge extends BinaryOp { 72 | public function __construct(ValuedQuery $value, $other) { 73 | parent::__construct(pb\Term_TermType::PB_GE, $value, $other); 74 | } 75 | } 76 | class Lt extends BinaryOp { 77 | public function __construct(ValuedQuery $value, $other) { 78 | parent::__construct(pb\Term_TermType::PB_LT, $value, $other); 79 | } 80 | } 81 | class Le extends BinaryOp { 82 | public function __construct(ValuedQuery $value, $other) { 83 | parent::__construct(pb\Term_TermType::PB_LE, $value, $other); 84 | } 85 | } 86 | 87 | class Not extends ValuedQuery 88 | { 89 | public function __construct(ValuedQuery $value) { 90 | $this->setPositionalArg(0, $value); 91 | } 92 | 93 | protected function getTermType() { 94 | return pb\Term_TermType::PB_NOT; 95 | } 96 | } 97 | 98 | class Match extends ValuedQuery 99 | { 100 | public function __construct(ValuedQuery $value, $expression) { 101 | $expression = nativeToDatum($expression); 102 | 103 | $this->setPositionalArg(0, $value); 104 | $this->setPositionalArg(1, $expression); 105 | } 106 | 107 | protected function getTermType() { 108 | return pb\Term_TermType::PB_MATCH; 109 | } 110 | } 111 | 112 | class Upcase extends ValuedQuery 113 | { 114 | public function __construct(ValuedQuery $value) { 115 | $this->setPositionalArg(0, $value); 116 | } 117 | 118 | protected function getTermType() { 119 | return pb\Term_TermType::PB_UPCASE; 120 | } 121 | } 122 | 123 | class Downcase extends ValuedQuery 124 | { 125 | public function __construct(ValuedQuery $value) { 126 | $this->setPositionalArg(0, $value); 127 | } 128 | 129 | protected function getTermType() { 130 | return pb\Term_TermType::PB_DOWNCASE; 131 | } 132 | } 133 | 134 | class Split extends ValuedQuery 135 | { 136 | public function __construct(ValuedQuery $value, $separator = null, $maxSplits = null) { 137 | $this->setPositionalArg(0, $value); 138 | if (isset($separator) || isset($maxSplits)) { 139 | $this->setPositionalArg(1, nativeToDatum($separator)); 140 | } 141 | if (isset($maxSplits)) { 142 | $this->setPositionalArg(2, nativeToDatum($maxSplits)); 143 | } 144 | } 145 | 146 | protected function getTermType() { 147 | return pb\Term_TermType::PB_SPLIT; 148 | } 149 | } 150 | 151 | class Random extends ValuedQuery 152 | { 153 | public function __construct($left = null, $right = null, $opts = null) { 154 | if (isset($left)) { 155 | $this->setPositionalArg(0, nativeToDatum($left)); 156 | } 157 | if (isset($right)) { 158 | $this->setPositionalArg(1, nativeToDatum($right)); 159 | } 160 | if (isset($opts)) { 161 | foreach ($opts as $opt => $val) { 162 | $this->setOptionalArg($opt, nativeToDatum($val)); 163 | } 164 | } 165 | } 166 | 167 | protected function getTermType() { 168 | return pb\Term_TermType::PB_RANDOM; 169 | } 170 | } 171 | 172 | ?> 173 | -------------------------------------------------------------------------------- /rdb2/queries/misc.php: -------------------------------------------------------------------------------- 1 | 25 | -------------------------------------------------------------------------------- /rdb2/queries/selecting.php: -------------------------------------------------------------------------------- 1 | setPositionalArg(0, $table); 9 | $this->setPositionalArg(1, $key); 10 | } 11 | 12 | protected function getTermType() { 13 | return pb\Term_TermType::PB_GET; 14 | } 15 | } 16 | 17 | class GetAll extends ValuedQuery 18 | { 19 | public function __construct(Table $table, $key, $opts = null) { 20 | $key = nativeToDatum($key); 21 | 22 | $this->setPositionalArg(0, $table); 23 | $this->setPositionalArg(1, $key); 24 | if (isset($opts)) { 25 | if (!is_array($opts)) throw new RqlDriverError("opts argument must be an array"); 26 | foreach ($opts as $k => $v) { 27 | $this->setOptionalArg($k, nativeToDatum($v)); 28 | } 29 | } 30 | } 31 | 32 | protected function getTermType() { 33 | return pb\Term_TermType::PB_GET_ALL; 34 | } 35 | } 36 | 37 | class GetMultiple extends ValuedQuery 38 | { 39 | public function __construct(Table $table, $keys, $opts = null) { 40 | if (!is_array($keys)) throw new RqlDriverError("Keys in GetMultiple must be an array."); 41 | foreach ($keys as &$key) { 42 | $key = nativeToDatum($key); 43 | unset($key); 44 | } 45 | $this->setPositionalArg(0, $table); 46 | $i = 1; 47 | foreach ($keys as $key) { 48 | $this->setPositionalArg($i++, $key); 49 | } 50 | if (isset($opts)) { 51 | if (!is_array($opts)) throw new RqlDriverError("opts argument must be an array"); 52 | foreach ($opts as $k => $v) { 53 | $this->setOptionalArg($k, nativeToDatum($v)); 54 | } 55 | } 56 | } 57 | 58 | protected function getTermType() { 59 | return pb\Term_TermType::PB_GET_ALL; 60 | } 61 | } 62 | 63 | class Between extends ValuedQuery 64 | { 65 | public function __construct(ValuedQuery $selection, $leftBound, $rightBound, $opts = null) { 66 | $leftBound = nativeToDatum($leftBound); 67 | $rightBound = nativeToDatum($rightBound); 68 | 69 | $this->setPositionalArg(0, $selection); 70 | $this->setPositionalArg(1, $leftBound); 71 | $this->setPositionalArg(2, $rightBound); 72 | if (isset($opts)) { 73 | if (!is_array($opts)) throw new RqlDriverError("opts argument must be an array"); 74 | foreach ($opts as $k => $v) { 75 | $this->setOptionalArg($k, nativeToDatum($v)); 76 | } 77 | } 78 | } 79 | 80 | protected function getTermType() { 81 | return pb\Term_TermType::PB_BETWEEN; 82 | } 83 | } 84 | 85 | class Filter extends ValuedQuery 86 | { 87 | public function __construct(ValuedQuery $sequence, $predicate, $default = null) { 88 | $predicate = nativeToDatumOrFunction($predicate); 89 | if (isset($default)) { 90 | $default = nativeToDatum($default); 91 | } 92 | 93 | $this->setPositionalArg(0, $sequence); 94 | $this->setPositionalArg(1, $predicate); 95 | if (isset($default)) 96 | $this->setOptionalArg('default', $default); 97 | } 98 | 99 | protected function getTermType() { 100 | return pb\Term_TermType::PB_FILTER; 101 | } 102 | } 103 | 104 | ?> 105 | -------------------------------------------------------------------------------- /rdb2/queries/tables.php: -------------------------------------------------------------------------------- 1 | setPositionalArg(0, $database); 9 | } 10 | 11 | protected function getTermType() { 12 | return pb\Term_TermType::PB_TABLE_LIST; 13 | } 14 | } 15 | 16 | class TableCreate extends ValuedQuery 17 | { 18 | public function __construct($database, $tableName, $options = null) { 19 | if (isset($database) && !is_a($database, "\\r\\Db")) throw ("Database is not a Db object."); 20 | $tableName = nativeToDatum($tableName); 21 | if (isset($options)) { 22 | if (!is_array($options)) throw new RqlDriverError("Options must be an array."); 23 | foreach ($options as $key => &$val) { 24 | if (!is_string($key)) throw new RqlDriverError("Option keys must be strings."); 25 | if (!(is_object($val) && is_subclass_of($val, "\\r\\Query"))) { 26 | $val = nativeToDatum($val); 27 | } 28 | unset($val); 29 | } 30 | } 31 | 32 | $i = 0; 33 | if (isset($database)) 34 | $this->setPositionalArg($i++, $database); 35 | $this->setPositionalArg($i++, $tableName); 36 | if (isset($options)) { 37 | foreach ($options as $key => $val) { 38 | $this->setOptionalArg($key, $val); 39 | } 40 | } 41 | } 42 | 43 | protected function getTermType() { 44 | return pb\Term_TermType::PB_TABLE_CREATE; 45 | } 46 | } 47 | 48 | class TableDrop extends ValuedQuery 49 | { 50 | public function __construct($database, $tableName) { 51 | if (isset($database) && !is_a($database, "\\r\\Db")) throw ("Database is not a Db object."); 52 | $tableName = nativeToDatum($tableName); 53 | 54 | $i = 0; 55 | if (isset($database)) 56 | $this->setPositionalArg($i++, $database); 57 | $this->setPositionalArg($i++, $tableName); 58 | } 59 | 60 | protected function getTermType() { 61 | return pb\Term_TermType::PB_TABLE_DROP; 62 | } 63 | } 64 | 65 | class Table extends ValuedQuery 66 | { 67 | public function insert($document, $opts = null) { 68 | return new Insert($this, $document, $opts); 69 | } 70 | public function get($key) { 71 | return new Get($this, $key); 72 | } 73 | public function getAll($key, $opts = null) { 74 | return new GetAll($this, $key, $opts); 75 | } 76 | public function getMultiple($keys, $opts = null) { 77 | return new GetMultiple($this, $keys, $opts); 78 | } 79 | public function getIntersecting($geo, $opts = null) { 80 | return new GetIntersecting($this, $geo, $opts); 81 | } 82 | public function getNearest($center, $opts = null) { 83 | return new GetNearest($this, $center, $opts); 84 | } 85 | public function sync() { 86 | return new Sync($this); 87 | } 88 | public function indexCreate($indexName, $keyFunction = null) { 89 | return new IndexCreate($this, $indexName, $keyFunction); 90 | } 91 | public function indexCreateMulti($indexName, $keyFunction = null) { 92 | return new IndexCreate($this, $indexName, $keyFunction, array('multi' => true)); 93 | } 94 | public function indexCreateGeo($indexName, $keyFunction = null) { 95 | return new IndexCreate($this, $indexName, $keyFunction, array('geo' => true)); 96 | } 97 | public function indexCreateMultiGeo($indexName, $keyFunction = null) { 98 | return new IndexCreate($this, $indexName, $keyFunction, array('multi' => true, 'geo' => true)); 99 | } 100 | public function indexDrop($indexName) { 101 | return new IndexDrop($this, $indexName); 102 | } 103 | public function indexList() { 104 | return new IndexList($this); 105 | } 106 | public function indexStatus($indexNames = null) { 107 | return new IndexStatus($this, $indexNames); 108 | } 109 | public function indexWait($indexNames = null) { 110 | return new IndexWait($this, $indexNames); 111 | } 112 | public function wait($opts = null) { 113 | return new Wait($this, $opts); 114 | } 115 | public function reconfigure($opts = null) { 116 | return new Reconfigure($this, $opts); 117 | } 118 | public function rebalance() { 119 | return new Rebalance($this); 120 | } 121 | public function config() { 122 | return new Config($this); 123 | } 124 | public function status() { 125 | return new Status($this); 126 | } 127 | 128 | 129 | public function __construct($database, $tableName, $useOutdatedOrOpts = null) { 130 | if (isset($database) && !is_a($database, "\\r\\Db")) throw ("Database is not a Db object."); 131 | $tableName = nativeToDatum($tableName); 132 | if (isset($useOutdated) && !is_bool($useOutdated)) throw new RqlDriverError("Use outdated must be bool."); 133 | 134 | $i = 0; 135 | if (isset($database)) 136 | $this->setPositionalArg($i++, $database); 137 | $this->setPositionalArg($i++, $tableName); 138 | if (isset($useOutdatedOrOpts)) { 139 | if (is_bool($useOutdatedOrOpts)) { 140 | $this->setOptionalArg('use_outdated', new BoolDatum($useOutdatedOrOpts)); 141 | } else { 142 | foreach ($useOutdatedOrOpts as $opt => $val) { 143 | $this->setOptionalArg($opt, nativeToDatum($val)); 144 | } 145 | } 146 | } 147 | } 148 | 149 | protected function getTermType() { 150 | return pb\Term_TermType::PB_TABLE; 151 | } 152 | } 153 | 154 | class Wait extends ValuedQuery 155 | { 156 | public function __construct(Query $tables, $opts = null) { 157 | $this->setPositionalArg(0, $tables); 158 | if (isset($opts)) { 159 | foreach ($opts as $opt => $val) { 160 | $this->setOptionalArg($opt, nativeToDatum($val)); 161 | } 162 | } 163 | } 164 | 165 | protected function getTermType() { 166 | return pb\Term_TermType::PB_WAIT; 167 | } 168 | } 169 | 170 | class Reconfigure extends ValuedQuery 171 | { 172 | public function __construct(Query $tables, $opts = null) { 173 | $this->setPositionalArg(0, $tables); 174 | if (isset($opts)) { 175 | foreach ($opts as $opt => $val) { 176 | $this->setOptionalArg($opt, nativeToDatum($val)); 177 | } 178 | } 179 | } 180 | 181 | protected function getTermType() { 182 | return pb\Term_TermType::PB_RECONFIGURE; 183 | } 184 | } 185 | 186 | class Rebalance extends ValuedQuery 187 | { 188 | public function __construct(Query $tables) { 189 | $this->setPositionalArg(0, $tables); 190 | } 191 | 192 | protected function getTermType() { 193 | return pb\Term_TermType::PB_REBALANCE; 194 | } 195 | } 196 | 197 | class Config extends ValuedQuery 198 | { 199 | public function __construct(Table $table) { 200 | $this->setPositionalArg(0, $table); 201 | } 202 | 203 | protected function getTermType() { 204 | return pb\Term_TermType::PB_CONFIG; 205 | } 206 | } 207 | 208 | class Status extends ValuedQuery 209 | { 210 | public function __construct(Table $table) { 211 | $this->setPositionalArg(0, $table); 212 | } 213 | 214 | protected function getTermType() { 215 | return pb\Term_TermType::PB_STATUS; 216 | } 217 | } 218 | 219 | ?> 220 | -------------------------------------------------------------------------------- /rdb2/queries/transformations.php: -------------------------------------------------------------------------------- 1 | setPositionalArg(0, $sequence); 12 | $this->setPositionalArg(1, $attributes); 13 | } 14 | 15 | protected function getTermType() { 16 | return pb\Term_TermType::PB_WITH_FIELDS; 17 | } 18 | } 19 | 20 | class Map extends ValuedQuery 21 | { 22 | public function __construct(ValuedQuery $sequence, $mappingFunction) { 23 | $mappingFunction = nativeToFunction($mappingFunction); 24 | 25 | $this->setPositionalArg(0, $sequence); 26 | $this->setPositionalArg(1, $mappingFunction); 27 | } 28 | 29 | protected function getTermType() { 30 | return pb\Term_TermType::PB_MAP; 31 | } 32 | } 33 | 34 | class MapMultiple extends ValuedQuery 35 | { 36 | public function __construct(ValuedQuery $sequence, $moreSequences, $mappingFunction) { 37 | if (!is_array($moreSequences)) 38 | $moreSequences = array($moreSequences); 39 | $mappingFunction = nativeToFunction($mappingFunction); 40 | 41 | $this->setPositionalArg(0, $sequence); 42 | $i = 1; 43 | foreach ($moreSequences as $seq) { 44 | $this->setPositionalArg($i++, $seq); 45 | } 46 | $this->setPositionalArg($i, $mappingFunction); 47 | } 48 | 49 | protected function getTermType() { 50 | return pb\Term_TermType::PB_MAP; 51 | } 52 | } 53 | 54 | class ConcatMap extends ValuedQuery 55 | { 56 | public function __construct(ValuedQuery $sequence, $mappingFunction) { 57 | $mappingFunction = nativeToFunction($mappingFunction); 58 | 59 | $this->setPositionalArg(0, $sequence); 60 | $this->setPositionalArg(1, $mappingFunction); 61 | } 62 | 63 | protected function getTermType() { 64 | return pb\Term_TermType::PB_CONCAT_MAP; 65 | } 66 | } 67 | 68 | class OrderBy extends ValuedQuery 69 | { 70 | public function __construct(ValuedQuery $sequence, $keys) { 71 | if (!is_array($keys)) 72 | $keys = array($keys); 73 | // Check keys and convert strings 74 | if (isset($keys['index'])) { 75 | $this->setOptionalArg('index', nativeToDatum($keys['index'])); 76 | unset($keys['index']); 77 | } 78 | foreach ($keys as &$val) { 79 | if (!(is_object($val) && is_subclass_of($val, "\\r\\Ordering"))) { 80 | $val = nativeToDatumOrFunction($val); 81 | } 82 | unset($val); 83 | } 84 | 85 | $this->setPositionalArg(0, $sequence); 86 | $i = 1; 87 | foreach ($keys as $key) { 88 | $this->setPositionalArg($i++, $key); 89 | } 90 | } 91 | 92 | protected function getTermType() { 93 | return pb\Term_TermType::PB_ORDER_BY; 94 | } 95 | } 96 | 97 | class Skip extends ValuedQuery 98 | { 99 | public function __construct(ValuedQuery $sequence, $n) { 100 | $n = nativeToDatum($n); 101 | 102 | $this->setPositionalArg(0, $sequence); 103 | $this->setPositionalArg(1, $n); 104 | } 105 | 106 | protected function getTermType() { 107 | return pb\Term_TermType::PB_SKIP; 108 | } 109 | } 110 | 111 | class Limit extends ValuedQuery 112 | { 113 | public function __construct(ValuedQuery $sequence, $n) { 114 | $n = nativeToDatum($n); 115 | 116 | $this->setPositionalArg(0, $sequence); 117 | $this->setPositionalArg(1, $n); 118 | } 119 | 120 | protected function getTermType() { 121 | return pb\Term_TermType::PB_LIMIT; 122 | } 123 | } 124 | 125 | class Slice extends ValuedQuery 126 | { 127 | public function __construct(ValuedQuery $sequence, $startIndex, $endIndex = null, $opts = null) { 128 | $startIndex = nativeToDatum($startIndex); 129 | if (isset($endIndex)) 130 | $endIndex = nativeToDatum($endIndex); 131 | 132 | $this->setPositionalArg(0, $sequence); 133 | $this->setPositionalArg(1, $startIndex); 134 | if (isset($endIndex)) { 135 | $this->setPositionalArg(2, $endIndex); 136 | } else { 137 | $this->setPositionalArg(2, new NumberDatum(-1)); 138 | $this->setOptionalArg('right_bound', new StringDatum('closed')); 139 | } 140 | if (isset($opts)) { 141 | if (!is_array($opts)) throw new RqlDriverError("opts argument must be an array"); 142 | foreach ($opts as $k => $v) { 143 | $this->setOptionalArg($k, nativeToDatum($v)); 144 | } 145 | } 146 | } 147 | 148 | protected function getTermType() { 149 | return pb\Term_TermType::PB_SLICE; 150 | } 151 | } 152 | 153 | class Nth extends ValuedQuery 154 | { 155 | public function __construct(ValuedQuery $sequence, $index) { 156 | $index = nativeToDatum($index); 157 | 158 | $this->setPositionalArg(0, $sequence); 159 | $this->setPositionalArg(1, $index); 160 | } 161 | 162 | protected function getTermType() { 163 | return pb\Term_TermType::PB_NTH; 164 | } 165 | } 166 | 167 | class OffsetsOf extends ValuedQuery 168 | { 169 | public function __construct(ValuedQuery $sequence, $predicate) { 170 | $predicate = nativeToDatumOrFunction($predicate); 171 | 172 | $this->setPositionalArg(0, $sequence); 173 | $this->setPositionalArg(1, $predicate); 174 | } 175 | 176 | protected function getTermType() { 177 | return pb\Term_TermType::PB_OFFSETS_OF; 178 | } 179 | } 180 | 181 | class IsEmpty extends ValuedQuery 182 | { 183 | public function __construct(ValuedQuery $sequence) { 184 | $this->setPositionalArg(0, $sequence); 185 | } 186 | 187 | protected function getTermType() { 188 | return pb\Term_TermType::PB_IS_EMPTY; 189 | } 190 | } 191 | 192 | class Union extends ValuedQuery 193 | { 194 | public function __construct(ValuedQuery $sequence, ValuedQuery $otherSequence) { 195 | $this->setPositionalArg(0, $sequence); 196 | $this->setPositionalArg(1, $otherSequence); 197 | } 198 | 199 | protected function getTermType() { 200 | return pb\Term_TermType::PB_UNION; 201 | } 202 | } 203 | 204 | class Sample extends ValuedQuery 205 | { 206 | public function __construct(ValuedQuery $sequence, $n) { 207 | $n = nativeToDatum($n); 208 | 209 | $this->setPositionalArg(0, $sequence); 210 | $this->setPositionalArg(1, $n); 211 | } 212 | 213 | protected function getTermType() { 214 | return pb\Term_TermType::PB_SAMPLE; 215 | } 216 | } 217 | 218 | ?> 219 | -------------------------------------------------------------------------------- /rdb2/queries/writing.php: -------------------------------------------------------------------------------- 1 | setPositionalArg(0, $table); 17 | $this->setPositionalArg(1, $document); 18 | if (isset($opts)) { 19 | foreach ($opts as $opt => $val) { 20 | $this->setOptionalArg($opt, nativeToDatum($val)); 21 | } 22 | } 23 | } 24 | 25 | protected function getTermType() { 26 | return pb\Term_TermType::PB_INSERT; 27 | } 28 | } 29 | 30 | class Update extends ValuedQuery 31 | { 32 | public function __construct(ValuedQuery $selection, $delta, $opts = null) { 33 | if (isset($opts) && !\is_array($opts)) throw new RqlDriverError("Options must be an array."); 34 | if (!(is_object($delta) && is_subclass_of($delta, "\\r\\Query"))) { 35 | try { 36 | $json = tryEncodeAsJson($delta); 37 | if ($json !== false) { 38 | $delta = new Json($json); 39 | } else { 40 | $delta = nativeToDatum($delta); 41 | } 42 | } catch (RqlDriverError $e) { 43 | $delta = nativeToFunction($delta); 44 | } 45 | } 46 | $delta = wrapImplicitVar($delta); 47 | 48 | $this->setPositionalArg(0, $selection); 49 | $this->setPositionalArg(1, $delta); 50 | if (isset($opts)) { 51 | foreach ($opts as $opt => $val) { 52 | $this->setOptionalArg($opt, nativeToDatum($val)); 53 | } 54 | } 55 | } 56 | 57 | protected function getTermType() { 58 | return pb\Term_TermType::PB_UPDATE; 59 | } 60 | } 61 | 62 | class Delete extends ValuedQuery 63 | { 64 | public function __construct(ValuedQuery $selection, $opts = null) { 65 | if (isset($opts) && !\is_array($opts)) throw new RqlDriverError("Options must be an array."); 66 | 67 | $this->setPositionalArg(0, $selection); 68 | 69 | if (isset($opts)) { 70 | foreach ($opts as $opt => $val) { 71 | $this->setOptionalArg($opt, nativeToDatum($val)); 72 | } 73 | } 74 | } 75 | 76 | protected function getTermType() { 77 | return pb\Term_TermType::PB_DELETE; 78 | } 79 | } 80 | 81 | class Replace extends ValuedQuery 82 | { 83 | public function __construct(ValuedQuery $selection, $delta, $opts) { 84 | if (isset($opts) && !\is_array($opts)) throw new RqlDriverError("Options must be an array."); 85 | if (!(is_object($delta) && is_subclass_of($delta, "\\r\\Query"))) { 86 | // If we can make it an object, we will wrap that object into a function. 87 | // Otherwise, we will try to make it a function. 88 | try { 89 | $json = tryEncodeAsJson($delta); 90 | if ($json !== false) { 91 | $delta = new Json($json); 92 | } else { 93 | $delta = nativeToDatum($delta); 94 | } 95 | } catch (RqlDriverError $e) { 96 | $delta = nativeToFunction($delta); 97 | } 98 | } 99 | $delta = wrapImplicitVar($delta); 100 | 101 | $this->setPositionalArg(0, $selection); 102 | $this->setPositionalArg(1, $delta); 103 | if (isset($opts)) { 104 | foreach ($opts as $opt => $val) { 105 | $this->setOptionalArg($opt, nativeToDatum($val)); 106 | } 107 | } 108 | } 109 | 110 | protected function getTermType() { 111 | return pb\Term_TermType::PB_REPLACE; 112 | } 113 | } 114 | 115 | class Sync extends ValuedQuery 116 | { 117 | public function __construct(Table $table) { 118 | $this->setPositionalArg(0, $table); 119 | } 120 | 121 | protected function getTermType() { 122 | return pb\Term_TermType::PB_SYNC; 123 | } 124 | } 125 | 126 | ?> 127 | -------------------------------------------------------------------------------- /rdb2/rdb.php: -------------------------------------------------------------------------------- 1 | 24 | -------------------------------------------------------------------------------- /rdb2/util.php: -------------------------------------------------------------------------------- 1 | frames = array(); 9 | foreach ($backtrace as $frame) 10 | $result->frames[] = Frame::_fromJSON($frame); 11 | return $result; 12 | } 13 | 14 | // Returns true if no more frames are available 15 | public function _consumeFrame() { 16 | if (\count($this->frames) == 0) return false; 17 | $frame = $this->frames[0]; 18 | $this->frames = array_slice($this->frames, 1); 19 | return $frame; 20 | } 21 | 22 | private $frames = null; 23 | } 24 | 25 | class Frame 26 | { 27 | static public function _fromJSON($frame) { 28 | $result = new Frame(); 29 | if (is_string($frame)) { 30 | $result->isOptionalArg = true; 31 | $result->optionalArgName = $frame; 32 | } else { 33 | $result->isPositionalArg = true; 34 | $result->positionalArgPosition = $frame; 35 | } 36 | 37 | return $result; 38 | } 39 | public function isPositionalArg() { return $this->isPositionalArg; } 40 | public function isOptionalArg() { return $this->isOptionalArg; } 41 | public function getOptionalArgName() { return $this->optionalArgName; } 42 | public function getPositionalArgPosition() { return $this->positionalArgPosition; } 43 | 44 | private $isPositionalArg = false; 45 | private $isOptionalArg = false; 46 | private $optionalArgName = null; 47 | private $positionalArgPosition = null; 48 | } 49 | 50 | // ------------- RethinkDB Exceptions ------------- 51 | class RqlDriverError extends \Exception 52 | { 53 | public function __construct($message, $code = 0) { 54 | parent::__construct($message, $code); 55 | } 56 | 57 | public function __toString() { 58 | return "RqlDriverError:\n " . $this->getMessage() . "\n"; 59 | } 60 | } 61 | 62 | class RqlServerError extends \Exception 63 | { 64 | public function __construct($message, $query = null, $backtrace = null, $code = 0) { 65 | $this->query = $query; 66 | $this->backtrace = $backtrace; 67 | parent::__construct($message, $code); 68 | } 69 | 70 | public function __toString() { 71 | return "RqlServerError:\n " . $this->getMessage() . "\n" . $this->getBacktraceString(); 72 | } 73 | 74 | public function getBacktraceString() { 75 | $result = ""; 76 | if (isset($this->query)) { 77 | $result .= " Failed query:\n"; 78 | $nullBacktrace = null; 79 | $result .= " " . $this->query->_toString($nullBacktrace) . "\n"; 80 | if (isset($this->backtrace)) { 81 | $backtraceCopy = $this->backtrace; 82 | $result .= " " . $this->query->_toString($backtraceCopy) . "\n"; 83 | } 84 | } 85 | return $result; 86 | } 87 | 88 | private $query; 89 | private $backtrace; 90 | } 91 | 92 | ?> 93 | -------------------------------------------------------------------------------- /rdb2/version.php: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /safereval/class.safereval.php: -------------------------------------------------------------------------------- 1 | allowedCalls = $allowedCalls; 21 | $this->allowedTokens = $allowedTokens; 22 | $this->globalVariables = $globalVariables; 23 | $this->allowedVariables = $allowedVariables; 24 | $this->disallowedExpressions = $disallowedExpressions; 25 | } 26 | 27 | function evalSyntax($code) { // Separate function for checking syntax without breaking the script 28 | ob_start(); // Catch potential parse error messages 29 | $code = eval('if(0){' . "\n" . $code . "\n" . '}'); // Put $code in a dead code sandbox to prevent its execution 30 | ob_end_clean(); 31 | return $code !== false; 32 | } 33 | 34 | function checkScript($code, $execute) { 35 | $this->execute = $execute; 36 | $this->code = $code; 37 | $this->tokens = token_get_all('code.' ?>'); 38 | $this->errors = array(); 39 | $this->braces = 0; 40 | 41 | // STEP 1: SYNTAX - Check if braces are balanced 42 | foreach ($this->tokens as $token) { 43 | if ($token == '{') $this->braces = $this->braces + 1; 44 | else if ($token == '}') $this->braces = $this->braces - 1; 45 | if ($this->braces < 0) { // Closing brace before one is open 46 | $this->errors[0]['name'] = 'Syntax error.'; 47 | break; 48 | } 49 | } 50 | 51 | if (empty($this->errors)) { 52 | if ($this->braces) $this->errors[0]['name'] = 'Unbalanced braces.'; 53 | } 54 | 55 | // STEP 2: SYNTAX - Check if syntax is valid 56 | else if (!$this->evalSyntax($this->code)) { 57 | $this->errors[0]['name'] = 'Syntax error.'; 58 | } 59 | 60 | // STEP 3: EXPRESSIONS - Check against various insecure elements 61 | if (empty($this->errors)) foreach ($this->disallowedExpressions as $disallowedExpression) { 62 | unset($matches); 63 | preg_match($disallowedExpression, $this->code, $matches); 64 | if($matches) { 65 | $this->errors[0]['name'] = 'Execution operator / variable function name / variable variable name detected.'; 66 | break; 67 | } 68 | } 69 | 70 | // STEP 4: TOKENS 71 | if(empty($this->errors)) { 72 | unset($this->tokens[0]); 73 | unset($this->tokens[0]); 74 | array_pop($this->tokens); 75 | array_pop($this->tokens); 76 | 77 | $i = 0; 78 | $test = $this->allowedVariables; 79 | foreach ($this->tokens as $key => $token) { 80 | $i++; 81 | if (is_array($token)) { 82 | $id = token_name($token[0]); 83 | switch ($id) { 84 | case('T_VARIABLE'): 85 | if(sizeof($test)==0){ 86 | $this->allowedVariables[] = "$".$token[1]; 87 | //$this->globalVariables[] = $token[1]; 88 | }else{ 89 | if (in_array($token[1], $this->allowedVariables) === false) { 90 | $this->errors[$i]['name'] = 'Illegal variable: ' . $token[1]; 91 | $this->errors[$i]['line'] = $token[2]; 92 | } 93 | } 94 | break; 95 | case('T_STRING'): 96 | if (in_array($token[1], $this->allowedCalls) === false) { 97 | $this->errors[$i]['name'] = 'Illegal function: ' . $token[1]; 98 | $this->errors[$i]['line'] = $token[2]; 99 | } 100 | break; 101 | default: 102 | if (in_array($id, $this->allowedTokens) === false) { 103 | $this->errors[$i]['name'] = 'Illegal token: ' . $token[1]; 104 | $this->errors[$i]['line'] = $token[2]; 105 | } 106 | break; 107 | } 108 | } 109 | } 110 | } 111 | 112 | if(!empty($this->errors)) { 113 | return $this->errors; 114 | } else if ($this->execute) { 115 | foreach ($this->globalVariables as $globalVariable) { 116 | global $$globalVariable; 117 | } 118 | eval($this->code); 119 | } 120 | } 121 | 122 | function htmlErrors ($errors = null) { 123 | if ($errors) { 124 | $this->errors = $errors; 125 | $this->errorsHTML = '

Errors:

'; 126 | $this->errorsHTML .= '
'; 127 | foreach ($this->errors as $error) { 128 | if ($error['line']) { 129 | $this->errorsHTML .= '
Line '.$error['line'].'
'; 130 | } 131 | $this->errorsHTML .= '
'.$error['name'].'
'; 132 | } 133 | $this->errorsHTML .= '
'; 134 | return($this->errorsHTML); 135 | } 136 | } 137 | } 138 | 139 | ?> -------------------------------------------------------------------------------- /safereval/config.safereval.php: -------------------------------------------------------------------------------- 1 | " 392 | 'T_AND_EQUAL', // assignment operators 393 | 'T_ARRAY', // array(), array syntax 394 | 'T_ARRAY_CAST', // type-casting 395 | 'T_AS', // foreach 396 | 'T_BOOLEAN_AND', // logical operators 397 | 'T_BOOLEAN_OR', // logical operators 398 | 'T_BOOL_CAST', // type-casting 399 | 'T_BREAK', // break 400 | 'T_CASE', // switch 401 | 'T_CHARACTER', // ? 402 | // 'T_COMMENT', // comments 403 | 'T_CONCAT_EQUAL', // assignment operators 404 | 'T_CONSTANT_ENCAPSED_STRING', // string syntax 405 | 'T_CONTINUE', // 406 | 'T_CURLY_OPEN', // 407 | 'T_DEC', // incrementing/decrementing operators 408 | 'T_DECLARE', // declare 409 | 'T_DEFAULT', // switch 410 | 'T_DIV_EQUAL', // assignment operators 411 | 'T_DNUMBER', // floating point numbers 412 | 'T_DO', // do..while 413 | 'T_DOUBLE_ARROW', // array syntax 414 | 'T_DOUBLE_CAST', // type-casting 415 | // 'T_ECHO', // 416 | 'T_ELSE', // else 417 | 'T_ELSEIF', // elseif 418 | 'T_EMPTY', // empty() 419 | 'T_ENCAPSED_AND_WHITESPACE', // ? 420 | 'T_ENDDECLARE', // declare, alternative syntax 421 | 'T_ENDFOR', // for, alternative syntax 422 | 'T_ENDFOREACH', // foreach, alternative syntax 423 | 'T_ENDIF', // if, alternative syntax 424 | 'T_ENDSWITCH', // switch, alternative syntax 425 | 'T_FOR', // for 426 | 'T_FOREACH', // foreach 427 | 'T_IF', // if 428 | 'T_INC', // incrementing/decrementing operators 429 | 'T_INT_CAST', // type-casting 430 | 'T_ISSET', // isset() 431 | 'T_IS_EQUAL', // comparison operators 432 | 'T_IS_GREATER_OR_EQUAL', // comparison operators 433 | 'T_IS_IDENTICAL', // comparison operators 434 | 'T_IS_NOT_EQUAL', // comparison operators 435 | 'T_IS_NOT_IDENTICAL', // comparison operators 436 | 'T_IS_SMALLER_OR_EQUAL', // comparison operators 437 | 'T_LNUMBER', // integers 438 | 'T_LOGICAL_AND', // logical operators 439 | 'T_LOGICAL_OR', // logical operators 440 | 'T_LOGICAL_XOR', // logical operators 441 | 'T_MINUS_EQUAL', // assignment operators 442 | // 'T_ML_COMMENT', // comments (PHP 4 only) 443 | 'T_MOD_EQUAL', // assignment operators 444 | 'T_MUL_EQUAL', // assignment operators 445 | 'T_NUM_STRING', // ? 446 | 'T_OR_EQUAL', // assignment operators 447 | 'T_PLUS_EQUAL', // assignment operators 448 | 'T_RETURN', // returning values 449 | 'T_SL', // bitwise operators 450 | 'T_SL_EQUAL', // assignment operators 451 | 'T_SR', // bitwise operators 452 | 'T_SR_EQUAL', // assignment operators 453 | 'T_STRING', // ? 454 | 'T_STRING_CAST', // type-casting 455 | 'T_STRING_VARNAME', // ? 456 | 'T_SWITCH', // switch 457 | 'T_UNSET', // unset() 458 | 'T_UNSET_CAST', // (not documented; casts to NULL) 459 | 'T_VARIABLE', // variables 460 | 'T_WHILE', // while, do..while 461 | 'T_WHITESPACE', // 462 | 'T_XOR_EQUAL', // assignment operators 463 | ); 464 | 465 | $disallowedExpressions = array ( // Probably unsafe to change these 466 | 467 | '/`/', // Shell execution operator: "`" 468 | '/\$\W/', // Variable variables: any "$" which is not "$_" or "$alphanumeric" 469 | '/(\]|\})\s*\(/', // Variable functions: "] (" or "} (" 470 | '/\$\w\w*\s*\(/', // Variable functions: "$_ (" or "$alphanumeric" 471 | // '/\$\w\w*\s*(\/\/|\/\*)/', // Comment after variable: "$alphanumeric //" or "$alphanumeric /*" 472 | // '/(\]|\})\s*\//', // Comment after parentheses: "] /" or "} /" 473 | 474 | ); 475 | 476 | ?> 477 | -------------------------------------------------------------------------------- /src/check_json.php: -------------------------------------------------------------------------------- 1 | true); 3 | if(!json_decode($_REQUEST["json_text"])){ 4 | $result = array("valid_json"=>false); 5 | } 6 | echo json_encode($result); 7 | ?> -------------------------------------------------------------------------------- /src/connect_db.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/databases.php: -------------------------------------------------------------------------------- 1 | run($conn); 5 | //$new_database = $new_database->toNative(); 6 | if($new_database["dbs_created"]>0){ 7 | ?> 8 |

Database created successfully!

9 | 12 |

Error occurred

13 | run($conn); 20 | //$drop_database = $drop_database->toNative(); 21 | if($drop_database["dbs_dropped"]>0){ 22 | ?> 23 |

Database dropped successfully!

24 | 27 |

Error occurred

28 | 37 | 58 | 61 | 82 | 83 |

Databases ()

84 | 85 | + new database 86 |
87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | run($conn); 98 | //$databases = $databases->toNative(); 99 | foreach($databases as $database){ 100 | ?> 101 | 102 | 103 | 104 | 105 | 106 | 109 | 110 | 111 |
Name  
drop
112 |
113 | -------------------------------------------------------------------------------- /src/doc.php: -------------------------------------------------------------------------------- 1 | table($_REQUEST["table"])->get($_REQUEST["doc"])->replace($json_array)->run($conn); 8 | //$update = $update->toNative(); 9 | if($update["replaced"]>0){ 10 | ?> 11 |

Doc updated successfully!

12 | 15 |

Error occurred

16 | table($_REQUEST["table"])->insert($json_array)->run($conn); 27 | //$insert = $insert->toNative(); 28 | if($insert["inserted"]>0){ 29 | ?> 30 |

Doc inserted successfully!

31 | 34 |

Error occurred

35 | 45 |

/

46 |

47 | New DocDoc ()

53 | 54 | table($_REQUEST["table"])->get($_REQUEST["doc"])->run($conn); 58 | //$doc = $doc->toNative(); 59 | $json_text = json_encode($doc,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES| JSON_PRETTY_PRINT); 60 | } 61 | ?> 62 | 72 | 98 |
&table=&doc=&action="> 104 |
105 | 106 | 107 |
108 | valid 109 |
110 |
111 | 112 |
-------------------------------------------------------------------------------- /src/docs.php: -------------------------------------------------------------------------------- 1 | table($_REQUEST["table"])->get($_REQUEST["doc"])->delete()->run($conn); 5 | //$delete = $delete->toNative(); 6 | if($delete["deleted"]>0){ 7 | ?> 8 |

Doc deleted successfully!

9 | 12 |

Error occurred

13 | 17 | 22 |

//Docs

23 | 24 | &table=&doc=new" class="btn btn-primary" role="button">+ new doc 25 |
26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | table($_REQUEST["table"])->run($conn); 48 | //$docs = $docs->toNative(); 49 | foreach($docs as $doc){ 50 | //$doc = first_keys($doc); 51 | $doc_text = json_encode($doc,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); 52 | //$doc_text = substr(str_replace('"{..}"','{..}',$doc_text),0,100); 53 | //$doc_text = str_replace('"{..}"','{..}',$doc_text); 54 | ?> 55 | 56 | 57 | 58 | 59 | 60 | 63 | 64 | 65 |
Name  
&table=&doc=" class="btn btn-info" role="button">Edit&table=&doc=&action=delete_doc" class="btn btn-danger" role="button">delete
66 |
67 | -------------------------------------------------------------------------------- /src/query.php: -------------------------------------------------------------------------------- 1 | 8 | 16 | 17 |

18 | PHP Query: 19 |

20 |
21 | query history 22 |
23 | 24 |
query=true&action=run"> 25 | 29 |
30 | 34 |
35 | 38 |
39 | 40 |
41 | 42 |
43 | 44 | $v) { 47 | if ($k !== $v) 48 | return true; 49 | } 50 | return false; 51 | } 52 | 53 | if(isset($_REQUEST["action"])) 54 | if(($_REQUEST["action"]=="run")){ 55 | $result = array(); 56 | try { 57 | set_time_limit(30); 58 | $command = $_REQUEST["query_text"]; 59 | $command = trim($command); 60 | if($command!==''){ 61 | 62 | //save query on memory 63 | $_SESSION["query_history"][] = $command; 64 | 65 | //use default user db connection 66 | if(isset($_REQUEST["use_db"])) 67 | $conn->useDb($_REQUEST["database"]); 68 | 69 | //#################EVAL################### 70 | //I'm having problems using safereval 71 | /* 72 | $se = new SaferEval(); 73 | $errors = $se->checkScript($command, 1); 74 | if ($errors) print_r($se->htmlErrors($errors)); 75 | */ 76 | 77 | //use EVAL function for your own risk 78 | eval($command); 79 | //######################################## 80 | 81 | /*if(method_exists($result,"toNative")){ 82 | $result = $result->toNative(); 83 | }*/ 84 | $resultArray = []; 85 | if(is_a($result,"ArrayObject")){ 86 | $resultArray = $result; 87 | }else{ 88 | if(is_array($result)||is_object($result)){ 89 | foreach ($result as $value) { 90 | $resultArray[] = $value; 91 | } 92 | } 93 | else{ 94 | $resultArray = $result; 95 | } 96 | } 97 | 98 | $header = []; 99 | $resultArrayTables = $resultArray; 100 | if(is_array($resultArray)){ 101 | foreach ($resultArray as $row) { 102 | $header = array_keys((array)$row) + $header; 103 | } 104 | }else{ 105 | $header = array_keys((array)$resultArray); 106 | $resultArrayTables = [0=>$resultArray]; 107 | } 108 | ?> 109 | 114 | 115 |
116 |
117 |

Json

118 |
119 |
120 | 143 | 166 |
167 | 174 | 175 | 176 | 208 | 209 | -------------------------------------------------------------------------------- /src/tables.php: -------------------------------------------------------------------------------- 1 | table($_REQUEST["old_table_name"])->config()->update(array("name"=>$_REQUEST["new_table_name"]))->run($conn); 5 | //$rename_table = $rename_table->toNative(); 6 | if($rename_table["replaced"]>0){ 7 | ?> 8 |

Table renamed successfully!

9 | 12 |

Error occurred

13 | tableCreate($_REQUEST["table_name"])->run($conn); 20 | //$new_table = $new_table->toNative(); 21 | if($new_table["tables_created"]>0){ 22 | ?> 23 |

Table created successfully!

24 | 27 |

Error occurred

28 | tableDrop($_REQUEST["table"])->run($conn); 35 | //$drop_table = $drop_table->toNative(); 36 | if($drop_table["tables_dropped"]>0){ 37 | ?> 38 |

Table dropped successfully!

39 | 42 |

Error occurred

43 | 48 | 56 | 57 | 78 | 79 | 80 | 81 | 82 | 104 | 105 | 106 |

/Tables

107 | 108 | + new table 109 |
110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | tableList()->run($conn); 121 | //$tables = $tables->toNative(); 122 | foreach($tables as $table){ 123 | ?> 124 | 125 | 126 | 127 | 128 | 129 | 132 | 133 |
Name  
&table=">rename&table=&action=drop_table" class="btn btn-danger" role="button">drop
134 |
--------------------------------------------------------------------------------