diff --git a/go-sql-database/README.md b/go-sql-database/README.md index e69de29..297cebc 100644 --- a/go-sql-database/README.md +++ b/go-sql-database/README.md @@ -0,0 +1,6 @@ +# Learning SQL DB Access + + +Resources: + +http://go-database-sql.org/index.html It's the missing guide to the docs "how" to use the database/sql package. \ No newline at end of file diff --git a/go-sql-database/try-sqlite/data/trysqlite.db b/go-sql-database/try-sqlite/data/trysqlite.db index d1cb1d4..8c05135 100644 Binary files a/go-sql-database/try-sqlite/data/trysqlite.db and b/go-sql-database/try-sqlite/data/trysqlite.db differ diff --git a/go-sql-database/try-sqlite/data/trysqlite.db-shm b/go-sql-database/try-sqlite/data/trysqlite.db-shm index cbb8862..fe9ac28 100644 Binary files a/go-sql-database/try-sqlite/data/trysqlite.db-shm and b/go-sql-database/try-sqlite/data/trysqlite.db-shm differ diff --git a/go-sql-database/try-sqlite/data/trysqlite.db-wal b/go-sql-database/try-sqlite/data/trysqlite.db-wal index 1da2d5d..e69de29 100644 Binary files a/go-sql-database/try-sqlite/data/trysqlite.db-wal and b/go-sql-database/try-sqlite/data/trysqlite.db-wal differ diff --git a/go-sql-database/try-sqlite/main.go b/go-sql-database/try-sqlite/main.go index ed781e9..ddf7211 100644 --- a/go-sql-database/try-sqlite/main.go +++ b/go-sql-database/try-sqlite/main.go @@ -266,4 +266,7 @@ func main() { log.Fatal(err) } } + + // Each driver has it's own error types + } diff --git a/go-web-app/README.md b/go-web-app/README.md index d7c6d6d..0a7faaf 100644 --- a/go-web-app/README.md +++ b/go-web-app/README.md @@ -19,3 +19,15 @@ I've taken this project a bit further then the article. Follow on work can inclu - [ ] Runs test suite - [ ] Tarball release artifact on Promote - [ ] Deb release artifact on Promote + + +## Adding Libsql to a project + +First install the driver + +``` +go get github.com/tursodatabase/go-libsql +``` + +We will only use a local file for this project. We will will use `GO_WIKI_DB` environment variable to determine where the SQLite file is located. It will default to ./data like the previous file based system. + diff --git a/learn_go_with_tests/concurrency/CheckWebsites.go b/learn_go_with_tests/concurrency/CheckWebsites.go new file mode 100644 index 0000000..9438de0 --- /dev/null +++ b/learn_go_with_tests/concurrency/CheckWebsites.go @@ -0,0 +1,13 @@ +package concurrency + +type WebsiteChecker func(string) bool + +func CheckWebsites(wc WebsiteChecker, urls []string) map[string]bool { + results := make(map[string]bool) + + for _, url := range urls { + results[url] = wc(url) + } + + return results +} diff --git a/learn_go_with_tests/concurrency/CheckWebsites_test.go b/learn_go_with_tests/concurrency/CheckWebsites_test.go new file mode 100644 index 0000000..9a4ca69 --- /dev/null +++ b/learn_go_with_tests/concurrency/CheckWebsites_test.go @@ -0,0 +1,30 @@ +package concurrency + +import ( + "reflect" + "testing" +) + +func mockWebsiteChecker(url string) bool { + return url != "waat://furhurterwe.geds" +} + +func TestWebsites(t *testing.T) { + websites := []string{ + "http://google.com", + "http://hackaday.com", + "waat://furhurterwe.geds", + } + + want := map[string]bool{ + "http://google.com": true, + "http://hackaday.com": true, + "waat://furhurterwe.geds": false, + } + + got := CheckWebsites(mockWebsiteChecker, websites) + + if !reflect.DeepEqual(want, got) { + t.Fatalf("Wanted %v, got %v", want, got) + } +} diff --git a/learn_go_with_tests/concurrency/go.mod b/learn_go_with_tests/concurrency/go.mod new file mode 100644 index 0000000..88825ae --- /dev/null +++ b/learn_go_with_tests/concurrency/go.mod @@ -0,0 +1,3 @@ +module concurrency + +go 1.22.5