35 lines
975 B
Plaintext
35 lines
975 B
Plaintext
|
st = conn.createStatement()
|
||
|
st.executeUpdate(
|
||
|
"CREATE TABLE IF NOT EXISTS posts (
|
||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||
|
post_id STRING NOT NULL,
|
||
|
subreddit STRING NOT NULL,
|
||
|
url STRING NOT NULL,
|
||
|
created_at INTEGER NOT NULL,
|
||
|
sent_at INTEGER NOT NULL
|
||
|
)")
|
||
|
st.executeUpdate(
|
||
|
"CREATE UNIQUE INDEX IF NOT EXISTS url_idx ON posts (url)")
|
||
|
st.close()
|
||
|
|
||
|
stIsPostExists = conn.prepareStatement(
|
||
|
"SELECT COUNT(*) FROM posts
|
||
|
WHERE url = ?")
|
||
|
stAddPost = conn.prepareStatement(
|
||
|
"INSERT INTO posts(post_id, subreddit, url, created_at, sent_at)
|
||
|
VALUES(?, ?, ?, ?, ?)")
|
||
|
|
||
|
def isPostUnique(post) {
|
||
|
stIsPostExists.setString(1, post.url)
|
||
|
rs = stIsPostExists.executeQuery()
|
||
|
return rs.getInt(1) == 0
|
||
|
}
|
||
|
|
||
|
def addPost(post) {
|
||
|
stAddPost.setString(1, post.id)
|
||
|
stAddPost.setString(2, post.sub)
|
||
|
stAddPost.setString(3, post.url)
|
||
|
stAddPost.setLong(4, post.time)
|
||
|
stAddPost.setLong(5, time() / 1000)
|
||
|
stAddPost.executeUpdate()
|
||
|
}
|