Member-only story
Go
Work with SQLite3 in Go
https://github.com/mattn/go-sqlite3 has more than 4.4k starts at this time. So I think we can count on that 💃.
First to install go-sqlite3 using go-mod
go get https://github.com/mattn/go-sqlite3
Connect and set max_idle_connection (for the case we might use concurrency).
db, err := sql.Open("sqlite3", "path_to_the_db")
if err != nil {
fmt.Println(err)
}
db.SetMaxIdleConns(MAX)defer db.Close()
defer for close the db after all the around functions finished calling.
Example for query data:
func displayGene(db *sql.DB, ensembleID string) (int, int, int, string, string, string) {
var seqidGene int
var startLocation int
var endLocation int
var sourceGene string
var strandGene string
var attributesGene string
row, err := db.Query("select seqid,start,end, source, strand, attributes from features where featuretype = 'gene' and id = $1;", ensembleID)
if err != nil {
log.Fatal(err)
}
defer row.Close()
for row.Next() { // Iterate and fetch the records from result cursor
var seqid int
var start int
var end int
var source string
var strand string…