Skip to content

Commit

Permalink
Fix #19 and misc. stuff, enable CGO everywhere (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored Dec 29, 2024
1 parent 3fcfb9d commit a031f39
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 63 deletions.
24 changes: 21 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ version: 2.1
jobs:
linux:
docker:
- image: cimg/go:1.18
- image: cimg/go:1.23
steps:
- checkout
- restore_cache:
keys:
- pod-babashka-go-sqlite3-{{ checksum "go.sum" }}-{{ checksum ".circleci/config.yml" }}
- run:
name: Build binary
environment:
CGO_ENABLED: "1"
GOOS: linux
GOARCH: amd64
command: go build -tags "fts5" -o pod-babashka-go-sqlite3 main.go
- run:
name: Install bb for test
Expand Down Expand Up @@ -91,15 +95,25 @@ jobs:
# - pod-babashka-go-sqlite3-{{ checksum "go.sum" }}-{{ checksum ".circleci/config.yml" }}
- run:
name: Build binary
environment:
CGO_ENABLED: "1"
GOOS: darwin
GOARCH: amd64
command: |
source /Users/$(whoami)/.bashrc
GOARCH=amd64 go build -tags "fts5" -o pod-babashka-go-sqlite3 main.go
echo $CGO_ENABLED
echo $GOARCH
go build -tags "fts5" -o pod-babashka-go-sqlite3 main.go
- run:
name: Install bb for test
command: |
mkdir bb
bash <(curl -sL https://raw.githubusercontent.com/borkdude/babashka/master/install) \
--dir bb --download-dir bb
- run:
name: Install Rosetta
command: |
sudo /usr/sbin/softwareupdate --install-rosetta --agree-to-license
- run:
name: Run test
command: |
Expand Down Expand Up @@ -133,9 +147,13 @@ jobs:
# - pod-babashka-go-sqlite3-{{ checksum "go.sum" }}-{{ checksum ".circleci/config.yml" }}
- run:
name: Build binary
environment:
CGO_ENABLED: "1"
GOOS: darwin
GOARCH: arm64
command: |
source /Users/$(whoami)/.bashrc
GOARCH=arm64 go build -tags "fts5" -o pod-babashka-go-sqlite3 main.go
go build -tags "fts5" -o pod-babashka-go-sqlite3 main.go
- run:
name: Install bb for test
command: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ pod-babashka-go-sqlite3
.clj-kondo/
.nrepl-port
.lsp/
pod-babashka-go-sqlite3-test
94 changes: 50 additions & 44 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,57 @@
---

version: "v-{build}"

image: Visual Studio 2019

clone_folder: C:\projects\babashka

environment:
GOPATH: C:\gopath
CGO_ENABLED: 1
GOVERSION: 119
---

version: "v-{build}"

image: Visual Studio 2019

clone_folder: C:\projects\babashka

environment:
GOPATH: C:\gopath
CGO_ENABLED: 1
GOVERSION: 123

install:
- set GOROOT=C:\go%GOVERSION%
- set PATH=%GOPATH%\bin;%GOROOT%\bin;%PATH%
- go version
- go env

cache:
- 'C:/gopath/pkg/mod -> go.sum, appveyor.yml'

clone_script:
- ps: >-
if(-not $env:APPVEYOR_PULL_REQUEST_NUMBER) {
git clone -q --branch=$env:APPVEYOR_REPO_BRANCH https://github.com/$env:APPVEYOR_REPO_NAME.git $env:APPVEYOR_BUILD_FOLDER
cd $env:APPVEYOR_BUILD_FOLDER
git checkout -qf $env:APPVEYOR_REPO_COMMIT
} else {
git clone -q https://github.com/$env:APPVEYOR_REPO_NAME.git $env:APPVEYOR_BUILD_FOLDER
cd $env:APPVEYOR_BUILD_FOLDER
git fetch -q origin +refs/pull/$env:APPVEYOR_PULL_REQUEST_NUMBER/merge:
git checkout -qf FETCH_HEAD
}
- cmd: git submodule update --init --recursive

build_script:

- cmd: >-
set PATH=C:\msys64\mingw64\bin;%PATH%
go build -tags "fts5" -o pod-babashka-go-sqlite3.exe main.go
set /P VERSION=< resources\POD_BABASHKA_GO_SQLITE3_VERSION
jar -cMf pod-babashka-go-sqlite3-%VERSION%-windows-amd64.zip pod-babashka-go-sqlite3.exe
artifacts:
- path: pod-babashka-go-sqlite3-*-windows-amd64.zip
name: pod-babashka-go-sqlite3
cache:
- 'C:/gopath/pkg/mod -> go.sum, appveyor.yml'

clone_script:
- ps: >-
if(-not $env:APPVEYOR_PULL_REQUEST_NUMBER) {
git clone -q --branch=$env:APPVEYOR_REPO_BRANCH https://github.com/$env:APPVEYOR_REPO_NAME.git $env:APPVEYOR_BUILD_FOLDER
cd $env:APPVEYOR_BUILD_FOLDER
git checkout -qf $env:APPVEYOR_REPO_COMMIT
} else {
git clone -q https://github.com/$env:APPVEYOR_REPO_NAME.git $env:APPVEYOR_BUILD_FOLDER
cd $env:APPVEYOR_BUILD_FOLDER
git fetch -q origin +refs/pull/$env:APPVEYOR_PULL_REQUEST_NUMBER/merge:
git checkout -qf FETCH_HEAD
}
- cmd: git submodule update --init --recursive

build_script:

- cmd: >-
set PATH=C:\msys64\mingw64\bin;%PATH%
go build -tags "fts5" -o pod-babashka-go-sqlite3.exe main.go
set /P VERSION=< resources\POD_BABASHKA_GO_SQLITE3_VERSION
jar -cMf pod-babashka-go-sqlite3-%VERSION%-windows-amd64.zip pod-babashka-go-sqlite3.exe
powershell -Command "if (Test-Path('bb.exe')) { return } else { (New-Object Net.WebClient).DownloadFile('https://github.com/babashka/babashka-dev-builds/releases/download/v1.0.169-SNAPSHOT/babashka-1.0.169-SNAPSHOT-windows-amd64.zip', 'bb.zip') }"
powershell -Command "if (Test-Path('bb.exe')) { return } else { Expand-Archive bb.zip . }"
call bb test/script.clj
artifacts:
- path: pod-babashka-go-sqlite3-*-windows-amd64.zip
name: pod-babashka-go-sqlite3
3 changes: 2 additions & 1 deletion script/test
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash

go build -tags "fts5" -o pod-babashka-go-sqlite3-test main.go && test/script.clj
# go build -tags "fts5" -o pod-babashka-go-sqlite3-test main.go
test/script.clj
33 changes: 18 additions & 15 deletions test/script.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,32 @@
(ns script
(:require [babashka.pods :as pods]
[clojure.java.io :as io]
[babashka.fs :as fs]
[clojure.test :as t :refer [deftest is testing]]))

(prn (pods/load-pod "./pod-babashka-go-sqlite3-test"))
(prn (pods/load-pod "./pod-babashka-go-sqlite3"))

(require '[pod.babashka.go-sqlite3 :as sqlite])

(.delete (io/file "/tmp/foo.db"))
(def temp-file (str (fs/file (fs/temp-dir) "foo.db")))

(prn (sqlite/execute! "/tmp/foo.db" ["create table if not exists foo (the_text TEXT, the_int INTEGER, the_real REAL, the_blob BLOB, the_json JSON)"]))
(prn (sqlite/execute! "/tmp/foo.db" ["delete from foo"]))
(fs/delete-if-exists temp-file)

(prn (sqlite/execute! temp-file ["create table if not exists foo (the_text TEXT, the_int INTEGER, the_real REAL, the_blob BLOB, the_json JSON)"]))
(prn (sqlite/execute! temp-file ["delete from foo"]))

(def png (java.nio.file.Files/readAllBytes (.toPath (io/file "resources/babashka.png"))))

(prn (sqlite/execute! "/tmp/foo.db" ["insert into foo (the_text, the_int, the_real, the_blob, the_json) values (?,?,?,?,?)" "foo" 1 3.14 png "{\"bar\": \"hello\"}"]))
(prn (sqlite/execute! "/tmp/foo.db" ["insert into foo (the_text, the_int, the_real) values (?,?,?)" "foo" 2 1.5]))
(prn (sqlite/execute! temp-file ["insert into foo (the_text, the_int, the_real, the_blob, the_json) values (?,?,?,?,?)" "foo" 1 3.14 png "{\"bar\": \"hello\"}"]))
(prn (sqlite/execute! temp-file ["insert into foo (the_text, the_int, the_real) values (?,?,?)" "foo" 2 1.5]))

(testing "multiple results"
(prn (sqlite/execute! "/tmp/foo.db"
(prn (sqlite/execute! temp-file
["insert into foo (the_text, the_int, the_real) values (?,?,?), (?,?,?)"
"bar" 3 1.5
"baz" 4 1.5])))

(def results (sqlite/query "/tmp/foo.db" ["select * from foo order by the_int asc"]))
(def results (sqlite/query temp-file ["select * from foo order by the_int asc"]))

(def results-min-png (mapv #(dissoc % :the_blob :the_json) results))

Expand All @@ -37,7 +40,7 @@
(deftest results-test
(is (= expected results-min-png)))

(def direct-results (sqlite/query "/tmp/foo.db" "select * from foo order by the_int asc"))
(def direct-results (sqlite/query temp-file "select * from foo order by the_int asc"))

(def direct-results-min-png (mapv #(dissoc % :the_blob :the_json) direct-results))

Expand All @@ -47,27 +50,27 @@
(deftest bytes-roundtrip
(is (= (count png) (count (get-in results [0 :the_blob])))))

(def json-field-result (sqlite/query "/tmp/foo.db" ["select the_json->>'$.bar' as bar from foo where the_json is not null"]))
(def json-field-result (sqlite/query temp-file ["select the_json->>'$.bar' as bar from foo where the_json is not null"]))

(deftest json-field-test
(is (= [{:bar "hello"}] json-field-result)))

(deftest error-test
(is (thrown-with-msg?
Exception #"no such column: non_existing"
(sqlite/query "/tmp/foo.db" ["select non_existing from foo"])))
(sqlite/query temp-file ["select non_existing from foo"])))
(is (thrown-with-msg?
Exception #"unexpected query type, expected a string or a vector"
(sqlite/query "/tmp/foo.db" 42)))
(sqlite/query temp-file 42)))
(is (thrown-with-msg?
Exception #"the sqlite connection must be a string"
(sqlite/query nil "select * from foo order by the_int asc"))))

(deftest fts50-test
(sqlite/execute! "/tmp/foo.db" ["CREATE VIRTUAL TABLE email USING fts5(sender, title, body)"])
(sqlite/execute! "/tmp/foo.db" ["INSERT INTO email VALUES('foo', 'bar', 'baz')"])
(sqlite/execute! temp-file ["CREATE VIRTUAL TABLE email USING fts5(sender, title, body)"])
(sqlite/execute! temp-file ["INSERT INTO email VALUES('foo', 'bar', 'baz')"])
(is (= [{:sender "foo" :title "bar" :body "baz"}]
(sqlite/query "/tmp/foo.db"
(sqlite/query temp-file
["SELECT * FROM email WHERE email MATCH 'baz';"]))))

(let [{:keys [:fail :error]} (t/run-tests)]
Expand Down

0 comments on commit a031f39

Please sign in to comment.