an ORM-free SQL experience

unwrap results in must-* variants

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li ac3ab727 134dc89d

verified
Changed files
+13 -36
+13 -36
types.go
··· 70 } 71 72 func MustExec(b Builder, p Database) sql.Result { 73 - res, err := Exec(b, p) 74 - if err != nil { 75 - panic(err) 76 - } 77 - 78 - return res 79 } 80 81 func MustExecContext(ctx context.Context, b Builder, p Database) sql.Result { 82 - res, err := ExecContext(ctx, b, p) 83 - if err != nil { 84 - panic(err) 85 - } 86 - 87 - return res 88 } 89 90 type Querier interface { ··· 127 } 128 129 func MustQuery(b Builder, db Database) *sql.Rows { 130 - rows, err := Query(b, db) 131 - if err != nil { 132 - panic(err) 133 - } 134 - 135 - return rows 136 } 137 138 func MustQueryContext(ctx context.Context, b Builder, db Database) *sql.Rows { 139 - rows, err := QueryContext(ctx, b, db) 140 - if err != nil { 141 - panic(err) 142 - } 143 - 144 - return rows 145 } 146 147 func MustQueryRow(b Builder, db Database) *sql.Row { 148 - row, err := QueryRow(b, db) 149 - if err != nil { 150 - panic(err) 151 - } 152 - 153 - return row 154 } 155 156 func MustQueryRowContext(ctx context.Context, b Builder, db Database) *sql.Row { 157 - row, err := QueryRowContext(ctx, b, db) 158 - if err != nil { 159 - panic(err) 160 - } 161 - 162 - return row 163 } 164 165 type Direction string ··· 173 var zero T 174 return zero 175 }
··· 70 } 71 72 func MustExec(b Builder, p Database) sql.Result { 73 + return unwrap(Exec(b, p)) 74 } 75 76 func MustExecContext(ctx context.Context, b Builder, p Database) sql.Result { 77 + return unwrap(ExecContext(ctx, b, p)) 78 } 79 80 type Querier interface { ··· 117 } 118 119 func MustQuery(b Builder, db Database) *sql.Rows { 120 + return unwrap(Query(b, db)) 121 } 122 123 func MustQueryContext(ctx context.Context, b Builder, db Database) *sql.Rows { 124 + return unwrap(QueryContext(ctx, b, db)) 125 } 126 127 func MustQueryRow(b Builder, db Database) *sql.Row { 128 + return unwrap(QueryRow(b, db)) 129 } 130 131 func MustQueryRowContext(ctx context.Context, b Builder, db Database) *sql.Row { 132 + return unwrap(QueryRowContext(ctx, b, db)) 133 } 134 135 type Direction string ··· 143 var zero T 144 return zero 145 } 146 + 147 + func unwrap[P any](p P, e error) P { 148 + if e != nil { 149 + panic(e) 150 + } 151 + return p 152 + }