From da133651e8982cc668d0b831009488d1a4a40e12 Mon Sep 17 00:00:00 2001 From: Bingo Date: Tue, 10 May 2022 23:42:02 +0800 Subject: [PATCH] feat community query --- dao/mysql/community.go | 18 ++++++++++++++++++ logic/community.go | 11 +++++++++++ 2 files changed, 29 insertions(+) create mode 100644 dao/mysql/community.go create mode 100644 logic/community.go diff --git a/dao/mysql/community.go b/dao/mysql/community.go new file mode 100644 index 0000000..6fb4566 --- /dev/null +++ b/dao/mysql/community.go @@ -0,0 +1,18 @@ +package mysql + +import ( + "Goi/models" + "database/sql" + "go.uber.org/zap" +) + +func GetCommunityList() (communityList []*models.Community, err error) { + sqlStr := "select community_id, community_name from community" + if err := db.Select(&communityList, sqlStr); err != nil { + if err == sql.ErrNoRows { + zap.L().Warn("there is no community in db") + err = nil + } + } + return +} diff --git a/logic/community.go b/logic/community.go new file mode 100644 index 0000000..a7e2a17 --- /dev/null +++ b/logic/community.go @@ -0,0 +1,11 @@ +package logic + +import ( + "Goi/dao/mysql" + "Goi/models" +) + +func GetCommunityList() ([]*models.Community, error) { + // 查数据库 查找到所有的community 并返回 + return mysql.GetCommunityList() +}