New upstream version 1.14.14~ds1
Mathias Gibbens
1 year, 10 months ago
0 | name: dockerfile | |
1 | ||
2 | on: | |
3 | workflow_dispatch: | |
4 | push: | |
5 | tags: | |
6 | - 'v*' | |
7 | pull_request: | |
8 | branches: [ master ] | |
9 | ||
10 | jobs: | |
11 | dockerfile: | |
12 | name: Run Dockerfiles in examples | |
13 | runs-on: ubuntu-latest | |
14 | steps: | |
15 | - uses: actions/checkout@v2 | |
16 | ||
17 | - name: Run example - simple | |
18 | run: | | |
19 | cd ./_example/simple | |
20 | docker build -t simple . | |
21 | docker run simple | grep 99\ こんにちわ世界099 |
13 | 13 | strategy: |
14 | 14 | matrix: |
15 | 15 | os: [ubuntu-latest, macos-latest] |
16 | go: ['1.15', '1.16', '1.17'] | |
16 | go: ['1.16', '1.17', '1.18'] | |
17 | 17 | fail-fast: false |
18 | 18 | env: |
19 | 19 | OS: ${{ matrix.os }} |
28 | 28 | |
29 | 29 | - name: Get Build Tools |
30 | 30 | run: | |
31 | GO111MODULE=on go get github.com/ory/go-acc | |
31 | GO111MODULE=on go install github.com/ory/go-acc@latest | |
32 | 32 | |
33 | 33 | - name: Add $GOPATH/bin to $PATH |
34 | 34 | run: | |
63 | 63 | |
64 | 64 | strategy: |
65 | 65 | matrix: |
66 | go: ['1.15', '1.16', '1.17'] | |
66 | go: ['1.16', '1.17', '1.18'] | |
67 | 67 | fail-fast: false |
68 | 68 | env: |
69 | 69 | OS: windows-latest |
0 | # ============================================================================= | |
1 | # Multi-stage Dockerfile Example | |
2 | # ============================================================================= | |
3 | # This is a simple Dockerfile that will build an image of scratch-base image. | |
4 | # Usage: | |
5 | # docker build -t simple:local . && docker run --rm simple:local | |
6 | # ============================================================================= | |
7 | ||
8 | # ----------------------------------------------------------------------------- | |
9 | # Build Stage | |
10 | # ----------------------------------------------------------------------------- | |
11 | FROM golang:alpine AS build | |
12 | ||
13 | # Important: | |
14 | # Because this is a CGO enabled package, you are required to set it as 1. | |
15 | ENV CGO_ENABLED=1 | |
16 | ||
17 | RUN apk add --no-cache \ | |
18 | # Important: required for go-sqlite3 | |
19 | gcc \ | |
20 | # Required for Alpine | |
21 | musl-dev | |
22 | ||
23 | WORKDIR /workspace | |
24 | ||
25 | COPY . /workspace/ | |
26 | ||
27 | RUN \ | |
28 | go mod init github.com/mattn/sample && \ | |
29 | go mod tidy && \ | |
30 | go install -ldflags='-s -w -extldflags "-static"' ./simple.go | |
31 | ||
32 | RUN \ | |
33 | # Smoke test | |
34 | set -o pipefail; \ | |
35 | /go/bin/simple | grep 99\ こんにちわ世界099 | |
36 | ||
37 | # ----------------------------------------------------------------------------- | |
38 | # Main Stage | |
39 | # ----------------------------------------------------------------------------- | |
40 | FROM scratch | |
41 | ||
42 | COPY --from=build /go/bin/simple /usr/local/bin/simple | |
43 | ||
44 | ENTRYPOINT [ "/usr/local/bin/simple" ] |
41 | 41 | log.Fatal(err) |
42 | 42 | } |
43 | 43 | } |
44 | tx.Commit() | |
44 | err = tx.Commit() | |
45 | if err != nil { | |
46 | log.Fatal(err) | |
47 | } | |
45 | 48 | |
46 | 49 | rows, err := db.Query("select id, name from foo") |
47 | 50 | if err != nil { |
352 | 352 | return nil |
353 | 353 | } |
354 | 354 | |
355 | func callbackRetGeneric(ctx *C.sqlite3_context, v reflect.Value) error { | |
356 | if v.IsNil() { | |
357 | C.sqlite3_result_null(ctx) | |
358 | return nil | |
359 | } | |
360 | ||
361 | cb, err := callbackRet(v.Elem().Type()) | |
362 | if err != nil { | |
363 | return err | |
364 | } | |
365 | ||
366 | return cb(ctx, v.Elem()) | |
367 | } | |
368 | ||
355 | 369 | func callbackRet(typ reflect.Type) (callbackRetConverter, error) { |
356 | 370 | switch typ.Kind() { |
357 | 371 | case reflect.Interface: |
359 | 373 | if typ.Implements(errorInterface) { |
360 | 374 | return callbackRetNil, nil |
361 | 375 | } |
376 | ||
377 | if typ.NumMethod() == 0 { | |
378 | return callbackRetGeneric, nil | |
379 | } | |
380 | ||
362 | 381 | fallthrough |
363 | 382 | case reflect.Slice: |
364 | 383 | if typ.Elem().Kind() != reflect.Uint8 { |
101 | 101 | } |
102 | 102 | } |
103 | 103 | } |
104 | ||
105 | func TestCallbackReturnAny(t *testing.T) { | |
106 | udf := func() interface{} { | |
107 | return 1 | |
108 | } | |
109 | ||
110 | typ := reflect.TypeOf(udf) | |
111 | _, err := callbackRet(typ.Out(0)) | |
112 | if err != nil { | |
113 | t.Errorf("Expected valid callback for any return type, got: %s", err) | |
114 | } | |
115 | } |
0 | // Copyright (C) 2019 Yasuhiro Matsumoto <mattn.jp@gmail.com>. | |
1 | // | |
2 | // Use of this source code is governed by an MIT-style | |
3 | // license that can be found in the LICENSE file. | |
4 | ||
5 | // +build sqlite_json sqlite_json1 json1 | |
6 | ||
7 | package sqlite3 | |
8 | ||
9 | /* | |
10 | #cgo CFLAGS: -DSQLITE_ENABLE_JSON1 | |
11 | */ | |
12 | import "C" |
32 | 32 | // The callback is passed a SQLitePreUpdateData struct with the data for |
33 | 33 | // the update, as well as methods for fetching copies of impacted data. |
34 | 34 | // |
35 | // If there is an existing update hook for this connection, it will be | |
35 | // If there is an existing preupdate hook for this connection, it will be | |
36 | 36 | // removed. If callback is nil the existing hook (if any) will be removed |
37 | 37 | // without creating a new one. |
38 | 38 | func (c *SQLiteConn) RegisterPreUpdateHook(callback func(SQLitePreUpdateData)) { |
12 | 12 | // The callback is passed a SQLitePreUpdateData struct with the data for |
13 | 13 | // the update, as well as methods for fetching copies of impacted data. |
14 | 14 | // |
15 | // If there is an existing update hook for this connection, it will be | |
15 | // If there is an existing preupdate hook for this connection, it will be | |
16 | 16 | // removed. If callback is nil the existing hook (if any) will be removed |
17 | 17 | // without creating a new one. |
18 | 18 | func (c *SQLiteConn) RegisterPreUpdateHook(callback func(SQLitePreUpdateData)) { |
1445 | 1445 | if ret != test.sum { |
1446 | 1446 | t.Fatalf("Custom sum returned wrong value, got %d, want %d", ret, test.sum) |
1447 | 1447 | } |
1448 | } | |
1449 | } | |
1450 | ||
1451 | type mode struct { | |
1452 | counts map[interface{}]int | |
1453 | top interface{} | |
1454 | topCount int | |
1455 | } | |
1456 | ||
1457 | func newMode() *mode { | |
1458 | return &mode{ | |
1459 | counts: map[interface{}]int{}, | |
1460 | } | |
1461 | } | |
1462 | ||
1463 | func (m *mode) Step(x interface{}) { | |
1464 | m.counts[x]++ | |
1465 | c := m.counts[x] | |
1466 | if c > m.topCount { | |
1467 | m.top = x | |
1468 | m.topCount = c | |
1469 | } | |
1470 | } | |
1471 | ||
1472 | func (m *mode) Done() interface{} { | |
1473 | return m.top | |
1474 | } | |
1475 | ||
1476 | func TestAggregatorRegistration_GenericReturn(t *testing.T) { | |
1477 | sql.Register("sqlite3_AggregatorRegistration_GenericReturn", &SQLiteDriver{ | |
1478 | ConnectHook: func(conn *SQLiteConn) error { | |
1479 | return conn.RegisterAggregator("mode", newMode, true) | |
1480 | }, | |
1481 | }) | |
1482 | db, err := sql.Open("sqlite3_AggregatorRegistration_GenericReturn", ":memory:") | |
1483 | if err != nil { | |
1484 | t.Fatal("Failed to open database:", err) | |
1485 | } | |
1486 | defer db.Close() | |
1487 | ||
1488 | _, err = db.Exec("create table foo (department integer, profits integer)") | |
1489 | if err != nil { | |
1490 | t.Fatal("Failed to create table:", err) | |
1491 | } | |
1492 | _, err = db.Exec("insert into foo values (1, 10), (1, 20), (1, 45), (2, 42), (2, 115), (2, 20)") | |
1493 | if err != nil { | |
1494 | t.Fatal("Failed to insert records:", err) | |
1495 | } | |
1496 | ||
1497 | var mode int | |
1498 | err = db.QueryRow("select mode(profits) from foo").Scan(&mode) | |
1499 | if err != nil { | |
1500 | t.Fatal("MODE query error:", err) | |
1501 | } | |
1502 | ||
1503 | if mode != 20 { | |
1504 | t.Fatal("Got incorrect mode. Wanted 20, got: ", mode) | |
1448 | 1505 | } |
1449 | 1506 | } |
1450 | 1507 |