Skip to content

Commit eaea1a4

Browse files
committed
more todos
1 parent 575f1a9 commit eaea1a4

6 files changed

Lines changed: 42 additions & 11 deletions

File tree

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
88
IteratorInterfaceExtensions = "82899510-4779-5014-852e-03e436cf321d"
99
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
1010
QueryOperators = "2aef5ad7-51ca-5a8f-8e88-e75cf067b44b"
11+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1112
SQLite = "0aa819cd-b072-5ff4-a722-6bc24af294d9"
1213
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1314
TableShowUtils = "5e66a065-1f0a-5976-b372-e0b8c017ca10"

src/QuerySQLite.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
module QuerySQLite
22

33
import Base: !, &, |, ==, !=, *, /, +, -, %, abs, Char, coalesce, collect, convert, eltype, getproperty, length,
4-
lowercase, in, isdone, isequal, isless, ismissing, iterate, IteratorSize, max, min,
4+
lowercase, in, isdone, isequal, isless, ismissing, iterate, IteratorSize, join, max, min,
55
occursin, rand, replace, repr, round, show, showerror, startswith, string, strip, SubString, uppercase
66
using Base: Generator, NamedTuple, RefValue, SizeUnknown, tail
77
using Base.Meta: quot
88
import Base.Multimedia: showable
99
using DataValues: DataValue
10-
import Dates: Date, DateTime, Time
10+
import Dates: Date, DateTime, format, Time
1111
import IteratorInterfaceExtensions: getiterator, isiterable
1212
import MacroTools
1313
using MacroTools: @capture
1414
import QueryOperators
15+
import Random: randstring
1516
import SQLite
1617
import SQLite: getvalue
1718
using SQLite: columns, DB, execute!, generate_namedtuple, juliatype,

src/code_instead.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,22 +152,24 @@ end
152152

153153
@code_instead abs SourceCode
154154

155+
# TODO: add more methods
155156
@code_instead char SourceCode Vararg{Any}
156157

157158
@code_instead coalesce SourceCode Vararg{Any}
158159

159160
@code_instead convert Type{Int} SourceCode
160161

161-
# TODO: support dateformat
162162
@code_instead Date SourceCode
163163

164-
# TODO: support dateformat
165164
@code_instead DateTime SourceCode
166165

167166
@code_instead QueryOperators.drop SourceCode Integer
168167

169168
@code_instead QueryOperators.filter SourceCode Any Expr
170169

170+
# TODO: support more methods
171+
@code_instead format SourceCode AbstractString
172+
171173
@code_instead QueryOperators.groupby SourceCode Any Expr Any Expr
172174

173175
@code_instead hex SourceCode
@@ -197,6 +199,8 @@ end
197199

198200
@code_instead ismissing SourceCode
199201

202+
@code_instead join SourceCode
203+
200204
@code_instead QueryOperators.join SourceCode SourceCode Any Expr Any Expr Any Expr
201205

202206
@code_instead max SourceCode Vararg{Any}
@@ -219,6 +223,9 @@ end
219223

220224
@code_instead rand BySQL Type{Int}
221225

226+
# TODO: add more methods
227+
@code_instead randstring BySQL Integer
228+
222229
# TODO: add more methods
223230
@code_instead replace SourceCode Pair
224231

@@ -254,11 +261,8 @@ end
254261

255262
# TODO: add
256263
# printf
257-
# randomblob
258264
# zeroblob
259-
# group_concat
260265
# total
261266
# julianday
262-
# strftime
263267

264268
# TODO: regex start and end

src/translate.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ function translate_call(::typeof(QueryOperators.filter), iterator, call, call_ex
9595
)
9696
end
9797

98+
function translate_call(::typeof(format), time_type, format_string; _primary = true)
99+
SQLExpression(
100+
:STRFTIME,
101+
translate(format_string; _primary = _primary),
102+
translate(time_type; _primary = _primary)
103+
)
104+
end
105+
98106
function translate_call(::typeof(getproperty), source_tables::Database, table_name; _primary = true)
99107
translated = translate(table_name; _primary = _primary)
100108
if _primary
@@ -137,6 +145,8 @@ end
137145

138146
@translate_default ::typeof(ismissing) Symbol("IS NULL")
139147

148+
@translate_default ::typeof(join) :GROUP_CONCAT
149+
140150
function translate_call(::typeof(QueryOperators.join), source1, source2, key1, key1_expression, key2, key2_expression, combine, combine_expression; _primary = true)
141151
model_row_1 = model_row(source1)
142152
model_row_2 = model_row(source2)
@@ -215,6 +225,8 @@ function translate_call(::typeof(rand), ::Type{Int}; _primary = true, digits = 0
215225
SQLExpression(:RANDOM)
216226
end
217227

228+
@translate_default ::typeof(randstring) :RANDOMBLOB
229+
218230
function translate_call(::typeof(replace), it, pair; _primary = true)
219231
SQLExpression(:REPLACE,
220232
translate(it; _primary = _primary),

test/runtests.jl

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using QuerySQLite
22

33
using DataValues: DataValue
4-
using Dates: Date, DateTime, Time
4+
using Dates: Date, DateTime, format, Time
55
using Documenter: doctest
66
using Query
77
using QueryTables
@@ -125,10 +125,18 @@ execute!(Stmt(connection, """
125125
execute!(Stmt(connection, """
126126
INSERT INTO test VALUES(0, 1, -1, "ab", NULL, 65, "b", " a ", "_a_", 1.11, "2019-12-08", "2019-12-08T11:09:00", "11:09:00")
127127
"""))
128-
database = Database(connection)
128+
small = Database(connection)
129+
130+
@test (small.test |>
131+
@groupby(_.zero) |>
132+
@map({
133+
join_test = join(_.ab)
134+
}) |>
135+
collect |>
136+
first).join_test == "ab"
129137

130138
result =
131-
database.test |>
139+
small.test |>
132140
@map({
133141
equals_test = _.zero == _.one,
134142
not_equals_test = _.zero != _.one,
@@ -170,9 +178,12 @@ result =
170178
SubString_test_1 = SubString(_.ab, 2, 2),
171179
SubString_test_2 = SubString(_.ab, 2),
172180
random_test = rand(BySQL(_), Int),
181+
# TODO: fix
182+
# randstring_test = randstring(BySQL(_), 4),
173183
date_test = Date(_.date_text),
174184
datetime_test = DateTime(_.datetime_text),
175-
time_test= Time(_.time_text),
185+
time_test = Time(_.time_text),
186+
format_test = format(_.datetime_text, "%Y-%m-%d %H:%M:%S"),
176187
type_of_test = type_of(_.zero),
177188
convert_test = convert(Int, _.b)
178189
}) |>
@@ -219,8 +230,10 @@ result =
219230
@test result.SubString_test_1 == "b"
220231
@test result.SubString_test_2 == "b"
221232
@test result.random_test isa DataValue{Int}
233+
@test_broken length(result.randomstring_test) == 4
222234
@test result.date_test == "2019-12-08"
223235
@test result.datetime_test == "2019-12-08 11:09:00"
236+
@test result.format_test == "2019-12-08 11:09:00"
224237
@test result.time_test == "11:09:00"
225238
@test result.type_of_test == "integer"
226239

test/test.sqlite

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)