Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #214 from skobkin/feature_postgresql_support
Browse files Browse the repository at this point in the history
[Partial] PostgreSQL support for magneticod
  • Loading branch information
boramalper authored Nov 27, 2020
2 parents 202cfc7 + ce393be commit 0a497e8
Show file tree
Hide file tree
Showing 5 changed files with 420 additions and 12 deletions.
10 changes: 9 additions & 1 deletion cmd/magneticod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ the repository `boramalper/magnetico`. Images are tagged as `d-vMAJOR.MINOR.PATC
## Usage
### Database
**magneticod** is designed to be able to use different database engines to store its data, but
currently only SQLite 3 is supported. The database file can be found in:
currently only SQLite 3 and PostgreSQL 9+ are supported.

#### SQLite

The database file can be found in:

- **On Linux**

Expand All @@ -45,6 +49,10 @@ currently only SQLite 3 is supported. The database file can be found in:
**magneticod** uses write-ahead logging (WAL) for its database, so there might be multiple
files while it is operating, but ``database.sqlite3`` is *the database*.

#### More engines (PostgreSQL and others)

You can read about other supported persistence engines [here](pkg/README.md).

### Using the Docker Image
You need to mount

Expand Down
10 changes: 4 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@ require (
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f // indirect
github.com/gorilla/mux v1.7.4
github.com/gorilla/schema v1.1.0
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6 // indirect
github.com/jackc/pgx/v4 v4.9.2
github.com/jessevdk/go-flags v1.4.0
github.com/kevinburke/go-bindata v3.16.0+incompatible // indirect
github.com/libp2p/go-sockaddr v0.0.1
github.com/mattn/go-sqlite3 v2.0.3+incompatible
github.com/pkg/errors v0.9.1
github.com/pkg/profile v1.4.0
github.com/willf/bloom v2.0.3+incompatible
go.uber.org/atomic v1.5.1 // indirect
go.uber.org/multierr v1.4.0 // indirect
go.uber.org/zap v1.14.0
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/lint v0.0.0-20200130185559-910be7a94367 // indirect
golang.org/x/net v0.0.0-20200222125558-5a598a2470a0 // indirect
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c
golang.org/x/text v0.3.2
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae
golang.org/x/text v0.3.3
golang.org/x/tools v0.0.0-20200221224223-e1da425f72fd // indirect
honnef.co/go/tools v0.0.1-2020.1.3 // indirect
)
Expand Down
25 changes: 24 additions & 1 deletion pkg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,33 @@
[![GoDoc](https://godoc.org/github.com/boramalper/magnetico?status.svg)](https://godoc.org/github.com/boramalper/magnetico)

- The most significant package is `persistence`, that abstracts access to the
magnetico databases with different engines (currently, only SQLite).
magnetico databases with different engines (currently, SQLite, stdout and partly PostgreSQL).

**For REST-ful magneticow API, see [https://app.swaggerhub.com/apis/boramalper/magneticow-api/](https://app.swaggerhub.com/apis/boramalper/magneticow-api/).**

## PostgreSQL database engine (only `magneticod` part implemented)

PostgreSQL database engine uses [PostgreSQL](https://www.postgresql.org/) to store indexed
torrents. It's more performant and flexible than SQLite but requires additional software configuration.

**WARNING:** `pg_trgm` extension required. You need to enable it for your database before starting `magneticod`:

```postgresql
CREATE EXTENSION pg_trgm;
```

Engine usage example:

```shell
magneticod --database=postgres://username:[email protected]:5432/database?schema=custom_schema_name&sslmode=disable
```

See [pgx repository](https://github.com/jackc/pgx/blob/master/stdlib/sql.go)
for more examples.

Optional parameter `schema` was added to choose which schema will be used to store magnetico tables,
sequences and indexes.

## Stdout Dummy Database Engine for magneticod

Stdout dummy database engine for **magneticod** prints a new [JSON Line](http://jsonlines.org/)
Expand Down
9 changes: 5 additions & 4 deletions pkg/persistence/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ const (
type databaseEngine uint8

const (
Sqlite3 databaseEngine = 1
Sqlite3 databaseEngine = 1
Postgres databaseEngine = 2
Stdout
)

Expand Down Expand Up @@ -113,12 +114,12 @@ func MakeDatabase(rawURL string, logger *zap.Logger) (Database, error) {
case "sqlite3":
return makeSqlite3Database(url_)

case "postgres":
return makePostgresDatabase(url_)

case "stdout":
return makeStdoutDatabase(url_)

case "postgresql":
return nil, fmt.Errorf("postgresql is not yet supported")

case "mysql":
return nil, fmt.Errorf("mysql is not yet supported")

Expand Down
Loading

0 comments on commit 0a497e8

Please sign in to comment.