cms wing低代码平台浅尝

313 阅读2分钟

安装

1.克隆项目

git clone https://gitee.com/cmswing/CmsWing.git
或
git clone https://github.com/arterli/CmsWing.git

2.命令行进入项目根目录安装

cd CmsWing # 项目文件名
npm install

3.关联数据库

// app/config/sequelize.js
{
	dialect: 'mysql',
	host: '127.0.0.1',
	port: 3306,
	database: 'cmswing2',
	username: 'root',
	password: 'root123456',
}
// 先创建数据库,然后把数据库配置文件的信息修改成你实际的数据库信息。

4.启动项目

npm run dev

5.本地启动项目地址

地址:http://127.0.0.1:7001/  
账号:admin  
密码:123456

建表

cms wing建表很简单,进入模型管理页面,点击新增模型,输入模块名称模块描述,然后点击提交,表就创建出来了

image.png

进入填写表字段页面,点击新增添加数据库表需要的字段,然后点击提交,表所需要的字段也更新出来了

image.png

基本操作

查询

query {
  Topic_findAndCountAll(where: {id: {op_eq: 1}}, limit: 1, offset: 0) {
    count
    rows {
      id
      name
      content
    }
  }
}

创建

mutation {
  TopicType_create(data: { name: "王者荣耀", content: "中国No1", icon: "https://appdown.baidu.com/img/0/512_512/244d263299e954004a6475b171586157.png" }) {
    name
    content
    icon
  }
}

更新

mutation {
  TopicType_update(data: { content: "中国No2" }, where: { id: {op_eq: 1 } }) {
    ids
  }
}

删除

mutation {
  TopicType_destroy(where: { id: { op_eq: 2 } }) {
    count
  }
}

多表关联查询

以话题功能为例

一般话题都会被被划为各种分类

所以存在多对多的关系,所以需要一个话题表,一个话题分类表,但是两张表是没有办法通过graphql语法进行查询的,需要一张表将话题和分类关联起来,就叫话题分类关联表

  1. 如果是用cms wing来做的话,首先创建三张表

image.png

2.话题分类关联表需要存在两个字段分别指向话题表id话题分类表id,通过关联将三张表联系在一起

image.png

3.cms wing生成接口之后,通过下面graphql的语法就可以多表关联查询了

query ($id: ID!) {
  Topic_findAndCountAll(where: {id: {op_eq: $id}}, limit: 1, offset: 0) {
    count
    rows {
      id
      name
      content
      pictures
      topic_type_relevance {
        id
        topic_type {
          id
          name
          content
          icon
        }
      }
    }
  }
}