Git Product home page Git Product logo

Comments (10)

xormplus avatar xormplus commented on May 12, 2024

你的叙述有不清晰的地方,你手工修改数据库记录是以什么方式修改的?

from xorm.

rts-gordon avatar rts-gordon commented on May 12, 2024

@xormplus 你好。
我增加缓存处理后,先查询一次数据库,得到结果是dictionary.name='安全',然后通过Navicat工具直接修改数据库记录为’安全abc‘,再次查询,结果得到’安全abc‘。因为有了缓存,理论上应该得到’安全‘,而不是’安全abc‘,所以我觉得是缓存没有起到作用。

from xorm.

xormplus avatar xormplus commented on May 12, 2024

请问这个表有主键么?没有主键的表中的数据将不会被缓存

from xorm.

rts-gordon avatar rts-gordon commented on May 12, 2024

有个id自增主键。
image

from xorm.

xormplus avatar xormplus commented on May 12, 2024

能否把数据库建表脚本和struct的代码发出来看看?

from xorm.

rts-gordon avatar rts-gordon commented on May 12, 2024

结构如下,很小的一个数据表:
--Schema table sql statement;

DROP TABLE library.dictionary CASCADE;
CREATE TABLE library.dictionary (
id BIGSERIAL PRIMARY KEY NOT NULL,
product_id BIGINT,
oid INTEGER,
key VARCHAR(50) NOT NULL,
value VARCHAR(100) NOT NULL,
zhvalue VARCHAR(100),
status INTEGER DEFAULT 1 NOT NULL,
parent_id BIGINT,
intro VARCHAR(1000)
);
COMMENT ON TABLE library.dictionary IS 'The dictionary table';
COMMENT ON COLUMN library.dictionary.id IS 'The primary key';
...

INSERT INTO library.dictionary (product_id,oid,key, value, zhvalue, status, parent_id, intro) VALUES (NULL,1,'main-feature', 'Capability', '核心能力', 1, NULL, 'Capability type of features');
...

from xorm.

xormplus avatar xormplus commented on May 12, 2024

golang的结构图定义的代码看下?

from xorm.

rts-gordon avatar rts-gordon commented on May 12, 2024

结构定义:

package model

// Don't use govalidator but valid.
type Dictionary struct {
Id uint64 xorm:"'id' autoincr" json:"id,omitempty" valid:"optional"
ProductId uint64 xorm:"'product_id'" json:"productId,omitempty" valid:"optional"
Oid int xorm:"'oid'" json:"oid,omitempty" valid:"optional"
Key string xorm:"'key'" json:"key,omitempty" valid:"required,length(1|50)"
Value string xorm:"'value'" json:"value,omitempty" valid:"optional,length(1|100)"
Zhvalue string xorm:"'zhvalue'" json:"zhvalue,omitempty" valid:"optional,length(1|100)"
Status int xorm:"'status'" json:"status,omitempty" valid:"optional,rang(1|2)" //状态:1: Available, 2: Unavailable
ParentId uint64 xorm:"'parent_id'" json:"parentId,omitempty" valid:"optional"
Intro string xorm:"'intro'" json:"intro,omitempty" valid:"optional,length(1|1000)"
}

// define table name:dictionary
func (d *Dictionary) TableName() string {
return "dictionary"
}

from xorm.

xormplus avatar xormplus commented on May 12, 2024

你这个结构体中没有定义主键,所以xorm无法识别,不会cache的

from xorm.

rts-gordon avatar rts-gordon commented on May 12, 2024

奥,是的,我以为只要SQL语句设置了主键就可以了,原来结构体也需要设置。已经解决,多谢多谢。

from xorm.

Related Issues (20)

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.