Caspian Nightworth
Caspian Nightworth
Explore posts from servers
DTDrizzle Team
Created by Caspian Nightworth on 6/11/2024 in #help
Convert PostgreSQL to Drizzle ORM
I have the following SQL that I am trying to convert to Drizzle ORM for my NextJS project.
SELECT
ffxiv_blue_mage_tracker_spells.id,
ffxiv_blue_mage_tracker_spells.name,
ffxiv_blue_mage_tracker_spells.description,
ffxiv_blue_mage_tracker_spells.tooltip,
ffxiv_blue_mage_tracker_spells.patch,
ffxiv_blue_mage_tracker_spells.icon,
ffxiv_blue_mage_tracker_spells.type,
ffxiv_blue_mage_tracker_spells.aspect,
(
SELECT
STRING_AGG(source_text, ', ')
FROM
ffxiv_blue_mage_tracker_sources AS src
WHERE
src.spell_id = ffxiv_blue_mage_tracker_spells.id
) AS where_to_aquire
FROM
ffxiv_blue_mage_tracker_spells
INNER JOIN (
SELECT
spell_id,
-- Remove grouping by source_text
STRING_AGG(source_text, ', ') AS source_text
FROM
ffxiv_blue_mage_tracker_sources
GROUP BY
spell_id
) AS ffxiv_blue_mage_tracker_sources ON ffxiv_blue_mage_tracker_spells.id = ffxiv_blue_mage_tracker_sources.spell_id
ORDER BY
ffxiv_blue_mage_tracker_spells.id ASC
SELECT
ffxiv_blue_mage_tracker_spells.id,
ffxiv_blue_mage_tracker_spells.name,
ffxiv_blue_mage_tracker_spells.description,
ffxiv_blue_mage_tracker_spells.tooltip,
ffxiv_blue_mage_tracker_spells.patch,
ffxiv_blue_mage_tracker_spells.icon,
ffxiv_blue_mage_tracker_spells.type,
ffxiv_blue_mage_tracker_spells.aspect,
(
SELECT
STRING_AGG(source_text, ', ')
FROM
ffxiv_blue_mage_tracker_sources AS src
WHERE
src.spell_id = ffxiv_blue_mage_tracker_spells.id
) AS where_to_aquire
FROM
ffxiv_blue_mage_tracker_spells
INNER JOIN (
SELECT
spell_id,
-- Remove grouping by source_text
STRING_AGG(source_text, ', ') AS source_text
FROM
ffxiv_blue_mage_tracker_sources
GROUP BY
spell_id
) AS ffxiv_blue_mage_tracker_sources ON ffxiv_blue_mage_tracker_spells.id = ffxiv_blue_mage_tracker_sources.spell_id
ORDER BY
ffxiv_blue_mage_tracker_spells.id ASC
So far what I have is the following and I'm not entirely sure that what I have so far is even correct:
const spellList = await db
.select({
spellId: spells.id,
name: spells.name,
description: spells.description,
tooltip: spells.tooltip,
patch: spells.patch,
icon: spells.icon,
type: spells.type,
aspect: spells.aspect,
whereToAquire: sql<string>`select string_agg(${sources.sourceText}, ', ') from ${sources} as src where src.spell_id = ${spells.id}`,
})
.from(spells)
.innerJoin(sources, eq(spells.id, sources.spellId))
.orderBy(asc(spells.id));
const spellList = await db
.select({
spellId: spells.id,
name: spells.name,
description: spells.description,
tooltip: spells.tooltip,
patch: spells.patch,
icon: spells.icon,
type: spells.type,
aspect: spells.aspect,
whereToAquire: sql<string>`select string_agg(${sources.sourceText}, ', ') from ${sources} as src where src.spell_id = ${spells.id}`,
})
.from(spells)
.innerJoin(sources, eq(spells.id, sources.spellId))
.orderBy(asc(spells.id));
I am stuck on how to handle the INNER JOIN in my original SQL
4 replies
TTCTheo's Typesafe Cult
Created by Caspian Nightworth on 6/10/2024 in #questions
Routing Assistance
No description
32 replies
DTDrizzle Team
Created by Caspian Nightworth on 6/10/2024 in #help
conflicting peer dependency when installing drizzle-orm
I am trying to install drizzle orm in a fresh install of Nextjs and have the following error presented
❯ npm i drizzle-orm
npm error code ERESOLVE
npm error ERESOLVE could not resolve
npm error
npm error While resolving: ffxiv-blue-mage-tracker@0.1.0
npm error Found: react@18.3.1
npm error node_modules/react
npm error peer react@"^18.2.0" from next@14.2.3
npm error node_modules/next
npm error next@"14.2.3" from the root project
npm error peer react@"^18.3.1" from react-dom@18.3.1
npm error node_modules/react-dom
npm error peer react-dom@"^18.2.0" from next@14.2.3
npm error node_modules/next
npm error next@"14.2.3" from the root project
npm error react-dom@"^18" from the root project
npm error 2 more (styled-jsx, the root project)
npm error
npm error Could not resolve dependency:
npm error drizzle-orm@"*" from the root project
npm error
npm error Conflicting peer dependency: react@18.2.0
npm error node_modules/react
npm error peer react@"18.2.0" from react-native@0.74.2
npm error node_modules/react-native
npm error peer react-native@">0.73.0" from @op-engineering/op-sqlite@6.0.4
npm error node_modules/@op-engineering/op-sqlite
npm error peerOptional @op-engineering/op-sqlite@">=2" from drizzle-orm@0.31.2
npm error node_modules/drizzle-orm
npm error drizzle-orm@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
❯ npm i drizzle-orm
npm error code ERESOLVE
npm error ERESOLVE could not resolve
npm error
npm error While resolving: ffxiv-blue-mage-tracker@0.1.0
npm error Found: react@18.3.1
npm error node_modules/react
npm error peer react@"^18.2.0" from next@14.2.3
npm error node_modules/next
npm error next@"14.2.3" from the root project
npm error peer react@"^18.3.1" from react-dom@18.3.1
npm error node_modules/react-dom
npm error peer react-dom@"^18.2.0" from next@14.2.3
npm error node_modules/next
npm error next@"14.2.3" from the root project
npm error react-dom@"^18" from the root project
npm error 2 more (styled-jsx, the root project)
npm error
npm error Could not resolve dependency:
npm error drizzle-orm@"*" from the root project
npm error
npm error Conflicting peer dependency: react@18.2.0
npm error node_modules/react
npm error peer react@"18.2.0" from react-native@0.74.2
npm error node_modules/react-native
npm error peer react-native@">0.73.0" from @op-engineering/op-sqlite@6.0.4
npm error node_modules/@op-engineering/op-sqlite
npm error peerOptional @op-engineering/op-sqlite@">=2" from drizzle-orm@0.31.2
npm error node_modules/drizzle-orm
npm error drizzle-orm@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
4 replies
TTCTheo's Typesafe Cult
Created by Caspian Nightworth on 6/9/2024 in #questions
unsafe assignment of an `any` value
No description
10 replies
TTCTheo's Typesafe Cult
Created by Caspian Nightworth on 6/1/2024 in #questions
From 0 to Production - The Modern React Tutorial (RSCs, Next.js, Shadui, Drizzle, TS and more) Issue
I am following along with the From 0 to Production - The Modern React Tutorial (RSCs, Next.js, Shadui, Drizzle, TS and more) and when I deploy to Vercel, it returns with a 404 error, yet my local displays the basic page. This is early in the video - 12:38. I am not quite sure where the disconnect is.
3 replies
SIASapphire - Imagine a framework
Created by Caspian Nightworth on 11/26/2023 in #sapphire-support
Paginination limitation when not using select menus
I have the following error being presented to me
(node:1484241) [PAGINATED_MESSAGE_EXCEEDED_MAXIMUM_AMOUNT_OF_PAGES] PaginatedMessageExceededMessagePageAmount: Maximum amount of pages exceeded for PaginatedMessage. Please check your instance of PaginatedMessage and ensure that you do not exceed 25 pages total. If you do need more than 25 pages you can extend the class and overwrite the actions in the constructor.
and this is my current code giving the error:
import { PaginatedMessage } from '@sapphire/discord.js-utilities';
import { EmbedBuilder } from 'discord.js';

export function movieResponseRebuilder(movieResponse: object) {
console.log('movie Response: ', JSON.stringify(movieResponse));

const display = new PaginatedMessage({
template: new EmbedBuilder().setColor('#8E44AD')
});

movieResponse.forEach((movie) => {
display.addPageEmbed((embed) => {
embed //
.addFields({
name: 'Test Name',
value: 'Test value'
});
return embed;
});
console.log('looped movie data', JSON.stringify(movie));
});

return display;
}
import { PaginatedMessage } from '@sapphire/discord.js-utilities';
import { EmbedBuilder } from 'discord.js';

export function movieResponseRebuilder(movieResponse: object) {
console.log('movie Response: ', JSON.stringify(movieResponse));

const display = new PaginatedMessage({
template: new EmbedBuilder().setColor('#8E44AD')
});

movieResponse.forEach((movie) => {
display.addPageEmbed((embed) => {
embed //
.addFields({
name: 'Test Name',
value: 'Test value'
});
return embed;
});
console.log('looped movie data', JSON.stringify(movie));
});

return display;
}
movieResponse is an array of objects that can exceed 25 objects. how do I get around this error as you can see, I don't have any menus in place in my embed code.
22 replies
SIASapphire - Imagine a framework
Created by Caspian Nightworth on 11/10/2023 in #sapphire-support
ReferenceError: exports is not defined in ES module scope
I am trying to run my bot and am presented with the following error
Successfully compiled: 13 files with swc (25.27ms)
Debugger listening on ws://0.0.0.0:9229/db93ad55-46aa-4ed1-be89-f2b2b5cded3b
For help, see: https://nodejs.org/en/docs/inspector
file:///home/demonicpagan/development/nodejs/discordBots/discord-trakt/dist/bot.js:2
Object.defineProperty(exports, "__esModule", {
^

ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/home/demonicpagan/development/nodejs/discordBots/discord-trakt/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///home/demonicpagan/development/nodejs/discordBots/discord-trakt/dist/bot.js:2:23
at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async loadESM (node:internal/process/esm_loader:34:7)
at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.9.0
 ELIFECYCLE  Command failed with exit code 1.
Successfully compiled: 13 files with swc (25.27ms)
Debugger listening on ws://0.0.0.0:9229/db93ad55-46aa-4ed1-be89-f2b2b5cded3b
For help, see: https://nodejs.org/en/docs/inspector
file:///home/demonicpagan/development/nodejs/discordBots/discord-trakt/dist/bot.js:2
Object.defineProperty(exports, "__esModule", {
^

ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/home/demonicpagan/development/nodejs/discordBots/discord-trakt/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///home/demonicpagan/development/nodejs/discordBots/discord-trakt/dist/bot.js:2:23
at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async loadESM (node:internal/process/esm_loader:34:7)
at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.9.0
 ELIFECYCLE  Command failed with exit code 1.
What do I need to do to resolve this? Since there are so many files involved and the length would exceed the Discord limitations, I created a gist with everything I think is needed. https://gist.github.com/dustin-lennon/30bee1b477e4de8dae3459f4fa4c6b96
14 replies
SIASapphire - Imagine a framework
Created by Caspian Nightworth on 10/28/2023 in #sapphire-support
Compiling with SWC
I've been trying to compile my code with SWC and it is finding errors in a couple of my files that were created using the CLI. Those files are src/commands/General/Ping.ts and src/listeners/ready.ts These are the errors that are presented:
> rimraf dist && swc ./src -d dist


× Expression expected
╭─[src/listeners/ready.ts:4:1]
4 │
5 │ const dev = process.env.NODE_ENV !== 'production';
6 │
7 │ @ApplyOptions<Listener.Options>({ once: true })
· ─
8 │ export class UserEvent extends Listener {
9 │ private readonly style = dev ? yellow : blue;
╰────


Caused by:
Syntax Error

× Expression expected
╭─[src/commands/General/Ping.ts:2:1]
2 │ import { isMessageInstance } from '@sapphire/discord.js-utilities';
3 │ import { Command } from '@sapphire/framework';
4 │
5 │ @ApplyOptions<Command.Options>({
· ─
6 │ description: 'Returns the round trip and heartbeat'
7 │ })
8 │ export class UserCommand extends Command {
╰────


Caused by:
Syntax Error
Successfully compiled: 11 files with swc (23.51ms)
Failed to compile 2 files with swc.
Error: Failed to compile:
src/listeners/ready.ts
src/commands/General/Ping.ts
at initialCompilation (/home/demonicpagan/development/nodejs/discordBots/discord-trakt/node_modules/.pnpm/@swc+cli@0.1.62_@swc+core@1.3.95/node_modules/@swc/cli/lib/swc/dir.js:163:19)
at async dir (/home/demonicpagan/development/nodejs/discordBots/discord-trakt/node_modules/.pnpm/@swc+cli@0.1.62_@swc+core@1.3.95/node_modules/@swc/cli/lib/swc/dir.js:228:5)
 ELIFECYCLE  Command failed with exit code 1.
> rimraf dist && swc ./src -d dist


× Expression expected
╭─[src/listeners/ready.ts:4:1]
4 │
5 │ const dev = process.env.NODE_ENV !== 'production';
6 │
7 │ @ApplyOptions<Listener.Options>({ once: true })
· ─
8 │ export class UserEvent extends Listener {
9 │ private readonly style = dev ? yellow : blue;
╰────


Caused by:
Syntax Error

× Expression expected
╭─[src/commands/General/Ping.ts:2:1]
2 │ import { isMessageInstance } from '@sapphire/discord.js-utilities';
3 │ import { Command } from '@sapphire/framework';
4 │
5 │ @ApplyOptions<Command.Options>({
· ─
6 │ description: 'Returns the round trip and heartbeat'
7 │ })
8 │ export class UserCommand extends Command {
╰────


Caused by:
Syntax Error
Successfully compiled: 11 files with swc (23.51ms)
Failed to compile 2 files with swc.
Error: Failed to compile:
src/listeners/ready.ts
src/commands/General/Ping.ts
at initialCompilation (/home/demonicpagan/development/nodejs/discordBots/discord-trakt/node_modules/.pnpm/@swc+cli@0.1.62_@swc+core@1.3.95/node_modules/@swc/cli/lib/swc/dir.js:163:19)
at async dir (/home/demonicpagan/development/nodejs/discordBots/discord-trakt/node_modules/.pnpm/@swc+cli@0.1.62_@swc+core@1.3.95/node_modules/@swc/cli/lib/swc/dir.js:228:5)
 ELIFECYCLE  Command failed with exit code 1.
This is my config for SWC, .swcrc
{
"env": {
"target": {
"node": 20
}
},
"jsc": {
"parser": {
"syntax": "typescript"
}
},
"module": {
"type": "commonjs"
},
"sourceMaps": "inline"
}
{
"env": {
"target": {
"node": 20
}
},
"jsc": {
"parser": {
"syntax": "typescript"
}
},
"module": {
"type": "commonjs"
},
"sourceMaps": "inline"
}
4 replies
SIASapphire - Imagine a framework
Created by Caspian Nightworth on 3/2/2023 in #sapphire-support
ReferenceError: [ENV] BOT_OWNER_IDS - The key must be an array, but is empty or undefined.
I am using @skyra/env-utilities and when I start up my bot, I get the error reported in the title of this post. I cannot figure out what I am missing. I have a .env.local file in my src directory. It is erroring when it gets to export const OWNERS = envParseArray('BOT_OWNER_IDS'); in my src/lib/constants.ts file. This is the contents of my src/lib/setup.ts file:
// Unless explicitly defined, set NODE_ENV as development:
// process.env.NODE_ENV ??= 'development';

import '@sapphire/plugin-api/register';
import '@sapphire/plugin-editable-commands/register';
import '@sapphire/plugin-logger/register';
import * as colorette from 'colorette';
import { type NumberString, setup, type ArrayString } from '@skyra/env-utilities';
import { join } from 'node:path';
import { inspect } from 'util';
import { rootFolder } from './constants';

// Read env var
setup(join(rootFolder, 'src', '.env'));

// Set default inspection depth
inspect.defaultOptions.depth = 1;

// Enable colorette
colorette.createColors({ useColor: true });

declare module '@skyra/env-utilities' {
interface Env {
BOT_OWNER_IDS: ArrayString;
BOT_REPORT_CHANNEL_ID: string;
MONGO_HOST: string;
MONGO_USERNAME: string;
MONGO_PASSWORD: string;
MONGO_DB: string;
MONGO_API_KEY: string;
MONGO_DB_MAX_SIZE: NumberString;
AWS_S3_BUCKET: string;
AWS_REGION: string;
}
}
// Unless explicitly defined, set NODE_ENV as development:
// process.env.NODE_ENV ??= 'development';

import '@sapphire/plugin-api/register';
import '@sapphire/plugin-editable-commands/register';
import '@sapphire/plugin-logger/register';
import * as colorette from 'colorette';
import { type NumberString, setup, type ArrayString } from '@skyra/env-utilities';
import { join } from 'node:path';
import { inspect } from 'util';
import { rootFolder } from './constants';

// Read env var
setup(join(rootFolder, 'src', '.env'));

// Set default inspection depth
inspect.defaultOptions.depth = 1;

// Enable colorette
colorette.createColors({ useColor: true });

declare module '@skyra/env-utilities' {
interface Env {
BOT_OWNER_IDS: ArrayString;
BOT_REPORT_CHANNEL_ID: string;
MONGO_HOST: string;
MONGO_USERNAME: string;
MONGO_PASSWORD: string;
MONGO_DB: string;
MONGO_API_KEY: string;
MONGO_DB_MAX_SIZE: NumberString;
AWS_S3_BUCKET: string;
AWS_REGION: string;
}
}
contents of my .env.local:
NODE_ENV=development

# Tokens
DISCORD_TOKEN=discordToken
DISCORD_CLIENT_ID=11111111
DISCORD_CLIENT_SECRET=discordSecret
DISCORD_PUBLIC_KEY=discordPubKey

# Configuration
DEFAULT_PREFIX=dmb
BOT_OWNER_IDS='49242868987990016 253018958536376321'
BOT_REPORT_CHANNEL_ID=470100327840874496

# Mongo DB Data
MONGO_HOST=some.address.mongodb.net
MONGO_USERNAME=username
MONGO_PASSWORD=password
MONGO_DB=db
MONGO_API_KEY=apiKey
MONGO_DB_MAX_SIZE=496

# AWS S3 Data
AWS_REGION=us-east-2
AWS_ACCESS_KEY_ID=awsAccessKey
AWS_SECRET_ACCESS_KEY=awsSecret
AWS_S3_BUCKET=awsBucket
NODE_ENV=development

# Tokens
DISCORD_TOKEN=discordToken
DISCORD_CLIENT_ID=11111111
DISCORD_CLIENT_SECRET=discordSecret
DISCORD_PUBLIC_KEY=discordPubKey

# Configuration
DEFAULT_PREFIX=dmb
BOT_OWNER_IDS='49242868987990016 253018958536376321'
BOT_REPORT_CHANNEL_ID=470100327840874496

# Mongo DB Data
MONGO_HOST=some.address.mongodb.net
MONGO_USERNAME=username
MONGO_PASSWORD=password
MONGO_DB=db
MONGO_API_KEY=apiKey
MONGO_DB_MAX_SIZE=496

# AWS S3 Data
AWS_REGION=us-east-2
AWS_ACCESS_KEY_ID=awsAccessKey
AWS_SECRET_ACCESS_KEY=awsSecret
AWS_S3_BUCKET=awsBucket
I am not sure what I am missing or how to resolve
13 replies
SIASapphire - Imagine a framework
Created by Caspian Nightworth on 3/1/2023 in #sapphire-support
How to use `@sapphire/shapeshift ` dateValid & stringRegex
I have a slash command that needs to take in a date input in the format of YYYY-MM-DD. I want to perform validation on this and throw an error if it is not in this format or not a valid date. I was looking at the documenation, but I was hoping to see a code example to help explain the usage. I appreciate the explanation and help.
4 replies
SIASapphire - Imagine a framework
Created by Caspian Nightworth on 2/25/2023 in #sapphire-support
How to get the current channel a slash command was used in
I took a look at the following post https://discord.com/channels/737141877803057244/1061609301556346921 and
const target= await interaction.guild?.channels.cache.get('id');
const target= await interaction.guild?.channels.cache.get('id');
comes up as undefined. I am needing to get returned as if I were running client.channels.fetch(process.env.BOT_REPORT_CHANNEL_ID)
4 replies