sten
sten
Explore posts from servers
DTDrizzle Team
Created by sten on 8/7/2024 in #help
[solved] The server does not support SSL connections
I am running Drizzle with Postgres in a devcontainer using Docker WSL 2. In my db file:
import { drizzle } from 'drizzle-orm/node-postgres';
import pg from 'pg';
import * as schema from './schema.ts';
import 'dotenv/config';

const client = new pg.Client({
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT || '3000'),
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
ssl: { rejectUnauthorized: false }
});

export const connection = await client.connect();

export const db = drizzle(client, { schema });
import { drizzle } from 'drizzle-orm/node-postgres';
import pg from 'pg';
import * as schema from './schema.ts';
import 'dotenv/config';

const client = new pg.Client({
host: process.env.DB_HOST,
port: parseInt(process.env.DB_PORT || '3000'),
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
ssl: { rejectUnauthorized: false }
});

export const connection = await client.connect();

export const db = drizzle(client, { schema });
In my config:
import { defineConfig } from 'drizzle-kit';
import dotenv from 'dotenv';

dotenv.config();

export default defineConfig({
schema: './src/db/schema.ts',
out: './drizzle',
dialect: 'postgresql',
dbCredentials: {
host: process.env.DB_HOST || 'localhost',
user: process.env.DB_USER || 'postgres',
password: process.env.DB_PASS || '',
database: process.env.DB_NAME || 'postgres',
port: parseInt(process.env.DB_PORT || '5432'),
ssl: false
}
});
import { defineConfig } from 'drizzle-kit';
import dotenv from 'dotenv';

dotenv.config();

export default defineConfig({
schema: './src/db/schema.ts',
out: './drizzle',
dialect: 'postgresql',
dbCredentials: {
host: process.env.DB_HOST || 'localhost',
user: process.env.DB_USER || 'postgres',
password: process.env.DB_PASS || '',
database: process.env.DB_NAME || 'postgres',
port: parseInt(process.env.DB_PORT || '5432'),
ssl: false
}
});
Despite this, I keep getting the SSL issue. I am starting my container like this: CMD ["sh", "-c", "npm run generate && npm run migrate && npm run dev"] Where the commands correspond to
"dev": "tsx src/index.ts",
"generate": "drizzle-kit up",
"migrate": "drizzle-kit migrate",
"dev": "tsx src/index.ts",
"generate": "drizzle-kit up",
"migrate": "drizzle-kit migrate",
I am calling generate and migrate to assure that if someone would run this on their system, they've would have the correct tables setup. UPDATE: So I removed ssl: { rejectUnauthorized: false } and it worked, however, upon connecting to the db docker exec -it postgres_db psql -U postgres -d postgres, it reveals that I don't have any relations
postgres=# \dt
Did not find any relations.
postgres=# \dt
Did not find any relations.
UPDATE 2: I noticed that my generate command was wrong
"generate": "drizzle-kit generate"
"generate": "drizzle-kit generate"
I was using drizzle-kit up, must have mixed them up somehow
1 replies
CDCloudflare Developers
Created by sten on 2/5/2024 in #pages-help
How to serve javascript files (as third party lib)
I am currently implementing a widget to be embedded as a third party library on websites. I am developing it with Vanilla Svelte and rollup.js. This is my rollup config.
export default {
input: 'src/embed.ts',
output: [
{
name: 'widget',
format: 'iife',
file: './dist/widget.js',
sourcemap: true
},
{
file: './dist/bundle.min.js',
format: 'iife',
name: 'version',
plugins: [terser()]
}
],
plugins: [
json(),
svelte({ preprocess: sveltePreprocess(), emitCss: false }),
resolve({ browser: true, dedupe: ['svelte'] }),
commonjs(),
typescript({ sourceMap: true, inlineSources: false, exclude: ['main.ts'] })
]
};
export default {
input: 'src/embed.ts',
output: [
{
name: 'widget',
format: 'iife',
file: './dist/widget.js',
sourcemap: true
},
{
file: './dist/bundle.min.js',
format: 'iife',
name: 'version',
plugins: [terser()]
}
],
plugins: [
json(),
svelte({ preprocess: sveltePreprocess(), emitCss: false }),
resolve({ browser: true, dedupe: ['svelte'] }),
commonjs(),
typescript({ sourceMap: true, inlineSources: false, exclude: ['main.ts'] })
]
};
Question: how can I serve the bundle.min.js through Cloudflare as a CDN? I am assuming it should be possible with Pages Direct Upload? Idea is to be able to include the script like this later on:
<script src="CDN.../bundle.min.js" defer></script>
<script src="CDN.../bundle.min.js" defer></script>
Would be awesome if someone could point me in the right direction
3 replies
DTDrizzle Team
Created by sten on 12/30/2023 in #help
Limitation in Drizzle? findMany does not work the same as an innerjoin, is it possible?
So I want to get all posts with supporters with a specific user_id. Q1 gives me that but I'd like to do it with Q2 but Q2 gives me all posts instead of just the ones that the user_id is supporting.
Q1:
const result = await db
.select()
.from(posts)
.innerJoin(supporters, eq(posts.id, supporters.idea_id))
.innerJoin(users, eq(supporters.user_id, users.id))
.where(eq(users.id, user_id))
.all();

Q2:
const result = await db.query.posts.findMany({
with: {
supporters: {
where: (supporters, { eq }) => eq(supporters.user_id, user_id)
}
}
});
Q1:
const result = await db
.select()
.from(posts)
.innerJoin(supporters, eq(posts.id, supporters.idea_id))
.innerJoin(users, eq(supporters.user_id, users.id))
.where(eq(users.id, user_id))
.all();

Q2:
const result = await db.query.posts.findMany({
with: {
supporters: {
where: (supporters, { eq }) => eq(supporters.user_id, user_id)
}
}
});
UPDATE I went this Q3 which works fine.
Q3:
const supporterResult = await db.query.supporters.findMany({
where: (supporters, { eq }) => eq(supporters.user_id, user_id)
});
const ideaIds = supporterResult.map((supporter) => supporter.idea_id);

const result = await db.query.posts.findMany({
with: {
supporters: true
},
where: (posts) => inArray(posts.id, ideaIds)
});
Q3:
const supporterResult = await db.query.supporters.findMany({
where: (supporters, { eq }) => eq(supporters.user_id, user_id)
});
const ideaIds = supporterResult.map((supporter) => supporter.idea_id);

const result = await db.query.posts.findMany({
with: {
supporters: true
},
where: (posts) => inArray(posts.id, ideaIds)
});
6 replies
CDCloudflare Developers
Created by sten on 12/23/2023 in #pages-help
Deploying with cloudflare/pages-action but cannot locate sveltekit build directory
I am currently setting up a build script with https://github.com/cloudflare/pages-action I am using @sveltejs/adapter-cloudflare as my adapter as well which says the build directory is .sveltekit/cloudflare. However, github actions cannot find that directory. Docs here says: https://developers.cloudflare.com/pages/framework-guides/deploy-a-svelte-site/
@sveltejs/adapter-static Only produces client-side static assets (no server-side rendering) and is compatible with Cloudflare Pages. Review the official SvelteKit documentation for instructions on how to set up the adapter. Keep in mind that if you decide to use this adapter, the build directory, instead of .svelte-kit/cloudflare, becomes build. You must also configure your Cloudflare Pages application’s build directory accordingly.
Which means .sveltekit/cloudflare should be correct.
6 replies
CDCloudflare Developers
Created by sten on 11/30/2023 in #pages-help
Build error when using adapter-cloudflare-workers
I am currently trying to deploy a sveltekit website with Cloudflare workers using Cloudflare KV. I've followed this guide https://kit.svelte.dev/docs/adapter-cloudflare-workers I tried building with @sveltejs/adapter-cloudflare:2.3.3 and that works fine, however event.platform.env does not contain Cloudflare KV, even though the .toml file is specified along with the app.d.ts
npmPackages:
@sveltejs/adapter-auto: ^2.0.0 => 2.1.1
@sveltejs/adapter-cloudflare: ^2.3.3 => 2.3.3
@sveltejs/adapter-cloudflare-workers: ^1.2.1 => 1.2.1
@sveltejs/kit: ^1.27.6 => 1.27.6
svelte: ^4.0.5 => 4.2.7
vite: ^4.4.2 => 4.5.0

wrangler.toml file

name = "sveltekit-app"
compatibility_date = "2021-11-12"
account_id = "id"
workers_dev = true
main = "./.cloudflare/worker.js"
site.bucket = "./.cloudflare/public"
build.command = "npm run build"
kv_namespaces = [
{ binding = "KV_1", id = "id", preview_id = "preview" },
{ binding = "KV_2", id = "id", preview_id = "preview" }
]

app.d.ts
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
interface Locals {
user: GithubUser;
KV_1: KVNamespace;
KV_2: KVNamespace;
}
interface Platform {
env?: {
KV_1: KVNamespace;
KV_2: KVNamespace;
};
}
}
declare namespace svelteHTML {
interface HTMLAttributes<T> {
'on:outclick'?: CompositionEventHandler<T>;
}
}
}

export {};
npmPackages:
@sveltejs/adapter-auto: ^2.0.0 => 2.1.1
@sveltejs/adapter-cloudflare: ^2.3.3 => 2.3.3
@sveltejs/adapter-cloudflare-workers: ^1.2.1 => 1.2.1
@sveltejs/kit: ^1.27.6 => 1.27.6
svelte: ^4.0.5 => 4.2.7
vite: ^4.4.2 => 4.5.0

wrangler.toml file

name = "sveltekit-app"
compatibility_date = "2021-11-12"
account_id = "id"
workers_dev = true
main = "./.cloudflare/worker.js"
site.bucket = "./.cloudflare/public"
build.command = "npm run build"
kv_namespaces = [
{ binding = "KV_1", id = "id", preview_id = "preview" },
{ binding = "KV_2", id = "id", preview_id = "preview" }
]

app.d.ts
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
interface Locals {
user: GithubUser;
KV_1: KVNamespace;
KV_2: KVNamespace;
}
interface Platform {
env?: {
KV_1: KVNamespace;
KV_2: KVNamespace;
};
}
}
declare namespace svelteHTML {
interface HTMLAttributes<T> {
'on:outclick'?: CompositionEventHandler<T>;
}
}
}

export {};
Anyone have any clue?
3 replies
CDCloudflare Developers
Created by sten on 11/29/2023 in #workers-help
Workers not logging objects
Tried to log an exception that was thrown but all it logged was: How can we debug better in workers?
{
"message": [
"mylog",
"[object Object]"
],
"level": "log",
"timestamp": 1701263872409
},
{
"message": [
"mylog",
"[object Object]"
],
"level": "log",
"timestamp": 1701263872409
},
By using JSON.stringifiyit printed out empty object "{}",
4 replies
CDCloudflare Developers
Created by sten on 10/5/2023 in #workers-help
How do you write to Cloudflare KV when developing locally with wrangler dev?
I remember that you could write directly to Cloudflare KV's namespace when running wrangler dev locally.
name = "project_name"
main = "src/index.js"
compatibility_date = "2022-10-06"
type = "webpack"

account_id = "account_id..."
workers_dev = true

kv_namespaces = [
{ binding = "namespace_name", id = "id..." }
]

[env.staging]
kv_namespaces = [
{ binding = "namespace_name", id = "id..." }
]

[env.production]
kv_namespaces = [
{ binding = "namespace_name", id = "id..." }
]
name = "project_name"
main = "src/index.js"
compatibility_date = "2022-10-06"
type = "webpack"

account_id = "account_id..."
workers_dev = true

kv_namespaces = [
{ binding = "namespace_name", id = "id..." }
]

[env.staging]
kv_namespaces = [
{ binding = "namespace_name", id = "id..." }
]

[env.production]
kv_namespaces = [
{ binding = "namespace_name", id = "id..." }
]
This is what my wrangler.toml looks like. I am currently running by calling wrangler dev. I have logged in with wrangler. It was a while ago since I did this, maybe an update have come or so. Right now it writes to local cache at .wrangler/kv
10 replies