li6185377 / LKDBHelper-SQLite-ORM

全自动的插入,查询,更新,删除, an automatic database operation thread-safe and not afraid of recursive deadlock
MIT License
1.21k stars 288 forks source link

请教一下,排序3个问题 #166

Closed CCBrother closed 2 years ago

CCBrother commented 2 years ago

1、模型的字段时间戳是longlong类型,存到数据库却是integer类型,取出的顺序有问题,需要把时间戳转为字符串吗? 2、NSMutableArray *searchResultArray = [TWYIMChatMessageModel searchWithWhere:[NSString stringWithFormat:@"sessionId='%@'", self.sessionModel.sessionId] orderBy:@"sendTimeStamp asc" offset:0 count:20];

@"sendTimeStamp asc" 这里的asc是指数据库的数据升序呢?还是取出来20个数据后,再进行升序? 3、保存数据到数据库的时候可以按字段逆序保存吗?

li6185377 commented 2 years ago
  1. sqlite 内部其实是无类型的,iOS 5s之后都是64位int了,如果要用 longlong 类型,建议用一个 string 来存,使用时在转为longlong
  2. asc 在数据库内 都是先排序 在取前20个
  3. 数据库是模型存储, 跟字段顺序无关(只有数组那种 才要求有序的吧)
CCBrother commented 2 years ago

明白了,感谢感谢!!!