vitess.io/vitess@v0.16.2/examples/demo/index.js (about)

     1  /*
     2   * Copyright 2019 The Vitess Authors.
     3  
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7  
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9  
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  'use strict';
    17  
    18  function DemoController($scope, $http) {
    19  
    20    function init() {
    21      $scope.samples = [
    22        "insert into product(pname) values ('monitor'), ('keyboard')",
    23        "select * from product /* pass-through to unsharded keyspace */",
    24        "--",
    25        "insert into customer(uname) values('alice'),('bob'),('charlie'),('dan'),('eve') /* multi-shard insert */",
    26        "select * from customer where customer_id=1 /* use hash vindex */",
    27        "select * from customer where uname='bob' /* scatter */",
    28        "update customer set customer_id=10 where customer_id=1 /* error: cannot change primary vindex column */",
    29        "delete from customer where uname='eve' /* scatter DML */",
    30        "--",
    31        "insert into corder(customer_id, product_id, oname) values (1,1,'gift'),(1,2,'gift'),(2,1,'work'),(3,2,'personal'),(4,1,'personal') /* orders are grouped with their customer, observe lookup table changes */",
    32        "select * from corder where customer_id=1 /* single-shard select */",
    33        "select * from corder where corder_id=1 /* use unique lookup */",
    34        "select * from corder where oname='gift' /* use non-unique lookup, also try with 'work' and 'personal' */",
    35        "select c.uname, o.oname, o.product_id from customer c join corder o on c.customer_id = o.customer_id where c.customer_id=1 /* local join */",
    36        "select c.uname, o.oname, o.product_id from customer c join corder o on c.customer_id = o.customer_id /* scatter local join */",
    37        "select c.uname, o.oname, p.pname from customer c join corder o on c.customer_id = o.customer_id join product p on o.product_id = p.product_id /* cross-shard join */",
    38        "delete from corder where corder_id=3 /* delete also deletes lookup entries */",
    39        "--",
    40        "insert into corder_event(corder_id, ename) values(1, 'paid'), (5, 'delivered') /* automatic population of keyspace_id */",
    41      ];
    42      $scope.submitQuery()
    43    }
    44  
    45    $scope.submitQuery = function() {
    46      try {
    47        $http({
    48            method: 'POST',
    49            url: '/exec',
    50            data: "query=" + $scope.query,
    51            headers: {
    52              'Content-Type': 'application/x-www-form-urlencoded'
    53            }
    54        }).success(function(data, status, headers, config) {
    55          $scope.result = angular.fromJson(data);
    56        });
    57      } catch (err) {
    58        $scope.result.error = err.message;
    59      }
    60    };
    61  
    62    $scope.setQuery = function($query) {
    63      $scope.query = $query;
    64      angular.element("#query_input").focus();
    65    };
    66  
    67    init();
    68  }