Comments (10)
你的叙述有不清晰的地方,你手工修改数据库记录是以什么方式修改的?
from xorm.
@xormplus 你好。
我增加缓存处理后,先查询一次数据库,得到结果是dictionary.name='安全',然后通过Navicat工具直接修改数据库记录为’安全abc‘,再次查询,结果得到’安全abc‘。因为有了缓存,理论上应该得到’安全‘,而不是’安全abc‘,所以我觉得是缓存没有起到作用。
from xorm.
请问这个表有主键么?没有主键的表中的数据将不会被缓存
from xorm.
from xorm.
能否把数据库建表脚本和struct的代码发出来看看?
from xorm.
结构如下,很小的一个数据表:
--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.
golang的结构图定义的代码看下?
from xorm.
结构定义:
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.
你这个结构体中没有定义主键,所以xorm无法识别,不会cache的
from xorm.
奥,是的,我以为只要SQL语句设置了主键就可以了,原来结构体也需要设置。已经解决,多谢多谢。
from xorm.
Related Issues (20)
- 子查询不可用 HOT 1
- no primary key for col HOT 2
- 支持sql拦截器吗 或者计划支持么 HOT 1
- 查询float类型的数据与实际的数据不一致 HOT 2
- 还继续维护吗?
- 当我使用engin.SQL(sqlStr, args...).Query().List()方法得时候,如果字段是NULL 返回得结果里面不展示为啥?
- 使用原生sql语句配合Limit函数进行数据库分页查询出错
- processor.BeforeInsert() 为什么不传入参数
- 读写分离能力与文档不符合
- 错误的test, 也没有example HOT 1
- 有没有支持schema auto migrate 功能。类似go-migrate 库做的事? HOT 1
- orm方式插入数据时未赋值的string类型字段会插入空字符串而非使用tag 定义的`default`中的值
- model支持外键
- session.QueryRows中方法查询失败后,未检查返回的core.Rows是否为nil,直接rows.close,导致panic HOT 2
- 会考虑支持CockroachDB吗? HOT 2
- 嵌套类型不能正确设值 HOT 2
- unsupported type xorm.sqlExpr, a struct
- 建议123
- ORACLE insert bug HOT 1
- 为什么engine中删除showExecTime方法 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xorm.