![]() ![]() The optional arguments are for any query placeholder parameters. The Query method runs a SELECT query that returns rows. INSERT INTO students(name, score) VALUES('John',10) Īnd test.db will be created in the working folder. INSERT INTO students(name, score) VALUES('Hummer',7.5) INSERT INTO students(name, score) VALUES('Hellen',7.0) INSERT INTO students(name, score) VALUES('Daniel',8.0) INSERT INTO students(name, score) VALUES('Charlie',6.5) INSERT INTO students(name, score) VALUES('Claire',9.5) INSERT INTO students(name, score) VALUES('Bob',7.5) INSERT INTO students(name, score) VALUES('Anna',8.5) First of all, we run a query to create 'students' table: package mainĭb, err := sql.Open("sqlite3", "test.db")ĬREATE TABLE students(id INTEGER PRIMARY KEY, name TEXT, score REAL) The Exec function executes a query without returning any rows. Log.Println("Successfully deleted the book in database!")ġ 23:21:46 Successfully created table books!ġ 23:21:46 Inserted the book into database!ġ 23:21:46 ID:1, Book:A Tale of Two Cities, Author:Charles Dickensġ 23:21:46 Successfully updated the book in database!ġ 23:21:46 ID:1, Book:A Tale of Three Cities, Author:Charles Dickensġ 23:21:46 Successfully deleted the book in database!ĪLSO READ: Golang Websocket Examples Different go sqlite driver functions Go sqlite3 Exec Statement, _ = db.Prepare("delete from books where id=?") Rows, _ = db.Query("SELECT id, name, author FROM books") Log.Println("Successfully updated the book in database!") Statement.Exec("A Tale of Three Cities", 1) Statement, _ = db.Prepare("update books set name=? where id=?") Now let us perform some update and delete operation on our sqlite database using the go driver: package main Update and Delete Operation using sqlite driver ![]() The same can be verified inside the sqlite database of books.db: Log.Printf("ID:%d, Book:%s, Author:%s\n", tempBook.id,ġ 23:11:26 Successfully created table books!ġ 23:11:26 Inserted the book into database!ġ 23:11:26 ID:1, Book:A Tale of Two Cities, Author:Charles Dickens Rows.Scan(
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |