Skip to content

Instantly share code, notes, and snippets.

@tom-huntington
Last active March 13, 2023 22:36
Show Gist options
  • Save tom-huntington/fced6a8ae8083771642671d73d5fdb79 to your computer and use it in GitHub Desktop.
Save tom-huntington/fced6a8ae8083771642671d73d5fdb79 to your computer and use it in GitHub Desktop.
Just noob questions

How to launch sveltkit server?

$ npm run dev

How to develop with planetscale? Online or local db instance?

Online.

planetscale/discussion#93 https://www.reddit.com/r/nextjs/comments/uuu4xu/does_anyone_know_how_to_use_planetscale_for_local/

How to develop Cloudflare Workers?

Just npm run dev and Vite will do the rest for you: https://developers.cloudflare.com/workers/get-started/guide#2-run-your-development-server

Without Edge

Oh you only get planetscale (+cf workers) if you select Edge. So without Edge, you are using AWS lambda I assume. But what sql database provider do you use with AWS lambda?

A: Planetscale even when not using Edge. You probably just want to go with Edge.

Edge

https://developers.cloudflare.com/pages/framework-guides/deploy-a-svelte-site

How does trpc work?

The docs say a good place to start is src/lib/server/routes/_app.ts for tRPC. So here is where you define queries, but how do you call them?

import { router, publicProcedure } from '../trpc';
import { z } from 'zod';

export const appRouter = router({
	greeting: publicProcedure
		.input(
			z.object({
				name: z.string().optional(),
			})
		)
		.query(({ input }) => {
			return `Hello, ${input.name ?? 'world'}!`;
		}),
});

export type AppRouter = typeof appRouter;

It seems like you access them here src/lib/trpc/index.ts.

import { createTRPCSvelte } from 'trpc-svelte-query';
import { ssrLink } from 'trpc-svelte-query/ssr';
import { httpBatchLink } from '@trpc/client';
import type { AppRouter } from '$lib/server/routes/_app';
import { transformer } from './transformer';

export const trpc = createTRPCSvelte<AppRouter>({
	links: [
		ssrLink(httpBatchLink)({
			url: '/api/trpc',
		}),
	],
	transformer,
});

Hmmmm, the structure is tricky. You have src/routes/ and also src/lib/server/routes/. Oh, apparently lib contains your library code (utilities and components). server contains your server-only library code. So this means you can only call the greeting route/query on the server?

How do you import the trpc object? Just import { trpc } from '$lib/trpc/index.ts';?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment