|
88 | 88 | )
|
89 | 89 |
|
90 | 90 | type exprDB interface {
|
| 91 | + StatementPrepare(ctx context.Context, stmt *exql.Statement) (*sql.Stmt, error) |
91 | 92 | StatementQuery(ctx context.Context, stmt *exql.Statement, args ...interface{}) (*sql.Rows, error)
|
92 | 93 | StatementQueryRow(ctx context.Context, stmt *exql.Statement, args ...interface{}) (*sql.Row, error)
|
93 | 94 | StatementExec(ctx context.Context, stmt *exql.Statement, args ...interface{}) (sql.Result, error)
|
@@ -132,6 +133,23 @@ func (b *sqlBuilder) IteratorContext(ctx context.Context, query interface{}, arg
|
132 | 133 | return &iterator{rows, err}
|
133 | 134 | }
|
134 | 135 |
|
| 136 | +func (b *sqlBuilder) Prepare(query interface{}) (*sql.Stmt, error) { |
| 137 | + return b.PrepareContext(b.sess.Context(), query) |
| 138 | +} |
| 139 | + |
| 140 | +func (b *sqlBuilder) PrepareContext(ctx context.Context, query interface{}) (*sql.Stmt, error) { |
| 141 | + switch q := query.(type) { |
| 142 | + case *exql.Statement: |
| 143 | + return b.sess.StatementPrepare(ctx, q) |
| 144 | + case string: |
| 145 | + return b.sess.StatementPrepare(ctx, exql.RawSQL(q)) |
| 146 | + case db.RawValue: |
| 147 | + return b.PrepareContext(ctx, q.Raw()) |
| 148 | + default: |
| 149 | + return nil, fmt.Errorf("Unsupported query type %T.", query) |
| 150 | + } |
| 151 | +} |
| 152 | + |
135 | 153 | func (b *sqlBuilder) Exec(query interface{}, args ...interface{}) (sql.Result, error) {
|
136 | 154 | return b.ExecContext(b.sess.Context(), query, args...)
|
137 | 155 | }
|
@@ -389,6 +407,8 @@ func columnFragments(columns []interface{}) ([]exql.Fragment, []interface{}, err
|
389 | 407 | f[i] = v
|
390 | 408 | case string:
|
391 | 409 | f[i] = exql.ColumnWithName(v)
|
| 410 | + case int: |
| 411 | + f[i] = exql.RawValue(fmt.Sprintf("%v", v)) |
392 | 412 | case interface{}:
|
393 | 413 | f[i] = exql.ColumnWithName(fmt.Sprintf("%v", v))
|
394 | 414 | default:
|
@@ -562,6 +582,14 @@ func (p *exprProxy) StatementExec(ctx context.Context, stmt *exql.Statement, arg
|
562 | 582 | return compat.ExecContext(p.db, ctx, s, args)
|
563 | 583 | }
|
564 | 584 |
|
| 585 | +func (p *exprProxy) StatementPrepare(ctx context.Context, stmt *exql.Statement) (*sql.Stmt, error) { |
| 586 | + s, err := stmt.Compile(p.t) |
| 587 | + if err != nil { |
| 588 | + return nil, err |
| 589 | + } |
| 590 | + return compat.PrepareContext(p.db, ctx, s) |
| 591 | +} |
| 592 | + |
565 | 593 | func (p *exprProxy) StatementQuery(ctx context.Context, stmt *exql.Statement, args ...interface{}) (*sql.Rows, error) {
|
566 | 594 | s, err := stmt.Compile(p.t)
|
567 | 595 | if err != nil {
|
|
0 commit comments