-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMDDSort.m
More file actions
41 lines (30 loc) · 1.09 KB
/
MDDSort.m
File metadata and controls
41 lines (30 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// MDDSort.m
// MDDatabase
//
// Created by xulinfeng on 2018/3/23.
// Copyright © 2018年 markejave. All rights reserved.
//
#import "MDDSort.h"
#import "MDDTableInfo.h"
#import "MDDColumn.h"
#import "MDDDescription.h"
@implementation MDDSort
+ (instancetype)sortWithTableInfo:(MDDTableInfo *)tableInfo property:(id<MDDItem>)property ascending:(BOOL)ascending;{
MDDSort *sort = [super descriptorWithTableInfo:tableInfo property:property value:nil];
sort->_ascending = ascending;
return sort;
}
- (NSString *)description{
return [[self dictionaryWithValuesForKeys:@[@"property", @"ascending"]] description];
}
- (MDDDescription *)SQLDescription{
MDDColumn *column = [self.tableInfo columnForProperty:[self property]];
NSParameterAssert(column);
NSString *SQL = [NSString stringWithFormat:@"%@ %@", [column name], [self ascending] ? @"ASC" : @"DESC"];
return [MDDDescription descriptionWithSQL:SQL values:nil];
}
+ (MDDDescription *)descriptionWithSorts:(NSArray<MDDSort *> *)sorts{
return [super descriptionWithDescriptors:sorts separator:@" , "];
}
@end