zoukankan      html  css  js  c++  java
  • sqler sql 转rest api 数据校验的处理

    早期版本(2.0 之前)使用rules 进行数据校验处理,2.0 之后进行了修改使用
    validators,这样更加明确

    参考格式

     
    addpost {
        // if any rule returns false, 
        // SQLer will return 422 code, with invalid rules.
        // 
        // $input is a global variable holds all request inputs,
        // including the http headers too (prefixed with `http_`)
        // all http header keys are normalized to be in this form 
        // `http_x_header_example`, `http_authorization` ... etc in lower case.
        validators {
            post_title_length = "$input.post_title && $input.post_title.trim().length > 0"
            post_content_length = "$input.post_content && $input.post_content.length > 0"
            post_user = "$input.post_user"
        }
        bind {
            title = "$input.post_title"
            content = "$input.post_content"
            user_id = "$input.post_user"
        }
        exec = <<SQL
            INSERT INTO posts(user_id, title, content) VALUES(:user_id, :title, :content);
            SELECT * FROM posts WHERE id = LAST_INSERT_ID();
        SQL
    }
     
     

    参考资料

    https://github.com/alash3al/sqler

  • 相关阅读:
    vue中的具名插槽
    vue中默认插槽slot
    局部组件使用指令-方法-过滤器-计算属性
    vue创建局部组件
    Class Metaprogramming
    Attribute Descriptors
    Dynamic Attributes and Properties
    Concurrency with asyncio
    Concurrency with Futures
    Coroutines
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/10265418.html
Copyright © 2011-2022 走看看