SQLite Cloud for Go is a powerful package that allows you to interact with the SQLite Cloud database seamlessly. It provides methods for various database operations. This package is designed to simplify database operations in Go applications, making it easier than ever to work with SQLite Cloud. In addition to the standard SQLite statements, several other commands are supported.
- Documentation: https://pkg.go.dev/github.com/sqlitecloud/sqlitecloud-go#section-documentation
- Source: https://github.com/sqlitecloud/sqlitecloud-go
- Site: https://sqlitecloud.io
-
Import the package in your Go source code:
import sqlitecloud "github.com/sqlitecloud/sqlitecloud-go"
-
Download the package, and run the
go mod tidy
command to synchronize your module's dependencies:$ go mod tidy go: downloading github.com/sqlitecloud/sqlitecloud-go v1.0.0
-
Connect to a SQLite Cloud database with a valid connection string:
db, err := sqlitecloud.Connect("sqlitecloud://user:pass@host.sqlite.cloud:port/dbname")
-
Execute queries using a method defined on the
SQCloud
struct, for exampleSelect
:result, _ := db.Select("SELECT * FROM table1;")
The following example shows how to print the content of the table table1
:
package main
import (
"fmt"
"strings"
sqlitecloud "github.com/sqlitecloud/sqlitecloud-go"
)
const connectionString = "sqlitecloud://admin:password@host.sqlite.cloud:8860/dbname.sqlite"
func main() {
db, err := sqlitecloud.Connect(connectionString)
if err != nil {
fmt.Println("Connect error: ", err)
}
tables, _ := db.ListTables()
fmt.Printf("Tables:\n\t%s\n", strings.Join(tables, "\n\t"))
fmt.Printf("Table1:\n")
result, _ := db.Select("SELECT * FROM t1;")
for r := uint64(0); r < result.GetNumberOfRows(); r++ {
id, _ := result.GetInt64Value(r, 0)
value, _ := result.GetStringValue(r, 1)
fmt.Printf("\t%d: %s\n", id, value)
}
}
You can connect to any cloud database using a special connection string in the form:
sqlitecloud://user:pass@host.com:port/dbname?timeout=10&key2=value2&key3=value3
To get a valid connection string, follow these instructions:
- Get a SQLite Cloud account. See the documentation for details.
- Create a SQLite Cloud project
- Create a SQLite Cloud database
- Get the connection string by clicking on the node address in the Dashboard Nodes section. A valid connection string will be copied to your clipboard.
- Add the database name to your connection string.
To start working on this project, follow these steps:
- Open the project folder in Visual Studio Code (VSCode) using the remote container feature.
- In the terminal, run the command
make setup-ide
to install the necessary development tools. - To ensure code quality, we have integrated pre-commit into the workflow. Before committing your changes to Git, pre-commit will run several tasks defined in the
.pre-commit-config.yaml
file.
By following these steps, you will have a fully set up development environment and be ready to contribute to the project.