Skip to content

Commit 88da00a

Browse files
committed
Add migration tool
Fixes #1
1 parent c09c0c3 commit 88da00a

5 files changed

Lines changed: 809 additions & 1 deletion

File tree

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,28 @@
44

55
This package provides a low-level Go interface to SQLite 3. It is a fork of
66
[`crawshaw.io/sqlite`][] that uses [`modernc.org/sqlite`][]. It aims to be a
7-
mostly drop-in replacement for `crawshaw.io/sqlite`.
7+
mostly drop-in replacement for `crawshaw.io/sqlite`. See the [migration docs][]
8+
for instructions on how to migrate.
89

910
[`crawshaw.io/sqlite`]: https://github.com/crawshaw.io/sqlite
1011
[`modernc.org/sqlite`]: https://pkg.go.dev/modernc.org/sqlite
12+
[migration docs]: cmd/zombiezen-sqlite-migrate/README.md
1113

1214
## Install
1315

1416
```shell
1517
go get zombiezen.com/go/sqlite
1618
```
1719

20+
## Getting Started
21+
22+
If you're creating a new application, see the [package examples][].
23+
24+
If you're looking to switch existing code that uses `crawshaw.io/sqlite`, take
25+
a look at the [migration docs][].
26+
27+
[package examples]: https://pkg.go.dev/zombiezen.com/go/sqlite#pkg-examples
28+
1829
## License
1930

2031
Mostly ISC, with some code borrowed from `modernc.org/sqlite`, which is under a
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module zombiezen.com/go/sqlite/cmd/zombiezen-sqlite-migrate
2+
3+
go 1.16
4+
5+
require (
6+
golang.org/x/tools v0.1.0
7+
zombiezen.com/go/bass v0.0.0-20210402215001-cb0af0b391a4
8+
)

0 commit comments

Comments
 (0)