Skip to content

xiaoshouchen/gorm-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gorm-generator

Introduction

this project is used to generate gorm model and repository from mysql database and other databases.

Usage

install

go install  github.com/xiaoshouchen/gorm-generator@latest

run

gorm-generator

config

{
  "databases": [
    {
      "scheme": "panda-trip",
      "package_name": "model",
      "connect": {
        "type": "mysql",
        "host": "localhost",
        "port": "3306",
        "user": "root",
        "password": "password"
      },
      "table_filter_option": "all",
      "tables": [],
      "cache_expiration": [
        {
          "name": "users",
          "time": 3600
        }
      ]
    }
  ]
}

cache

generate cache for table

  1. you should add cache expiration time for table in config
  2. the cache key is table_name_%s
  3. the cache value is the table data
  4. the cache expiration time is the time you set in config
  5. batch get cache data by ids , if cache not exists, will get data from database and set cache
  6. if some ids not exists in database, it also set cache for these ids, but the value is {} ,avoid cache penetration, {} empty cache expiration time is 1 day always

sync cache by canal

  1. watch canal event
  2. when insert/update/delete event, will sync cache
  3. table_name_cache.go is generated by gorm-generator , do not modify it ,and if you want to add or edit cache, you should modify table_name_repo.go for additional operations

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors