zoukankan      html  css  js  c++  java
  • sqler sql 转rest api 数据聚合操作

    sqler 2.0 提供了一个新的指令aggregate,注意这个和sql 的聚合函数不是一个概念,这个只是为了
    方便api数据的拼接

    参考格式

     
    databases {
        exec = "SHOW DATABASES"
        transformer = <<JS
            // there is a global variable called `$result`,
            // `$result` holds the result of the sql execution.
            (function(){
                newResult = []
                for ( i in $result ) {
                    newResult.push($result[i].Database)
                }
                return newResult
            })()
        JS
    }
    tables {
        exec = "SELECT `table_schema` as `database`, `table_name` as `table` FROM INFORMATION_SCHEMA.tables"
        transformer = <<JS
            (function(){
                $ret = {}
                for ( i in $result ) {
                    if ( ! $ret[$result[i].database] ) {
                        $ret[$result[i].database] = [];
                    }
                    $ret[$result[i].database].push($result[i].table)
                }
                return $ret
            })()
        JS
    }
    databasesAndTables {
        aggregate {
            databases = "current_databases"
            tables = "current_tables"
        }
    }
     

    参考资料

    https://github.com/alash3al/sqler

  • 相关阅读:
    [HAOI2008]下落的圆盘
    10.2 上午 考试
    10.1 考试 ..........
    9.29 考试
    博弈论笔记
    bzoj_1022: [SHOI2008]小约翰的游戏John
    课程总结第十五周
    团队冲刺第二阶段09
    团队冲刺第二阶段08
    对搜狗输入法的评价
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/10265432.html
Copyright © 2011-2022 走看看