Example_libSQL demonstrates use of River's SQLite driver with libSQL (a SQLite fork).
()
| 15 | // Example_libSQL demonstrates use of River's SQLite driver with libSQL (a |
| 16 | // SQLite fork). |
| 17 | func Example_libSQL() { //nolint:dupl |
| 18 | ctx := context.Background() |
| 19 | |
| 20 | dbPool, err := sql.Open("libsql", "file:./example_libsql_test.libsql") |
| 21 | if err != nil { |
| 22 | panic(err) |
| 23 | } |
| 24 | dbPool.SetMaxOpenConns(1) |
| 25 | defer dbPool.Close() |
| 26 | |
| 27 | driver := riversqlite.New(dbPool) |
| 28 | |
| 29 | if err := migrateDB(ctx, driver); err != nil { |
| 30 | panic(err) |
| 31 | } |
| 32 | |
| 33 | workers := river.NewWorkers() |
| 34 | river.AddWorker(workers, &SortWorker{}) |
| 35 | |
| 36 | riverClient, err := river.NewClient(driver, initTestConfig(ctx, nil, &river.Config{ |
| 37 | Queues: map[string]river.QueueConfig{ |
| 38 | river.QueueDefault: {MaxWorkers: 100}, |
| 39 | }, |
| 40 | Workers: workers, |
| 41 | })) |
| 42 | if err != nil { |
| 43 | panic(err) |
| 44 | } |
| 45 | |
| 46 | // Out of example scope, but used to wait until a job is worked. |
| 47 | subscribeChan, subscribeCancel := riverClient.Subscribe(river.EventKindJobCompleted) |
| 48 | defer subscribeCancel() |
| 49 | |
| 50 | if err := riverClient.Start(ctx); err != nil { |
| 51 | panic(err) |
| 52 | } |
| 53 | |
| 54 | _, err = riverClient.Insert(ctx, SortArgs{ |
| 55 | Strings: []string{ |
| 56 | "whale", "tiger", "bear", |
| 57 | }, |
| 58 | }, nil) |
| 59 | if err != nil { |
| 60 | panic(err) |
| 61 | } |
| 62 | |
| 63 | // Wait for jobs to complete. Only needed for purposes of the example test. |
| 64 | riversharedtest.WaitOrTimeoutN(testutil.PanicTB(), subscribeChan, 1) |
| 65 | |
| 66 | if err := riverClient.Stop(ctx); err != nil { |
| 67 | panic(err) |
| 68 | } |
| 69 | |
| 70 | // Output: |
| 71 | // Sorted strings: [bear tiger whale] |
| 72 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…