Giter Club home page Giter Club logo

escapade's Introduction

暂定名:Escapade

任意端发送给服务端查询数据库(0.x.x版本暂定MYSQL)

不限定发送端和接受端的语言,这里只是给出协议规定。

暂定:

1.X端向服务端发送http协议 json格式,发送body(dataType:"json")
2.服务端只输出json格式。

设计: 假设我要操作数据库某个表,向后端发送,

{
Action:"Select",                 
From:"table",                     
Fields:"id,make,model",
Limit:"5,10",
Sort:[{by:"id",order:"ASC"},{by:"make","order":desc}],  
Where:[{logic:"and",fields:"id",vaule:1234,perator:"Gte" }],
Group:{by:"model"},
}
字段名 可能的值 说明
Action "Select" 执行动作,查询(Select),更新(Update),Delete(删除)
From "table" 要操作的表名字
Fields "id","make","model" 显示那些字段 (没想好:匹配所有字段怎么办 ,例如:[" * "]
Limit "5,10" 读取条数,从哪个开始到哪里结束
Sort [{by:"id",order:"ASC"},{by:"name","order":desc}] 按照哪个字段排序Asc为正序,Desc为倒序
Where [{logic:"and",fields:"id",vaule:1234,perator:"Gte" },{logic:"and",fields:"make",vaule:"aaa",make:"aaa",perator:"Eq" }] 过滤条件,相当于where 1=1 and id=1233
Group {by:"model"} 过滤条件,相当于SELECT * FROM table GROUP BY model;
Filter where,include 过滤条件
Filter.where {"logic":"and","id":1234,perator:"eq" } 字段条件(看下面的操作符)
****Filter.include {"posts":"authorPointer"} 关系数据(没想好怎么关联)

[where]字段条件操作符(暂定):

操作符 说明
And 逻辑与
Or 逻辑或
Eq/NotEq 等于/不等于
Gt/Gte 大于(>),大于或等于(> =)。只有效数值和日期值
Lt/Lte 小于(<),小于或等于(< =)。只有效数值和日期值
Between 在…之间
NotNull/Null {"logic":"and","Fields":"name",perator:"Null" } 过滤条件,相当于where name IS NOT NULL
Like/NotLike Where:{NotLike:"%王%",Fields:"name"} where name not like '%王%'
*inq,nin 在/不在一个数组之内

DEMO:

<!DOCTYPE html> 
<html > 
  <head> 
    <meta charset="UTF-8"> 
    <title>anchor</title> 

  </head> 
  <body > 
获取表名字为TableE666的,所有字段的数据
  </body> 
</html> 
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
var data = {
Action:"Select",                 
From:"table",                     
fields:["*"],     
}

$.ajax({  

url:"/restful/test.php",

type:"post",  

dataType:"json",  

data:JSON.stringify(data),  

headers: {'Content-Type': 'application/json'},  

success: function (ret) {    
console.log(ret)

}
})   

</script>

假设数据库表名为:"table",结构为:

id name
1 第一组数据
2 第二组数据

后端返回:

{
   datalist:[
      {
         id:1,
         name:"第一组数据"
      },
      {
         id:2,
         name:"第二组数据"
      }
   ], 
}

代码实现(后端PHP,数据库Mysql)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.