sqler 在10前发布了,2.2 添加了定时任务以及触发器(webhook),都是比较方便的功能,
同时我也修改了dockerfile, 做了构建,添加了功能支持,同时push 到了dockerhub 仓库

使用

  • docker-compose 文件
    集成了一个测试webhook benthos
 
version: "3"
services:
  sqler:
    image: dalongrong/sqler:2.2
    volumes:
    - "./config/config-2-2-example.hcl:/app/config.example.hcl"
    environment:
    - "DSN=root:dalongrong@tcp(mysqldb:3306)/test?multiStatements=true"
    ports:
    - "3678:3678"
    - "8025:8025"
  benthos:
    image: jeffail/benthos
    volumes:
    - "./configs/webhook.yaml:/benthos.yaml"
    ports:
    - "4195:4195"
  mysqldb:
    image: mysql:5.7.16
    ports:
      - 3306:3306
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    environment:
      MYSQL_ROOT_PASSWORD: dalongrong
      MYSQL_DATABASE: test
      MYSQL_USER: test
      MYSQL_PASSWORD: test
      TZ: Asia/Shanghai
  • benthos webhook 配置
input:
  type: broker
  broker:
    inputs:
      - type: http_server
        http_server:
          path: /post/customer1
        processors:
          - type: text
            text:
              operator: prepend
              value: "Customer 1 received: "
      - type: http_server
        http_server:
          path: /post/customer2
        processors:
          - type: text
            text:
              operator: prepend
              value: "Customer 2 received: "
      - type: http_server
        http_server:
          path: /post/customer3
        processors:
          - type: text
            text:
              operator: prepend
              value: "Customer 3 received: "
output:
  type: stdout
 
 
  • 参考配置文件
// create a macro/endpoint called "_boot",
// this macro is private "used within other macros" 
// because it starts with "_".
_boot {
    // the query we want to execute
    exec = <<SQL
        CREATE TABLE IF NOT EXISTS datax (
            ID INT PRIMARY KEY,
            data TEXT DEFAULT NULL
        );
    SQL
}
addpost {
    include = ["_boot"]
    methods = ["POST"]
    // validators {
    // title_is_empty = "$input.title && $input.title.trim().length > 0"
    // content_is_empty = "$input.content"
    // }
    bind {
        data = <<JS
            JSON.stringify({
                "title": $input.title,
                "content": $input.content
            })
        JS
    }
    exec = <<SQL
        INSERT INTO datax(ID, data) VALUES(default, :data) RETURNING id, data;
    SQL
}
// adduser macro/endpoint, just hit `/adduser` with
// a `?user_name=&user_email=` or json `POST` request
// with the same fields.
adduser {
    validators {
        user_name_is_empty = "$input.user_name && $input.user_name.trim().length > 0"
        user_email_is_empty = "$input.user_email && $input.user_email.trim().length > 0"
        user_password_is_not_ok = "$input.user_password && $input.user_password.trim().length > 5"
    }
    bind {
        name = "$input.user_name"
        email = "$input.user_email"
        password = "$input.user_password"
    }
    methods = ["POST"]
    authorizer = <<JS
        (function(){
            log("use this for debugging")
            token = $input.http_authorization
            response = fetch("http://requestbin.fullcontact.com/zxpjigzx", {
                headers: {
                    "Authorization": token
                }
            })
            if ( response.statusCode != 200 ) {
                return false
            }
            return true
        })()
    JS
    // include some macros we declared before
    include = ["_boot"]
    exec = <<SQL
        INSERT INTO users(name, email, password, time) VALUES(:name, :email, :password, UNIX_TIMESTAMP());
        SELECT * FROM users WHERE id = LAST_INSERT_ID();
    SQL
}
// list all databases, and run a transformer function
databases {
    // include = ["_boot"]
    exec = "SHOW DATABASES"
    transformer = <<JS
        (function(){
            // $result
            $new = [];
            for ( i in $result ) {
                $new.push($result[i].Database)
            }
            return $new
        })()
    JS
}
// list all tables from all databases
tables {
    exec = "SELECT `table_name` as `table`, `table_schema` as `database` FROM INFORMATION_SCHEMA.tables"
    transformer = <<SQL
        (function(){
            $ret = []
            for ( i in $result ){
                $ret.push({
                    table: $result[i].table,
                    database: $result[i].database,
                })
            }
            return $ret
        })()
    SQL
}
data {
    bind {
        limit = 2
        field = "'id'"
    }
    exec = "SELECT id FROM data limit 5"
}
// a macro that aggregates `databases` macro and `tables` macro into one macro
databases_tables {
    aggregate = ["databases", "tables"]
}
_sqlite_tables {
    exec = <<SQL
    SELECT 
        name
    FROM 
        userinfos;
    SQL
    cron = "* * * * *"
    trigger {
        webhook = "http://benthos:4195/post/customer1"
    }
}

启动&&测试

  • 启动
docker-compose up -d
  • 准备测试数据表
    参考如下脚本添加(主要测试定时任务以及webhook)
 
CREATE TABLE `userinfos` (
  `id` bigint(20) DEFAULT NULL,
  `name` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT INTO test.userinfos
(id, name)
VALUES(1, 'dalong'); 
  • 效果
    查看benthos 容器日志
docker-compose logs -f benthos

效果

sqler 日志

参考资料

https://github.com/alash3al/sqler
https://github.com/rongfengliang/sqler-docker-compose
https://github.com/Jeffail/benthos

sqler 2.2 发布了,支持定时任务以及触发器的更多相关文章

  1. Ranorex 5 发布,支持SAP、Oracle Forms、MS Dynamics等

    Ranorex 5 发布,支持SAP.Oracle Forms.MS Dynamics等 http://blog.csdn.net/testing_is_believing/article/detai ...

  2. CentOS 7 ARM 版发布:支持树莓派2/香蕉派/CubieTruck

    CentOS 7 ARM 版发布:支持树莓派2/香蕉派/CubieTruck 来自CentOS团队的Karanbir Singh很高兴地宣布,面向ARM硬件架构的CentOS 7 Linux已经正式发 ...

  3. [转]Ubuntu Tweak 0.8.7 发布:支持 Ubuntu 14.04

    原文网址:http://www.oschina.net/news/51054/ubuntu-tweak-0-8-7 这是我开发 Ubuntu Tweak 七年以来第一次没在 Ubuntu 正式发布之前 ...

  4. Selenium WebDriver 2.34.0 发布,支持Firefox22

    Selenium WebDriver 2.34.0 发布,支持Firefox22http://automationqa.com/forum.php?mod=viewthread&tid=270 ...

  5. ArcGIS图框工具5.2发布,支持ArcGIS10.0,10.110.2,支持国家2000坐标系

    ArcGIS图框工具5.2发布,支持ArcGIS10.0,10.110.2,支持国家2000坐标系 下载地址http://files.cnblogs.com/gisoracle/atktoolnew. ...

  6. swoole-1.7.18 版本已发布,支持 PHP7

    swoole-1.7.18 版本已发布,支持 PHP7 matyhtf 发布于: 2015年07月23日 (22评) 分享到:    收藏 +16 3月19日,深圳源创会火热报名中,go>> ...

  7. PostSharp-5.0.26安装包_KeyGen发布_支持VS2017

    PostSharp-5.0.26安装包_KeyGen发布_支持VS2017 请低调使用. PostSharp安装及注册步骤截图.rar 请把浏览器主页设置为以下地址支持本人.https://www.d ...

  8. Akka.NET v1.0 已发布,支持Mono

    Akka.NET 是Java/Scala 流行框架Akka的一个 .NET 开源移植.可用于构建高并发,分布式和容错事件驱动的应用在 .NET 和 Mono 平台之上.Akka.NET 经过一年多的努 ...

  9. EQueue 2.3.2版本发布(支持高可用)

    前言 前段时间针对EQueue的完善终于告一段落了,实在值得庆祝,自己的付出和坚持总算有了成果.这次新版本主要为EQueue实现了集群功能,基本实现了Broker的高可用.另外还增加了很多实用的功能, ...

随机推荐

  1. [NewLife.XCode]角色权限

    NewLife.XCode是一个有10多年历史的开源数据中间件,支持nfx/netcore,由新生命团队(2002~2019)开发完成并维护至今,以下简称XCode. 整个系列教程会大量结合示例代码和 ...

  2. webpack-dev-server 不是内部或外部命令,也不是可运行的程序 解决方案

    我看了网上的 一些解决方案,说是webpack版本不对,但我按照提示操作后依然不行: 要先确认是否安装了webpack-dev-server,如果没有安装,安装便可以解决: 粗暴的解决方案是删除nod ...

  3. windowsServer ------ 安装IIS

    1.找到服务器管理器,点击添加角色,一步步执行 2.添加IIS 相关组件 勾选web服务器 下一步 将web服务iis 相关组件全部勾选,ftp 可不选 选择好后安装 等一会 关闭 可以查看到所安装角 ...

  4. java jdb

    https://stackoverflow.com/questions/8155253/how-do-i-compile-in-debug-mode-netbeans-java-maven <p ...

  5. 云原生生态周报 Vol. 12 | K8s 1.16 API 重大变更

    本文作者:源三.临石.张磊.莫源 业界要闻 1. K8s 1.16 将废弃一系列旧的 API 版本 影响面涉及 NetworkPolicy.PodSecurityPolicy.DaemonSet, D ...

  6. Kubernetes 有状态与无状态介绍

    Kubernetes 有状态与无状态介绍 无状态:deployment - 认为所有pod都是一样的,不具备与其他实例有不同的关系. - 没有顺序的要求. - 不用考虑再哪个Node运行. - 随意扩 ...

  7. Kafka 2.3 Producer (0.9以后版本适用)

    kafka0.9版本以后用java重新编写了producer,废除了原来scala编写的版本. 这里直接使用最新2.3版本,0.9以后的版本都适用. 注意引用的包为:org.apache.kafka. ...

  8. Window权限维持(十):Netsh Helper DLL

    Netsh是Windows实用程序,管理员可以使用它来执行与系统的网络配置有关的任务,并在基于主机的Windows防火墙上进行修改.可以通过使用DLL文件来扩展Netsh功能.此功能使红队可以使用此工 ...

  9. 【UOJ#76】【UR #6】懒癌(动态规划)

    [UOJ#76][UR #6]懒癌(动态规划) 题面 UOJ 题解 神....神仙题. 先考虑如果是完全图怎么做... 因为是完全图,所以是对称的,所以我们只考虑一个有懒癌的人的心路历程. 如果只有一 ...

  10. NLP第一课(我也是才开始学)

    闲着无聊的时候,我就会问问自己,编程也有了五年经验了,除了增删改查,我还会什么,有一天我跳槽,去面试的时候,我能比那些年轻而且期望薪资待遇低的年轻毕业生,我有什么优势,而且我只是一个专科的机电系学生, ...