doc.go 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright (c) 2018 David Crawshaw <david@zentus.com>
  2. // Copyright (c) 2021 Ross Light <ross@zombiezen.com>
  3. //
  4. // Permission to use, copy, modify, and distribute this software for any
  5. // purpose with or without fee is hereby granted, provided that the above
  6. // copyright notice and this permission notice appear in all copies.
  7. //
  8. // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. //
  16. // SPDX-License-Identifier: ISC
  17. /*
  18. Package sqlite provides a Go interface to SQLite 3.
  19. The semantics of this package are deliberately close to the
  20. SQLite3 C API, so it is helpful to be familiar with
  21. http://www.sqlite.org/c3ref/intro.html.
  22. An SQLite connection is represented by a *sqlite.Conn.
  23. Connections cannot be used concurrently.
  24. A typical Go program will create a pool of connections
  25. (using Open to create a *sqlitex.Pool) so goroutines can
  26. borrow a connection while they need to talk to the database.
  27. This package assumes SQLite will be used concurrently by the
  28. process through several connections, so the build options for
  29. SQLite enable multi-threading and the shared cache:
  30. https://www.sqlite.org/sharedcache.html
  31. The implementation automatically handles shared cache locking,
  32. see the documentation on Stmt.Step for details.
  33. The optional SQLite 3 extensions compiled in are: session, FTS5, RTree, JSON1,
  34. and GeoPoly.
  35. This is not a database/sql driver. For helper functions that make some kinds of
  36. statements easier to write, see the sqlitex package.
  37. Statement Caching
  38. Statements are prepared with the Prepare and PrepareTransient methods.
  39. When using Prepare, statements are keyed inside a connection by the
  40. original query string used to create them. This means long-running
  41. high-performance code paths can write:
  42. stmt, err := conn.Prepare("SELECT ...")
  43. After all the connections in a pool have been warmed up by passing
  44. through one of these Prepare calls, subsequent calls are simply a
  45. map lookup that returns an existing statement.
  46. Streaming Blobs
  47. The sqlite package supports the SQLite incremental I/O interface for
  48. streaming blob data into and out of the the database without loading
  49. the entire blob into a single []byte.
  50. (This is important when working either with very large blobs, or
  51. more commonly, a large number of moderate-sized blobs concurrently.)
  52. Deadlines and Cancellation
  53. Every connection can have a done channel associated with it using
  54. the SetInterrupt method. This is typically the channel returned by
  55. a context.Context Done method.
  56. As database connections are long-lived, the SetInterrupt method can
  57. be called multiple times to reset the associated lifetime.
  58. Transactions
  59. SQLite transactions have to be managed manually with this package
  60. by directly calling BEGIN / COMMIT / ROLLBACK or
  61. SAVEPOINT / RELEASE/ ROLLBACK. The sqlitex has a Savepoint
  62. function that helps automate this.
  63. */
  64. package sqlite