@@ -8,8 +8,8 @@ Automatically create tables based on the model. To achieve additions and deletio
8
8
9
9
#### Use
10
10
11
- 实现协议方法.
12
- Imp < SJDBMapUseProtocol > Method.
11
+ 实现协议方法.
12
+ Imp SJDBMapUseProtocol Method.
13
13
14
14
```
15
15
@interface SampleVideoModel : NSObject<SJDBMapUseProtocol>
@@ -42,10 +42,10 @@ Imp <SJDBMapUseProtocol> Method.
42
42
```
43
43
44
44
#### insertOrUpdate 插入数据或更新数据
45
+ 数据在插入表之前, 会检测是否已经存在相关表。如果不存在,会先创建相关表(可能会创建多个表), 再进行数据的更新或插入。
46
+ 如果类中新添了属性, 会自动检测并更新相关表字段。
45
47
Data before the table is inserted, it will detect whether the relevant table already exists. If it does not exist, it will first create a related table (may create multiple tables), and then update the data or insert.
46
48
If a new attribute is added to the class, the associated table field is automatically detected and updated.
47
- 数据在插入表之前, 会检测是否已经存在相关表。如果不存在,会先创建相关表(可能会创建多个表), 再进行数据的更新或插入。
48
- 如果类中新添了属性, 会自动检测并更新相关表字段。
49
49
50
50
```
51
51
- (void)insertOrUpdate {
@@ -63,30 +63,78 @@ If a new attribute is added to the class, the associated table field is automati
63
63
// ....
64
64
}];
65
65
}
66
+ - (void)update {
67
+ [[SJDatabaseMap sharedServer] update:person property:@[@"tags", @"age"] callBlock:^(BOOL result) {
68
+ // ....
69
+ }];
70
+
71
+ [[SJDatabaseMap sharedServer] update:person insertedOrUpdatedValues:@{@"tags":insertedValues} callBlock:^(BOOL r) {
72
+ // ....
73
+ }];
74
+ }
66
75
```
67
76
#### delete 删除
77
+ 删除数据是删除该类对应的表的数据, 与其关联的其他类的数据没有做处理。
68
78
Deleting data is to delete the data of the corresponding table of the class, and the data of the other class associated with it is not processed.
69
- 删除数据是删除该类对应的表的数据, 与其关联的其他类的数据没有做处理。
70
79
71
80
```
72
81
- (void)del {
73
82
[[SJDBMap sharedServer] deleteDataWithClass:[Person class] primaryValue:0 callBlock:^(BOOL result) {
74
83
// ...
75
84
}];
85
+ [[SJDatabaseMap sharedServer] deleteDataWithClass:[Person class] primaryValues:@[@(1), @(0)] callBlock:^(BOOL r) {
86
+ // ...
87
+ }];
88
+ [[SJDatabaseMap sharedServer] deleteDataWithModels:personModels callBlock:^(BOOL result) {
89
+ // ...
90
+ }];
76
91
}
77
92
```
78
93
#### query 查询
94
+ 查询数据会将与该类相关的所有数据都读取出来, 并转换相应的模型。
79
95
The query data will read all the data associated with that class and convert the corresponding model.
80
- 查询数据会将与该类相关的所有数据都读取出来, 并转换相应的模型。
81
96
82
97
```
83
98
- (void)query {
84
99
[[SJDBMap sharedServer] queryAllDataWithClass:[Person class] completeCallBlock:^(NSArray<id> * _Nonnull data) {
85
100
// ...
86
101
}];
102
+
103
+ [[SJDatabaseMap sharedServer] queryDataWithClass:[Person class] primaryValue:12 completeCallBlock:^(id<SJDBMapUseProtocol> _Nullable model) {
104
+ // ...
105
+ }];
106
+
107
+ [[SJDatabaseMap sharedServer] queryDataWithClass:[Person class] queryDict:@{@"name":@"sj", @"age":@(20)} completeCallBlock:^(NSArray<id<SJDBMapUseProtocol>> * _Nullable data) {
108
+ // ...
109
+ }];
110
+
111
+ [[SJDatabaseMap sharedServer] queryDataWithClass:[Person class] range:NSMakeRange(2, 10) completeCallBlock:^(NSArray<id<SJDBMapUseProtocol>> * _Nullable data) {
112
+ // ...
113
+ }];
114
+ }
115
+ // 模糊查询
116
+ - (void)fuzzyQuery {
117
+ // 匹配以 's' 开头的name.
118
+ [[SJDatabaseMap sharedServer] fuzzyQueryDataWithClass:[Person class] queryDict:@{@"name":@"s"} match:SJDatabaseMapFuzzyMatchFront completeCallBlock:^(NSArray<id<SJDBMapUseProtocol>> * _Nullable data) {
119
+ // ...
120
+ }];
121
+ * 匹配左右两边
122
+ * ...A...
123
+ */
124
+ SJDatabaseMapFuzzyMatchAll = 0,
125
+ /*!
126
+ * 匹配以什么开头
127
+ * ABC.....
128
+ */
129
+ SJDatabaseMapFuzzyMatchFront,
130
+ /*!
131
+ * 匹配以什么结尾
132
+ * ...DEF
133
+ */
134
+ SJDatabaseMapFuzzyMatchLater
87
135
}
88
136
```
89
137
#### Use attention 使用注意
90
-
138
+ 模型需要一个主键或自增主键
91
139
The model requires a primary key or a self-incrementing key
92
- 模型需要一个主键或自增主键
140
+
0 commit comments