|
1 | | -# SQLite Cloud GO Client |
2 | 1 |
|
3 | | -### Run the test for the SDK |
4 | | -If you want to run the Test programs: `make test` |
| 2 | +# Introduction |
5 | 3 |
|
6 | | -### Building the CLI App |
7 | | -To build the CLI App, you have to enter: `make cli` |
| 4 | +The SQLite Cloud Client SDK for Go (sqlitecloud/go-sdk) is the Go Programming Language application programmer's interface to [SQLite Cloud](https://sqlitecloud.io/). |
8 | 5 |
|
9 | | -### Build all at the same time: |
10 | | -If you want to do all at the same time: `make all` |
| 6 | +It is a set of library functions that allow client programs to pass queries and SQL commands to the SQLite Cloud backend server and to receive the results of these queries. In addition to the standard SQLite statements, several other [commands](https://docs.sqlitecloud.io/docs/commands) are supported. |
11 | 7 |
|
12 | | -## Documentation |
13 | | -If you want to see the Documentation: `make doc` - Warning: A browser window will open and display the documentation to you. The Documentation is updated live while coding. To stop the live mode, press CRTL-C on the command line. |
| 8 | +# Getting Started |
14 | 9 |
|
15 | | -## Development helpers |
16 | | -- Check files with gosec: `make checksec` |
17 | | -- Open the repo in github: `make github`. |
18 | | -- See changes: `make diff` |
19 | | -- Clean dependencies and precompiled code: `make clean` |
| 10 | +## Use the SQLite Cloud Client SDK in your Go code |
| 11 | + |
| 12 | +1. Import the package in your Go source code |
| 13 | + |
| 14 | + ``` |
| 15 | + import sqlitecloud "github.com/sqlitecloud/go-sdk" |
| 16 | + ``` |
| 17 | + |
| 18 | +2. download the package, run the [`go mod tidy` command](https://go.dev/ref/mod#go-mod-tidy) to synchronize your module's dependencies: |
| 19 | + |
| 20 | + ``` |
| 21 | + $ go mod tidy |
| 22 | + go: downloading github.com/sqlitecloud/go-sdk v1.0.0 |
| 23 | + ``` |
| 24 | + |
| 25 | +3. Connect to SQLite Cloud database with a valid [connection string](#get-a-connection-string) |
| 26 | + |
| 27 | + ``` |
| 28 | + db, err := sqlitecloud.Connect("sqlitecloud://user:pass@host.sqlite.cloud:port/dbname") |
| 29 | + ``` |
| 30 | + |
| 31 | +4. Execute queries using a [method](#api-documentation) defined on the `SQCloud` struct, for example `Select`: |
| 32 | + |
| 33 | + ``` |
| 34 | + result, _ := db.Select("SELECT * FROM table1;") |
| 35 | + ``` |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +The following example shows how to print the content of the table `table1`: |
| 40 | + |
| 41 | +``` |
| 42 | +package main |
| 43 | +
|
| 44 | +import ( |
| 45 | + "fmt" |
| 46 | + "strings" |
| 47 | +
|
| 48 | + sqlitecloud "github.com/sqlitecloud/go-sdk" |
| 49 | +) |
| 50 | +
|
| 51 | +const connectionString = "sqlitecloud://admin:password@host.sqlite.cloud:8860/dbname.sqlite" |
| 52 | +
|
| 53 | +func main() { |
| 54 | + db, err := sqlitecloud.Connect(connectionString) |
| 55 | + if err != nil { |
| 56 | + fmt.Println("Connect error: ", err) |
| 57 | + } |
| 58 | +
|
| 59 | + tables, _ := db.ListTables() |
| 60 | + fmt.Printf("Tables: \n\t%s\n", strings.Join(tables, "\n\t")) |
| 61 | +
|
| 62 | + fmt.Printf("Table1:\n") |
| 63 | + result, _ := db.Select("SELECT * FROM t1;") |
| 64 | + for r := uint64(0); r < result.GetNumberOfRows(); r++ { |
| 65 | + id, _ := result.GetInt64Value(r, 0) |
| 66 | + value, _ := result.GetStringValue(r, 1) |
| 67 | + fmt.Printf("\t%d: %s\n", id, value) |
| 68 | + } |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +## Get a connection string |
| 73 | + |
| 74 | +You can connect to any cloud database using a special connection string in the form: |
| 75 | + |
| 76 | +`sqlitecloud://user:pass@host.com:port/dbname?timeout=10&key2=value2&key3=value3` |
| 77 | + |
| 78 | +To get a valid connection string just follow these instructions: |
| 79 | + |
| 80 | +- Get a [SQLite Cloud](https://sqlitecloud.io/) account. See the [documentation](https://docs.sqlitecloud.io/docs/introduction/login) for details. |
| 81 | +- Create a [SQLite Cloud project](https://docs.sqlitecloud.io/docs/introduction/projects) |
| 82 | +- Create a [SQLite Cloud database](https://docs.sqlitecloud.io/docs/introduction/databases) |
| 83 | +- Get the connection string by clicking on the node address in the [Dashboard Nodes](https://docs.sqlitecloud.io/docs/introduction/nodes) section. A valid connection string for twill be copied in your clipboard. |
| 84 | +- add the database name to your connection string |
| 85 | + |
| 86 | +## API Documentation |
| 87 | + |
| 88 | +The complete documentation of the sqlitecloud/go-sdk library is available at: https://pkg.go.dev/github.com/sqlitecloud/go-sdk |
0 commit comments