|
| 1 | +# Migrating from `crawshaw.io/sqlite` |
| 2 | + |
| 3 | +`zombiezen.com/go/sqlite` is designed to mostly be a drop-in replacement for |
| 4 | +`crawshaw.io/sqlite`. However, there are some incompatible API changes. To aid |
| 5 | +in migrating, I've prepared a program that rewrites Go source code using |
| 6 | +`crawshaw.io/sqlite` to use `zombiezen.com/go/sqlite`. |
| 7 | + |
| 8 | +## Installation |
| 9 | + |
| 10 | +```shell |
| 11 | +go install zombiezen.com/go/sqlite/cmd/zombiezen-sqlite-migrate@latest |
| 12 | +``` |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +Preview changes with: |
| 17 | + |
| 18 | +```shell |
| 19 | +zombiezen-sqlite-migrate ./... |
| 20 | +``` |
| 21 | + |
| 22 | +And then apply them with: |
| 23 | + |
| 24 | +```shell |
| 25 | +zombiezen-sqlite-migrate -w ./... |
| 26 | +``` |
| 27 | + |
| 28 | +## Automatically fixed changes |
| 29 | + |
| 30 | +The `zombiezen-sqlite-migrate` tool automatically makes a number of mechanical |
| 31 | +changes beyond changing the import paths to preserve semantics. |
| 32 | + |
| 33 | +### `ErrorCode` to `ResultCode` |
| 34 | + |
| 35 | +The `crawshaw.io/sqlite.ErrorCode` type actually represents a SQLite |
| 36 | +[result code][], not just error codes. To better capture this, the new type |
| 37 | +is named `zombiezen.com/go/sqlite.ResultCode`. |
| 38 | + |
| 39 | +[result code]: https://sqlite.org/rescode.html |
| 40 | + |
| 41 | +### Friendlier constant names |
| 42 | + |
| 43 | +The constant names in `crawshaw.io/sqlite` are written in upper snake case with |
| 44 | +`SQLITE_` prefixed (e.g. `sqlite.SQLITE_OK`); the constant names in |
| 45 | +`zombiezen.com/go/sqlite` are written in upper camel case with the type prefixed |
| 46 | +(e.g. `sqlite.ResultOK`). |
| 47 | + |
| 48 | +## Changes that require manual effort |
| 49 | + |
| 50 | +Other usages of the `crawshaw.io/sqlite` may require manual effort to migrate, |
| 51 | +but the `zombiezen-sqlite-migrate` tool will point them out. |
| 52 | + |
| 53 | +### Application-Defined Functions |
| 54 | + |
| 55 | +The `crawshaw.io/sqlite.Conn.CreateFunction` method and supporting APIs like |
| 56 | +`Context` and `Value` have been re-tooled in `zombiezen.com/go/sqlite` with |
| 57 | +better ergonomics. See the [`CreateFunction` reference][] for more details. |
| 58 | + |
| 59 | +[`CreateFunction` reference]: https://pkg.go.dev/zombiezen.com/go/sqlite#Conn.CreateFunction |
| 60 | + |
| 61 | +### Removed `Blob` methods |
| 62 | + |
| 63 | +`zombiezen.com/go/sqlite.Blob` does not implement the [`io.ReaderAt`][] or |
| 64 | +[`io.WriterAt`][] interfaces. Technically, neither did `crawshaw.io/sqlite.Blob`, |
| 65 | +because it was not safe to call in parallel, which these interfaces require. |
| 66 | +To avoid these methods being used incorrectly, I removed them. |
| 67 | + |
| 68 | +I also removed the unused embedded interface fields. |
| 69 | + |
| 70 | +[`io.ReaderAt`]: https://pkg.go.dev/io#ReaderAt |
| 71 | +[`io.WriterAt`]: https://pkg.go.dev/io#WriterAt |
| 72 | + |
| 73 | +### No dedicated `sqlite.Error` type |
| 74 | + |
| 75 | +I don't want to commit to a specific error type in `zombiezen.com/go/sqlite`, so |
| 76 | +there I removed the `Error` type. [`zombiezen.com/go/sqlite.ErrCode`][] still |
| 77 | +extracts the `ResultCode` from an `error`, which covers most needs. |
| 78 | + |
| 79 | +[`zombiezen.com/go/sqlite.ErrCode`]: https://pkg.go.dev/zombiezen.com/go/sqlite#ErrCode |
0 commit comments