This is the native target and it's going to be super easy. If you want to follow along, get yourself a copy of Zig (v0.9 or above), a copy of Go (v1.18 or above) and clone the repo in question. Of course I will be using zig cc as the C compiler. Normally you would just run go test, but in my case I'll add -c to make Go produce the test executable without running it, allowing me to move the executable on the correct machine. I'm going to create the following builds on a aarch64 linux machine:Įach build will consist of the test suite that the package comes with. In this post I'm going to show all the good and bad of compiling for different OSs mattn/go-sqlite3, the package that relies on CGo to compile the original SQLite source file. Secondly, dealing with CGo is actually not that bad nowadays. Is the tradeoff worth it? I would say no.įirstly, SQLite is famous for being tested extremely thoroughly and, while the Go version is the result of machine translation of the original code, I would trust the original code over any reimplementation. The C implementation was twice as fast as the Go one, but it saves you from having to deal with CGo. Some bundled the official C implementation, while others offered a pure Go implementation. Note that sometimes you can't use the for statement because you don't have more than one row, then you can use the if statement if rows.A recent post on the front page of HN made a comparison between different SQLite packages for Go. You may have noticed that the code is almost the same as in the previous section, and that we only changed the name of the registered driver and called sql.Open to connect to SQLite in a different way. To create a database protected by user authentication, provide the following argument to the connection string auth. To use the User authentication module, the package has to be compiled with the tag sqliteuserauth. Stmt, err = db.Prepare( "delete from userinfo where uid=?") This package supports the SQLite User Authentication module. Rows.Close() //good habit to close // delete Var uid int var username string var department string var created time.TimeĮrr = rows.Scan(&uid, &username, &department, &created) Internally, slice and an array are connected with. It is just like an array having an index value and length, but the size of the slice is resized they are not in fixed-size just like an array. Rows, err := db.Query( "SELECT * FROM userinfo") Slice is a variable-length sequence which stores elements of a similar type, you are not allowed to store different type of elements in the same slice. Res, err = stmt.Exec( "astaxieupdate", id) Stmt, err = db.Prepare( "update userinfo set username=? where uid=?") This package operates models which are described by Model interface. Res, err := stmt.Exec( "astaxie", "研发部门", "") Lightweight package implementing some ORM-like features and helpers for sqlite databases. Stmt, err := db.Prepare( "INSERT INTO userinfo(username, departname, created) values(?,?,?)") These are the top rated real world Golang examples of /mxk/go-sqlite/sqlite3.Open extracted from open source. We create the following SQL: CREATE TABLE `userinfo` (ĭb, err := sql.Open( "sqlite3", "./foo.db") The first driver is the only one that supports the database/sql interface standard in its SQLite driver, so I use this in my projects -it will make it easy to migrate my code in the future if I need to.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |