Procházet zdrojové kódy

[fix]连接数据库,生成dao层代码

Zhangzhenhua před 2 týdny
rodič
revize
2092a79484

+ 16 - 0
api/v1/v1.go

@@ -0,0 +1,16 @@
+// =================================================================================
+// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
+// =================================================================================
+
+package v1
+
+import (
+	"context"
+
+	"cris/api/v1/common"
+)
+
+type IV1Common interface {
+	Chat(ctx context.Context, req *common.ChatReq) (res *common.ChatRes, err error)
+	Login(ctx context.Context, req *common.LoginReq) (res *common.LoginRes, err error)
+}

+ 2 - 3
hack/config.yaml

@@ -1,13 +1,12 @@
-
 # CLI tool, only in development environment.
 # https://goframe.org/docs/cli
 gfcli:
   gen:
     dao:
-      - link: "mysql:root:12345678@tcp(127.0.0.1:3306)/test"
+      - link: "mysql:root:zhang1027.@tcp(47.99.88.76:3306)/gf_demo"
         descriptionTag: true
 
   docker:
     build: "-a amd64 -s linux -p temp -ew"
     tagPrefixes:
-      - my.image.pub/my-app
+      - my.image.pub/my-app

+ 5 - 0
internal/controller/v1/v1.go

@@ -0,0 +1,5 @@
+// =================================================================================
+// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
+// =================================================================================
+
+package v1

+ 14 - 0
internal/controller/v1/v1_common_chat.go

@@ -0,0 +1,14 @@
+package v1
+
+import (
+	"context"
+
+	"github.com/gogf/gf/v2/errors/gcode"
+	"github.com/gogf/gf/v2/errors/gerror"
+
+	"cris/api/v1/common"
+)
+
+func (c *ControllerCommon) Chat(ctx context.Context, req *common.ChatReq) (res *common.ChatRes, err error) {
+	return nil, gerror.NewCode(gcode.CodeNotImplemented)
+}

+ 14 - 0
internal/controller/v1/v1_common_login.go

@@ -0,0 +1,14 @@
+package v1
+
+import (
+	"context"
+
+	"github.com/gogf/gf/v2/errors/gcode"
+	"github.com/gogf/gf/v2/errors/gerror"
+
+	"cris/api/v1/common"
+)
+
+func (c *ControllerCommon) Login(ctx context.Context, req *common.LoginReq) (res *common.LoginRes, err error) {
+	return nil, gerror.NewCode(gcode.CodeNotImplemented)
+}

+ 15 - 0
internal/controller/v1/v1_new.go

@@ -0,0 +1,15 @@
+// =================================================================================
+// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
+// =================================================================================
+
+package v1
+
+import (
+	"cris/api/v1"
+)
+
+type ControllerCommon struct{}
+
+func NewCommon() v1.IV1Common {
+	return &ControllerCommon{}
+}

+ 93 - 0
internal/dao/internal/orders.go

@@ -0,0 +1,93 @@
+// ==========================================================================
+// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
+// ==========================================================================
+
+package internal
+
+import (
+	"context"
+
+	"github.com/gogf/gf/v2/database/gdb"
+	"github.com/gogf/gf/v2/frame/g"
+)
+
+// OrdersDao is the data access object for the table orders.
+type OrdersDao struct {
+	table   string        // table is the underlying table name of the DAO.
+	group   string        // group is the database configuration group name of the current DAO.
+	columns OrdersColumns // columns contains all the column names of Table for convenient usage.
+}
+
+// OrdersColumns defines and stores column names for the table orders.
+type OrdersColumns struct {
+	Id              string //
+	UserId          string //
+	OrderNumber     string //
+	Status          string //
+	TotalAmount     string //
+	CreatedAt       string //
+	UpdatedAt       string //
+	ShippedAt       string //
+	DeliveredAt     string //
+	PaymentStatus   string //
+	ShippingAddress string //
+}
+
+// ordersColumns holds the columns for the table orders.
+var ordersColumns = OrdersColumns{
+	Id:              "id",
+	UserId:          "user_id",
+	OrderNumber:     "order_number",
+	Status:          "status",
+	TotalAmount:     "total_amount",
+	CreatedAt:       "created_at",
+	UpdatedAt:       "updated_at",
+	ShippedAt:       "shipped_at",
+	DeliveredAt:     "delivered_at",
+	PaymentStatus:   "payment_status",
+	ShippingAddress: "shipping_address",
+}
+
+// NewOrdersDao creates and returns a new DAO object for table data access.
+func NewOrdersDao() *OrdersDao {
+	return &OrdersDao{
+		group:   "default",
+		table:   "orders",
+		columns: ordersColumns,
+	}
+}
+
+// DB retrieves and returns the underlying raw database management object of the current DAO.
+func (dao *OrdersDao) DB() gdb.DB {
+	return g.DB(dao.group)
+}
+
+// Table returns the table name of the current DAO.
+func (dao *OrdersDao) Table() string {
+	return dao.table
+}
+
+// Columns returns all column names of the current DAO.
+func (dao *OrdersDao) Columns() OrdersColumns {
+	return dao.columns
+}
+
+// Group returns the database configuration group name of the current DAO.
+func (dao *OrdersDao) Group() string {
+	return dao.group
+}
+
+// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
+func (dao *OrdersDao) Ctx(ctx context.Context) *gdb.Model {
+	return dao.DB().Model(dao.table).Safe().Ctx(ctx)
+}
+
+// Transaction wraps the transaction logic using function f.
+// It rolls back the transaction and returns the error if function f returns a non-nil error.
+// It commits the transaction and returns nil if function f returns nil.
+//
+// Note: Do not commit or roll back the transaction in function f,
+// as it is automatically handled by this function.
+func (dao *OrdersDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
+	return dao.Ctx(ctx).Transaction(ctx, f)
+}

+ 85 - 0
internal/dao/internal/user.go

@@ -0,0 +1,85 @@
+// ==========================================================================
+// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
+// ==========================================================================
+
+package internal
+
+import (
+	"context"
+
+	"github.com/gogf/gf/v2/database/gdb"
+	"github.com/gogf/gf/v2/frame/g"
+)
+
+// UserDao is the data access object for the table user.
+type UserDao struct {
+	table   string      // table is the underlying table name of the DAO.
+	group   string      // group is the database configuration group name of the current DAO.
+	columns UserColumns // columns contains all the column names of Table for convenient usage.
+}
+
+// UserColumns defines and stores column names for the table user.
+type UserColumns struct {
+	Id        string //
+	Name      string //
+	Gender    string //
+	Email     string //
+	Age       string //
+	CreatedAt string //
+	UpdatedAt string //
+}
+
+// userColumns holds the columns for the table user.
+var userColumns = UserColumns{
+	Id:        "id",
+	Name:      "name",
+	Gender:    "gender",
+	Email:     "email",
+	Age:       "age",
+	CreatedAt: "created_at",
+	UpdatedAt: "updated_at",
+}
+
+// NewUserDao creates and returns a new DAO object for table data access.
+func NewUserDao() *UserDao {
+	return &UserDao{
+		group:   "default",
+		table:   "user",
+		columns: userColumns,
+	}
+}
+
+// DB retrieves and returns the underlying raw database management object of the current DAO.
+func (dao *UserDao) DB() gdb.DB {
+	return g.DB(dao.group)
+}
+
+// Table returns the table name of the current DAO.
+func (dao *UserDao) Table() string {
+	return dao.table
+}
+
+// Columns returns all column names of the current DAO.
+func (dao *UserDao) Columns() UserColumns {
+	return dao.columns
+}
+
+// Group returns the database configuration group name of the current DAO.
+func (dao *UserDao) Group() string {
+	return dao.group
+}
+
+// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
+func (dao *UserDao) Ctx(ctx context.Context) *gdb.Model {
+	return dao.DB().Model(dao.table).Safe().Ctx(ctx)
+}
+
+// Transaction wraps the transaction logic using function f.
+// It rolls back the transaction and returns the error if function f returns a non-nil error.
+// It commits the transaction and returns nil if function f returns nil.
+//
+// Note: Do not commit or roll back the transaction in function f,
+// as it is automatically handled by this function.
+func (dao *UserDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) {
+	return dao.Ctx(ctx).Transaction(ctx, f)
+}

+ 27 - 0
internal/dao/orders.go

@@ -0,0 +1,27 @@
+// =================================================================================
+// This file is auto-generated by the GoFrame CLI tool. You may modify it as needed.
+// =================================================================================
+
+package dao
+
+import (
+	"cris/internal/dao/internal"
+)
+
+// internalOrdersDao is an internal type for wrapping the internal DAO implementation.
+type internalOrdersDao = *internal.OrdersDao
+
+// ordersDao is the data access object for the table orders.
+// You can define custom methods on it to extend its functionality as needed.
+type ordersDao struct {
+	internalOrdersDao
+}
+
+var (
+	// Orders is a globally accessible object for table orders operations.
+	Orders = ordersDao{
+		internal.NewOrdersDao(),
+	}
+)
+
+// Add your custom methods and functionality below.

+ 27 - 0
internal/dao/user.go

@@ -0,0 +1,27 @@
+// =================================================================================
+// This file is auto-generated by the GoFrame CLI tool. You may modify it as needed.
+// =================================================================================
+
+package dao
+
+import (
+	"cris/internal/dao/internal"
+)
+
+// internalUserDao is an internal type for wrapping the internal DAO implementation.
+type internalUserDao = *internal.UserDao
+
+// userDao is the data access object for the table user.
+// You can define custom methods on it to extend its functionality as needed.
+type userDao struct {
+	internalUserDao
+}
+
+var (
+	// User is a globally accessible object for table user operations.
+	User = userDao{
+		internal.NewUserDao(),
+	}
+)
+
+// Add your custom methods and functionality below.

+ 26 - 0
internal/model/do/orders.go

@@ -0,0 +1,26 @@
+// =================================================================================
+// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
+// =================================================================================
+
+package do
+
+import (
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/os/gtime"
+)
+
+// Orders is the golang structure of table orders for DAO operations like Where/Data.
+type Orders struct {
+	g.Meta          `orm:"table:orders, do:true"`
+	Id              interface{} //
+	UserId          interface{} //
+	OrderNumber     interface{} //
+	Status          interface{} //
+	TotalAmount     interface{} //
+	CreatedAt       *gtime.Time //
+	UpdatedAt       *gtime.Time //
+	ShippedAt       *gtime.Time //
+	DeliveredAt     *gtime.Time //
+	PaymentStatus   interface{} //
+	ShippingAddress interface{} //
+}

+ 22 - 0
internal/model/do/user.go

@@ -0,0 +1,22 @@
+// =================================================================================
+// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
+// =================================================================================
+
+package do
+
+import (
+	"github.com/gogf/gf/v2/frame/g"
+	"github.com/gogf/gf/v2/os/gtime"
+)
+
+// User is the golang structure of table user for DAO operations like Where/Data.
+type User struct {
+	g.Meta    `orm:"table:user, do:true"`
+	Id        interface{} //
+	Name      interface{} //
+	Gender    interface{} //
+	Email     interface{} //
+	Age       interface{} //
+	CreatedAt *gtime.Time //
+	UpdatedAt *gtime.Time //
+}

+ 24 - 0
internal/model/entity/orders.go

@@ -0,0 +1,24 @@
+// =================================================================================
+// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
+// =================================================================================
+
+package entity
+
+import (
+	"github.com/gogf/gf/v2/os/gtime"
+)
+
+// Orders is the golang structure for table orders.
+type Orders struct {
+	Id              int         `json:"id"              orm:"id"               description:""` //
+	UserId          int         `json:"userId"          orm:"user_id"          description:""` //
+	OrderNumber     string      `json:"orderNumber"     orm:"order_number"     description:""` //
+	Status          string      `json:"status"          orm:"status"           description:""` //
+	TotalAmount     float64     `json:"totalAmount"     orm:"total_amount"     description:""` //
+	CreatedAt       *gtime.Time `json:"createdAt"       orm:"created_at"       description:""` //
+	UpdatedAt       *gtime.Time `json:"updatedAt"       orm:"updated_at"       description:""` //
+	ShippedAt       *gtime.Time `json:"shippedAt"       orm:"shipped_at"       description:""` //
+	DeliveredAt     *gtime.Time `json:"deliveredAt"     orm:"delivered_at"     description:""` //
+	PaymentStatus   string      `json:"paymentStatus"   orm:"payment_status"   description:""` //
+	ShippingAddress string      `json:"shippingAddress" orm:"shipping_address" description:""` //
+}

+ 20 - 0
internal/model/entity/user.go

@@ -0,0 +1,20 @@
+// =================================================================================
+// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
+// =================================================================================
+
+package entity
+
+import (
+	"github.com/gogf/gf/v2/os/gtime"
+)
+
+// User is the golang structure for table user.
+type User struct {
+	Id        int         `json:"id"        orm:"id"         description:""` //
+	Name      string      `json:"name"      orm:"name"       description:""` //
+	Gender    int         `json:"gender"    orm:"gender"     description:""` //
+	Email     string      `json:"email"     orm:"email"      description:""` //
+	Age       int         `json:"age"       orm:"age"        description:""` //
+	CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:""` //
+	UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:""` //
+}

binární
main.exe~