mirror of
https://github.com/rybbit-io/rybbit.git
synced 2025-05-12 12:55:36 +02:00
import session logic
This commit is contained in:
parent
6f46abd12f
commit
0d798d6556
12 changed files with 186 additions and 180 deletions
37
server/src/db/postgres/postgres.ts
Normal file
37
server/src/db/postgres/postgres.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import postgres from "postgres";
|
||||
import { Session } from "./types";
|
||||
|
||||
export const sql = postgres({
|
||||
host: process.env.POSTGRES_HOST || "postgres",
|
||||
port: parseInt(process.env.POSTGRES_PORT || "5432", 10),
|
||||
database: process.env.POSTGRES_DB,
|
||||
username: process.env.POSTGRES_USER,
|
||||
password: process.env.POSTGRES_PASSWORD,
|
||||
});
|
||||
|
||||
export async function initializePostgres() {
|
||||
try {
|
||||
await sql<Session[]>`
|
||||
CREATE TABLE IF NOT EXISTS active_sessions (
|
||||
session_id TEXT PRIMARY KEY,
|
||||
user_id TEXT,
|
||||
hostname TEXT,
|
||||
start_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
last_activity TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
pageviews INT DEFAULT 0,
|
||||
entry_page TEXT,
|
||||
exit_page TEXT,
|
||||
device_type TEXT,
|
||||
screen_width INT,
|
||||
screen_height INT,
|
||||
browser TEXT,
|
||||
operating_system TEXT,
|
||||
language TEXT,
|
||||
referrer TEXT
|
||||
);
|
||||
`;
|
||||
console.log("Tables created successfully.");
|
||||
} catch (err) {
|
||||
console.error("Error creating tables:", err);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue