forked from binarylogic/searchlogic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqlite_adapter.rb
88 lines (69 loc) · 2.19 KB
/
sqlite_adapter.rb
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
module Searchlogic
module ActiveRecord
module ConnectionAdapters
module SQLiteAdapter
# Date functions
def microseconds_sql(column_name)
"((strftime('%f', #{column_name}) % 1) * 1000000)"
end
def milliseconds_sql(column_name)
"((strftime('%f', #{column_name}) % 1) * 1000)"
end
def second_sql(column_name)
"(strftime('%S', #{column_name}) * 1)"
end
def minute_sql(column_name)
"(strftime('%M', #{column_name}) * 1)"
end
def hour_sql(column_name)
"(strftime('%H', #{column_name}) * 1)"
end
def day_of_week_sql(column_name)
"(strftime('%w', #{column_name}) * 1)"
end
def day_of_month_sql(column_name)
"(strftime('%d', #{column_name}) * 1)"
end
def day_of_year_sql(column_name)
"(strftime('%j', #{column_name}) * 1)"
end
def week_sql(column_name)
"(strftime('%W', #{column_name}) * 1)"
end
def month_sql(column_name)
"(strftime('%m', #{column_name}) * 1)"
end
def year_sql(column_name)
"(strftime('%Y', #{column_name}) * 1)"
end
# Number functions
def avg_sql(column_name)
"AVG(#{column_name})"
end
def count_sql(column_name)
"COUNT(#{column_name})"
end
def sum_sql(column_name)
"SUM(#{column_name})"
end
# String functions
def lower_sql(column_name)
"lower(#{column_name})"
end
def ltrim_sql(column_name)
"ltrim(#{column_name})"
end
def rtrim_sql(column_name)
"rtrim(#{column_name})"
end
def trim_sql(column_name)
"trim(#{column_name})"
end
def upper_sql(column_name)
"upper(#{column_name})"
end
end
end
end
end
::ActiveRecord::ConnectionAdapters::SQLiteAdapter.send(:include, Searchlogic::ActiveRecord::ConnectionAdapters::SQLiteAdapter)