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

Commit

Permalink
Refactor to un-export some vars
Browse files Browse the repository at this point in the history
  • Loading branch information
fischersean committed Apr 15, 2021
1 parent 47ef013 commit 6152cf7
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*.db
.dolt

resources/
*.ignore
*/dist/*
Expand Down
14 changes: 7 additions & 7 deletions internal/database/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ const (

func Connect(input ConnectionInput) (conn Connection, err error) {

conn.EtlResultsTable = os.Getenv("ETL_RESULTS_TABLE")
conn.RedditPostArchiveBucket = os.Getenv("REDDIT_ARCHIVE_BUCKET")
conn.etlResultsTable = os.Getenv("ETL_RESULTS_TABLE")
conn.redditPostArchiveBucket = os.Getenv("REDDIT_ARCHIVE_BUCKET")

if conn.EtlResultsTable == "" {
if conn.etlResultsTable == "" {
return conn, fmt.Errorf("Could not find required table name ETL_RESULTS_TABLE")
}

if conn.RedditPostArchiveBucket == "" {
if conn.redditPostArchiveBucket == "" {
return conn, fmt.Errorf("Could not find required table name REDDIT_ARCHIVE_BUCKET")
}

conn.Session = input.Session
conn.Service = dynamodb.New(conn.Session)
conn.S3Service = s3.New(conn.Session)
conn.session = input.Session
conn.service = dynamodb.New(conn.session)
conn.s3Service = s3.New(conn.session)

return conn, err
}
24 changes: 12 additions & 12 deletions internal/database/etl.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ func (c *Connection) PutRedditPostArchiveRecord(record RedditPostArchiveRecord)
}

input := &s3.PutObjectInput{
Bucket: aws.String(c.RedditPostArchiveBucket),
Bucket: aws.String(c.redditPostArchiveBucket),
Key: aws.String(record.Key),
Body: bytes.NewReader(buf),
}
_, err = c.S3Service.PutObject(input)
_, err = c.s3Service.PutObject(input)
return err
}

Expand All @@ -62,11 +62,11 @@ func (c *Connection) ListRedditPostArchiveRecord(input RedditPostArchiveListInpu
)

listInput := &s3.ListObjectsV2Input{
Bucket: aws.String(c.RedditPostArchiveBucket),
Bucket: aws.String(c.redditPostArchiveBucket),
Prefix: aws.String(startAfterPrefix),
}

objectList, err := c.S3Service.ListObjectsV2(listInput)
objectList, err := c.s3Service.ListObjectsV2(listInput)
if err != nil {
return keys, err
}
Expand All @@ -81,11 +81,11 @@ func (c *Connection) ListRedditPostArchiveRecord(input RedditPostArchiveListInpu
func (c *Connection) GetRedditPostArchiveRecord(input RedditPostArchiveQueryInput) (record RedditPostArchiveRecord, err error) {

getObjectInput := &s3.GetObjectInput{
Bucket: aws.String(c.RedditPostArchiveBucket),
Bucket: aws.String(c.redditPostArchiveBucket),
Key: aws.String(input.Key),
}

object, err := c.S3Service.GetObject(getObjectInput)
object, err := c.s3Service.GetObject(getObjectInput)
if err != nil {
return record, err
}
Expand Down Expand Up @@ -122,10 +122,10 @@ func (c *Connection) PutEtlResultsRecord(record EtlResultsRecord) (err error) {

input := &dynamodb.PutItemInput{
Item: av,
TableName: aws.String(c.EtlResultsTable),
TableName: aws.String(c.etlResultsTable),
}

_, err = c.Service.PutItem(input)
_, err = c.service.PutItem(input)

return err
}
Expand All @@ -139,10 +139,10 @@ func (c *Connection) GetEtlResultsRecord(input EtlResultsQueryInput) (record []E
},
},
KeyConditionExpression: aws.String("id = :v1"),
TableName: aws.String(c.EtlResultsTable),
TableName: aws.String(c.etlResultsTable),
}

result, err := c.Service.Query(qInput)
result, err := c.service.Query(qInput)

if err != nil {
return record, err
Expand Down Expand Up @@ -179,10 +179,10 @@ func (c *Connection) GetLatestEtlResultsRecord(input EtlResultsQueryInput) (reco
KeyConditionExpression: aws.String("id = :v1"),
ScanIndexForward: aws.Bool(false),
Limit: aws.Int64(1),
TableName: aws.String(c.EtlResultsTable),
TableName: aws.String(c.etlResultsTable),
}

result, err = c.Service.Query(qInput)
result, err = c.service.Query(qInput)
if err != nil {
return record, err
}
Expand Down
21 changes: 7 additions & 14 deletions internal/database/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,17 @@ import (
)

type Connection struct {
// Session is the shared aws session
Session *session.Session
// session is the shared aws session
session *session.Session

// Service is the shared dynamo db connection
Service *dynamodb.DynamoDB

// S3Service is the shared S3 connection
S3Service *s3.S3

EtlResultsTable string
RedditPostArchiveBucket string
ApiKeyTable string
service *dynamodb.DynamoDB

// YahooTrendingTable is deprecated
YahooTrendingTable string
// s3Service is the shared S3 connection
s3Service *s3.S3

// UserTable is deprecated
UserTable string
etlResultsTable string
redditPostArchiveBucket string
}

type EtlResultsRecord struct {
Expand Down
9 changes: 9 additions & 0 deletions sql/bootstrap.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Create the main datbase
CREATE DATABASE IF NOT EXISTS kettle;
USE kettle;



-- Create insert query

-- Create update symbols query
13 changes: 13 additions & 0 deletions sql/create_counts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Create count table
CREATE TABLE IF NOT EXISTS Counts (
Id varchar(25),
CountDate datetime,
Ticker varchar(10),
PostScore int,
CommentScore int,
TotalScore float,
PostMentions int,
CommentMentions int,
PRIMARY KEY(Id)
);

9 changes: 9 additions & 0 deletions sql/create_symbols.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Create ticker symbol table
CREATE TABLE IF NOT EXISTS Symbols (
Ticker varchar(10),
Exchange varchar(255),
FullName varchar(255),
ETF boolean,
PRIMARY KEY(Ticker)
);

0 comments on commit 6152cf7

Please sign in to comment.