@@ -7,7 +7,7 @@ namespace SqlcGenCsharp.Drivers;
7
7
8
8
public class MethodGen ( DbDriver dbDriver )
9
9
{
10
- public static MethodDeclaration OneDeclare ( string funcName , string queryTextConstant , string argInterface ,
10
+ public MethodDeclaration OneDeclare ( string funcName , string queryTextConstant , string argInterface ,
11
11
string returnInterface , IList < Parameter > parameters , IList < Column > columns )
12
12
{
13
13
var newObjectExpression = new NewObject ( returnInterface , GetColumnsInitExpressions ( columns ) ) ;
@@ -16,8 +16,8 @@ public static MethodDeclaration OneDeclare(string funcName, string queryTextCons
16
16
withResourceBody = withResourceBody . AppendIfNotNull ( queryParams ) ;
17
17
withResourceBody = withResourceBody . Concat (
18
18
[
19
- PrepareQuery ( queryTextConstant ) ,
20
- ExecuteAndAssign ( queryTextConstant , queryParams ) ,
19
+ dbDriver . PrepareStmt ( funcName , queryTextConstant ) ,
20
+ ExecuteAndAssign ( funcName , queryParams ) ,
21
21
new SimpleStatement ( Variable . Row . AsVar ( ) , new SimpleExpression ( $ "{ Variable . Result . AsVar ( ) } .first") ) ,
22
22
new SimpleExpression ( $ "return nil if { Variable . Row . AsVar ( ) } .nil?") ,
23
23
new SimpleStatement ( $ "{ Variable . Entity . AsVar ( ) } ", newObjectExpression ) ,
@@ -37,7 +37,7 @@ public static MethodDeclaration OneDeclare(string funcName, string queryTextCons
37
37
return parameters . Count == 0 ? null : argInterface . SnakeCase ( ) ;
38
38
}
39
39
40
- public static MethodDeclaration ManyDeclare ( string funcName , string queryTextConstant , string argInterface ,
40
+ public MethodDeclaration ManyDeclare ( string funcName , string queryTextConstant , string argInterface ,
41
41
string returnInterface , IList < Parameter > parameters , IList < Column > columns )
42
42
{
43
43
var listAppend = new ListAppend ( Variable . Entities . AsVar ( ) ,
@@ -47,8 +47,8 @@ public static MethodDeclaration ManyDeclare(string funcName, string queryTextCon
47
47
withResourceBody = withResourceBody . AppendIfNotNull ( queryParams ) ;
48
48
withResourceBody = withResourceBody . Concat (
49
49
[
50
- PrepareQuery ( queryTextConstant ) ,
51
- ExecuteAndAssign ( queryTextConstant , queryParams ) ,
50
+ dbDriver . PrepareStmt ( funcName , queryTextConstant ) ,
51
+ dbDriver . ExecuteStmt ( funcName , queryParams ) ,
52
52
new SimpleStatement ( Variable . Entities . AsVar ( ) , new SimpleExpression ( "[]" ) ) ,
53
53
new ForeachLoop ( Variable . Result . AsVar ( ) , Variable . Row . AsVar ( ) , new List < IComposable > { listAppend } ) ,
54
54
new SimpleExpression ( $ "return { Variable . Entities . AsVar ( ) } ")
@@ -62,16 +62,16 @@ public static MethodDeclaration ManyDeclare(string funcName, string queryTextCon
62
62
} ) ;
63
63
}
64
64
65
- public static MethodDeclaration ExecDeclare ( string funcName , string queryTextConstant , string argInterface ,
65
+ public MethodDeclaration ExecDeclare ( string funcName , string queryTextConstant , string argInterface ,
66
66
IList < Parameter > parameters )
67
67
{
68
68
IEnumerable < IComposable > withResourceBody = new List < IComposable > ( ) ;
69
69
var queryParams = GetQueryParams ( argInterface , parameters ) ;
70
70
withResourceBody = withResourceBody . AppendIfNotNull ( queryParams ) ;
71
71
withResourceBody = withResourceBody . Concat (
72
72
[
73
- PrepareQuery ( queryTextConstant ) ,
74
- ExecuteStmt ( queryTextConstant , queryParams )
73
+ dbDriver . PrepareStmt ( funcName , queryTextConstant ) ,
74
+ dbDriver . ExecuteStmt ( funcName , queryParams )
75
75
]
76
76
) ;
77
77
return new MethodDeclaration ( funcName , GetMethodArgs ( argInterface , parameters ) ,
@@ -81,16 +81,16 @@ public static MethodDeclaration ExecDeclare(string funcName, string queryTextCon
81
81
} ) ;
82
82
}
83
83
84
- public static MethodDeclaration ExecLastIdDeclare ( string funcName , string queryTextConstant , string argInterface ,
84
+ public MethodDeclaration ExecLastIdDeclare ( string funcName , string queryTextConstant , string argInterface ,
85
85
IList < Parameter > parameters )
86
86
{
87
87
IEnumerable < IComposable > withResourceBody = new List < IComposable > ( ) ;
88
88
var queryParams = GetQueryParams ( argInterface , parameters ) ;
89
89
withResourceBody = withResourceBody . AppendIfNotNull ( queryParams ) ;
90
90
withResourceBody = withResourceBody . Concat (
91
91
[
92
- PrepareQuery ( queryTextConstant ) ,
93
- ExecuteStmt ( queryTextConstant , queryParams ) ,
92
+ dbDriver . PrepareStmt ( funcName , queryTextConstant ) ,
93
+ dbDriver . ExecuteStmt ( funcName , queryParams ) ,
94
94
new SimpleExpression ( $ "return { Variable . Client . AsVar ( ) } .last_id")
95
95
]
96
96
) ;
@@ -109,25 +109,14 @@ public static MethodDeclaration ExecLastIdDeclare(string funcName, string queryT
109
109
: new SimpleStatement ( Variable . QueryParams . AsVar ( ) , new SimpleExpression ( $ "[{ queryParams . JoinByComma ( ) } ]") ) ;
110
110
}
111
111
112
- private static SimpleStatement PrepareQuery ( string queryTextConstant )
113
- {
114
- return new SimpleStatement ( Variable . Stmt . AsVar ( ) ,
115
- new SimpleExpression ( $ "{ Variable . Client . AsVar ( ) } .prepare({ queryTextConstant } )") ) ;
116
- }
117
-
118
- private static SimpleExpression ExecuteStmt ( string queryTextConstant , SimpleStatement ? queryParams )
119
- {
120
- var queryParamsArg = queryParams is null ? string . Empty : $ ", { Variable . QueryParams . AsVar ( ) } ";
121
- return new SimpleExpression ( $ "{ Variable . Stmt . AsVar ( ) } .execute({ queryTextConstant } { queryParamsArg } )") ;
122
- }
123
-
124
112
private static IEnumerable < SimpleExpression > GetColumnsInitExpressions ( IEnumerable < Column > columns )
125
113
{
126
114
return columns . Select ( c => new SimpleExpression ( $ "{ Variable . Row . AsVar ( ) } ['{ c . Name } ']") ) ;
127
115
}
128
116
129
- private static SimpleStatement ExecuteAndAssign ( string queryTextConstant , SimpleStatement ? queryParams )
117
+ private SimpleStatement ExecuteAndAssign ( string funcName , SimpleStatement ? queryParams )
130
118
{
131
- return new SimpleStatement ( Variable . Result . AsVar ( ) , ExecuteStmt ( queryTextConstant , queryParams ) ) ;
119
+ return new SimpleStatement ( Variable . Result . AsVar ( ) ,
120
+ dbDriver . ExecuteStmt ( funcName , queryParams ) ) ;
132
121
}
133
122
}
0 commit comments