forked from elliotBraem/efizzybot
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34d2e05
commit 4788b26
Showing
11 changed files
with
221 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { eq } from "drizzle-orm"; | ||
import { twitterCache, twitterCookies } from "./schema"; | ||
import { BunSQLiteDatabase } from "drizzle-orm/bun-sqlite"; | ||
|
||
// Twitter Cookie Management | ||
export function getTwitterCookies(db: BunSQLiteDatabase, username: string) { | ||
return db | ||
.select() | ||
.from(twitterCookies) | ||
.where(eq(twitterCookies.username, username)) | ||
.get(); | ||
} | ||
|
||
export function setTwitterCookies( | ||
db: BunSQLiteDatabase, | ||
username: string, | ||
cookiesJson: string, | ||
) { | ||
return db | ||
.insert(twitterCookies) | ||
.values({ | ||
username, | ||
cookies: cookiesJson, | ||
}) | ||
.onConflictDoUpdate({ | ||
target: twitterCookies.username, | ||
set: { | ||
cookies: cookiesJson, | ||
updatedAt: new Date().toISOString(), | ||
}, | ||
}); | ||
} | ||
|
||
export function deleteTwitterCookies(db: BunSQLiteDatabase, username: string) { | ||
return db.delete(twitterCookies).where(eq(twitterCookies.username, username)); | ||
} | ||
|
||
// Twitter Cache Management | ||
export function getTwitterCacheValue(db: BunSQLiteDatabase, key: string) { | ||
return db | ||
.select() | ||
.from(twitterCache) | ||
.where(eq(twitterCache.key, key)) | ||
.get(); | ||
} | ||
|
||
export function setTwitterCacheValue( | ||
db: BunSQLiteDatabase, | ||
key: string, | ||
value: string, | ||
) { | ||
return db | ||
.insert(twitterCache) | ||
.values({ | ||
key, | ||
value, | ||
}) | ||
.onConflictDoUpdate({ | ||
target: twitterCache.key, | ||
set: { | ||
value, | ||
updatedAt: new Date().toISOString(), | ||
}, | ||
}); | ||
} | ||
|
||
export function deleteTwitterCacheValue(db: BunSQLiteDatabase, key: string) { | ||
return db.delete(twitterCache).where(eq(twitterCache.key, key)); | ||
} | ||
|
||
export function clearTwitterCache(db: BunSQLiteDatabase) { | ||
return db.delete(twitterCache); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { sqliteTable as table, text } from "drizzle-orm/sqlite-core"; | ||
|
||
// Reusable timestamp columns | ||
const timestamps = { | ||
createdAt: text("created_at") | ||
.notNull() | ||
.$defaultFn(() => new Date().toISOString()), | ||
updatedAt: text("updated_at").$defaultFn(() => new Date().toISOString()), | ||
}; | ||
|
||
export const twitterCookies = table( | ||
"twitter_cookies", | ||
{ | ||
username: text("username").primaryKey(), | ||
cookies: text("cookies").notNull(), // JSON string of TwitterCookie[] | ||
...timestamps, | ||
} | ||
); | ||
|
||
export const twitterCache = table( | ||
"twitter_cache", | ||
{ | ||
key: text("key").primaryKey(), // e.g., "last_tweet_id" | ||
value: text("value").notNull(), | ||
...timestamps, | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.