0.4.0b2 database fix (and dotenv loading)
This commit is contained in:
parent
5b98a2e98a
commit
9919e74836
7 changed files with 49 additions and 22 deletions
20
package-lock.json
generated
20
package-lock.json
generated
|
|
@ -1,23 +1,24 @@
|
|||
{
|
||||
"name": "sknsybot",
|
||||
"version": "0.4.0",
|
||||
"version": "0.4.0.b2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "sknsybot",
|
||||
"version": "0.4.0",
|
||||
"version": "0.4.0.b2",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"chalk": "^5.4.1",
|
||||
"discord.js": "^14.14.1",
|
||||
"dotenv": "^16.4.7",
|
||||
"dotenv": "^17.3.1",
|
||||
"drizzle-orm": "^0.45.1",
|
||||
"node-cron": "^3.0.3",
|
||||
"pg": "^8.18.0",
|
||||
"wikijs": "^6.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chalk": "^0.4.31",
|
||||
"@types/node": "^22.10.7",
|
||||
"@types/node-cron": "^3.0.11",
|
||||
"@types/pg": "^8.16.0",
|
||||
|
|
@ -1144,6 +1145,13 @@
|
|||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/chalk": {
|
||||
"version": "0.4.31",
|
||||
"resolved": "https://registry.npmjs.org/@types/chalk/-/chalk-0.4.31.tgz",
|
||||
"integrity": "sha512-nF0fisEPYMIyfrFgabFimsz9Lnuu9MwkNrrlATm2E4E46afKDyeelT+8bXfw1VSc7sLBxMxRgT7PxTC2JcqN4Q==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "22.10.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.7.tgz",
|
||||
|
|
@ -1333,9 +1341,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.4.7",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz",
|
||||
"integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==",
|
||||
"version": "17.3.1",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.3.1.tgz",
|
||||
"integrity": "sha512-IO8C/dzEb6O3F9/twg6ZLXz164a2fhTnEWb95H23Dm4OuN+92NmEAlTrupP9VW6Jm3sO26tQlqyvyi4CsnY9GA==",
|
||||
"license": "BSD-2-Clause",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "sknsybot",
|
||||
"version": "0.4.0.b1",
|
||||
"version": "0.4.0.b2",
|
||||
"private": true,
|
||||
"description": "",
|
||||
"license": "Apache-2.0",
|
||||
|
|
@ -14,13 +14,14 @@
|
|||
"dependencies": {
|
||||
"chalk": "^5.4.1",
|
||||
"discord.js": "^14.14.1",
|
||||
"dotenv": "^16.4.7",
|
||||
"dotenv": "^17.3.1",
|
||||
"drizzle-orm": "^0.45.1",
|
||||
"node-cron": "^3.0.3",
|
||||
"pg": "^8.18.0",
|
||||
"wikijs": "^6.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chalk": "^0.4.31",
|
||||
"@types/node": "^22.10.7",
|
||||
"@types/node-cron": "^3.0.11",
|
||||
"@types/pg": "^8.16.0",
|
||||
|
|
|
|||
|
|
@ -3,13 +3,28 @@ import { drizzle } from "drizzle-orm/node-postgres";
|
|||
import * as schema from "./schema";
|
||||
import { Pool } from "pg";
|
||||
|
||||
function urlToObj(url: string) {
|
||||
if (!url) throw new Error('DATABASE_URL is not set');
|
||||
|
||||
const { username, password, hostname, port, pathname } = URL.parse(url);
|
||||
|
||||
return {
|
||||
user: username,
|
||||
password,
|
||||
host: hostname,
|
||||
port: +(port || 5432),
|
||||
database: pathname.split('/')[1]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const client = new Pool({
|
||||
connectionString: process.env.DATABASE_URL!
|
||||
...urlToObj(process.env.DATABASE_URL!)
|
||||
});
|
||||
|
||||
export const db = drizzle({
|
||||
client,
|
||||
casing: 'snake_case',
|
||||
// casing: 'snake_case', [DOES NOT WORK ON DRIZZLEKIT]
|
||||
schema
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
|
||||
import { config as configDotenv } from 'dotenv';
|
||||
import { configDotenv } from 'dotenv';
|
||||
import process from 'node:process';
|
||||
|
||||
export default function init (){
|
||||
configDotenv();
|
||||
|
|
|
|||
18
src/main.ts
18
src/main.ts
|
|
@ -1,17 +1,19 @@
|
|||
|
||||
import init from "./initConfig";
|
||||
import { configDotenv } from "dotenv";
|
||||
|
||||
init();
|
||||
configDotenv(); // apparently init does not get executed
|
||||
|
||||
const client = (await import("./bot")).default;
|
||||
|
||||
import client from "./bot";
|
||||
|
||||
// query TEST
|
||||
import { db } from "./db/database";
|
||||
import { count } from "drizzle-orm";
|
||||
import { users } from "./db/schema";
|
||||
import chalk from "chalk";
|
||||
(async function () {
|
||||
const uCount = await db.select({ count: count() }).from(users);
|
||||
// async imports because yes
|
||||
const { db } = await import("./db/database");
|
||||
const { count } = await import("drizzle-orm");
|
||||
const { users } = await import("./db/schema");
|
||||
const chalk = (await import("chalk")).default;
|
||||
const uCount = (await db.select({ count: count() }).from(users))[0].count;
|
||||
console.log(`Watching over ${chalk.bold(uCount)} users`);
|
||||
})().then(() => { });
|
||||
// END query TEST
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@ function strToObjArr(s: string | object[]): object[] {
|
|||
|
||||
export type SectionObject = {title: string, content: string};
|
||||
|
||||
type WithPageId = {pageId: any};
|
||||
|
||||
export class MediaWikiClient {
|
||||
apiUrl: string
|
||||
siteName: string | null
|
||||
|
|
@ -29,7 +27,7 @@ export class MediaWikiClient {
|
|||
const wikiClient = wiki({
|
||||
apiUrl: this.apiUrl,
|
||||
origin: null
|
||||
});
|
||||
}) as any;
|
||||
const page = await wikiClient.page(title);
|
||||
const pageId = page.raw.pageid;
|
||||
const pageUrl = page.url();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2017",
|
||||
"module": "preserve",
|
||||
"rootDir": "src/",
|
||||
"outDir": "build/",
|
||||
"esModuleInterop": true,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue