1- require " ./multi "
1+ require " ./repo/query "
22
33module Crecto
44 class LiveTransaction (T )
5+ alias Query = Repo ::Query
6+
57 def initialize (@tx : DB ::Transaction , @repo : T )
68 end
79
10+ def raw_exec (args : Array )
11+ @repo .raw_exec(args, @tx )
12+ end
13+
14+ def raw_exec (* args)
15+ @repo .raw_exec(* args, @tx )
16+ end
17+
18+ def raw_query (query, * args)
19+ @repo .raw_query(query, * args, @tx ) do |rs |
20+ yield rs
21+ end
22+ end
23+
24+ def raw_query (query, args : Array )
25+ @repo .raw_query(query, args, @tx )
26+ end
27+
28+ def raw_query (query, * args)
29+ @repo .raw_query(query, * args)
30+ end
31+
32+ def raw_scalar (* args)
33+ @repo .raw_scalar(* args, @tx )
34+ end
35+
36+ def all (queryable, query : Query ? = Query .new, ** opts)
37+ @repo .all(queryable, query, @tx , ** opts)
38+ end
39+
40+ def all (queryable, query = Query .new)
41+ @repo .all(queryable, query, @tx )
42+ end
43+
44+ def get (queryable, id)
45+ @repo .get(queryable, id, @tx )
46+ end
47+
48+ def get !(queryable, id)
49+ @repo .get!(queryable, id, @tx )
50+ end
51+
52+ def get (queryable, id, query : Query )
53+ @repo .get(queryable, id, query, @tx )
54+ end
55+
56+ def get !(queryable, id, query : Query )
57+ @repo .get!(queryable, id, query, @tx )
58+ end
59+
60+ def get_by (queryable, ** opts)
61+ @repo .get_by(queryable, @tx , ** opts)
62+ end
63+
64+ def get_by (queryable, query)
65+ @repo .get_by(queryable, query, @tx )
66+ end
67+
68+ def get_by !(queryable, ** opts)
69+ @repo .get_by!(queryable, @tx , ** opts)
70+ end
71+
72+ def get_by !(queryable, query)
73+ @repo .get_by!(queryable, query, @tx )
74+ end
75+
76+ def get_association (queryable_instance, association_name : Symbol )
77+ @repo .get_association(queryable_instance, association_name, @tx )
78+ end
79+
80+ def get_association !(queryable_instance, association_name : Symbol )
81+ @repo .get_association!(queryable_instance, association_name, @tx )
82+ end
83+
884 {% for type in %w[insert insert! delete delete! update update!] % }
985 def {{type.id}} (queryable : Crecto ::Model )
1086 @repo .{{type .id}}(queryable, @tx )
@@ -26,5 +102,19 @@ module Crecto
26102 def update_all (queryable, query, update_tuple : NamedTuple )
27103 update_all(queryable, query, update_tuple.to_h)
28104 end
105+
106+ def aggregate (queryable, aggregate_function : Symbol , field : Symbol )
107+ @repo .aggregate(queryable, aggregate_function, field, @tx )
108+ end
109+
110+ def aggregate (queryable, aggregate_function : Symbol , field : Symbol , query : Crecto ::Repo ::Query )
111+ @repo .aggregate(queryable, aggregate_function, field, query, @tx )
112+ end
113+
114+ def transaction !
115+ @repo .transaction!(@tx ) do |tx |
116+ yield tx
117+ end
118+ end
29119 end
30120end
0 commit comments