package
0.0.0-20241009184404-4052853c1b79
Repository: https://github.com/erikbryant/shipahoy.git
Documentation: pkg.go.dev
# README
Installation
This application stores ship sightings in an SQL database. You need to have one installed and listening on 127.0.0.1:3306. It has been developed and tested with MySQL Community Server.
To easily access the mysql
binary, add /usr/local/mysql/bin
to the path.
SQL statements
If you already have restore files (ships.sql.gz
and sightings.sql.gz
) you can skip these steps. The restore.sh
script will do these for you.
CREATE DATABASE IF NOT EXISTS ship_ahoy;
CREATE USER IF NOT EXISTS 'ships'@'localhost' IDENTIFIED BY 'ships_password';
GRANT ALL ON ship_ahoy.* TO 'ships';
CREATE TABLE ships (
mmsi varchar(20) not null,
imo varchar(20) not null,
name varchar(40) not null,
ais int not null,
type varchar(128) not null,
sar boolean not null,
direct_link varchar(128) not null,
draught float not null,
year int not null,
gt int not null,
length int not null,
beam int not null,
dw int not null,
flag varchar(20) not null,
invalidDimensions boolean not null,
marineTrafficID int not null,
);
CREATE UNIQUE INDEX mmsi ON ships ( mmsi );
DELETE FROM ships;
ALTER TABLE ships DROP COLUMN unknown;
CREATE TABLE sightings (
mmsi varchar(20),
ship_course float,
timestamp int, # Unix datetime
lat float,
lon float,
my_lat float,
my_lon float
);
Database Backup / Restore
mysqldump -u ships -p db_name t1 > dump.sql
mysql -u ships -p db_name < dump.sql
# Functions
Close closes the connection to the database opened by Open.
CountRows returns the number of rows in the given table.
CountSightings counts the number of times we have seen this ship.
LookupLastSighting is [hopefully] faster than dbLookupSighting() because it only queries the timestamp.
LookupShip reads ship details from the database.
LookupShipExists is [hopefully] faster than loading the entire record like dbLookupShip() does.
LookupSighting reads sighting details from the database.
Open opens a connection to the database.
SaveShip writes ship details to the database.
SaveSighting writes the ship sighting details to the database.
TableStats prints interesting statistics about the size of the database.