This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We need somewhere to store the prepared statement for the lifetime of our | |
// web application. A neat way is to embed it in the model alongside the | |
// connection pool. | |
type ExampleModel struct { | |
DB *sql.DB | |
InsertStmt *sql.Stmt | |
} | |
// Create a constructor for the model, in which we set up the prepared | |
// statement. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Types for the result object with discriminated union | |
type Success<T> = { | |
data: T; | |
error: null; | |
}; | |
type Failure<E> = { | |
data: null; | |
error: E; | |
}; |