demo-sveltekit-pro

Demo of SvelteKit with pro setup for Typescript, Tailwind, DaisyUI, PostCSS, and more

https://github.com/joelparkerhenderson/demo-sveltekit-pro

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (7.3%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

Demo of SvelteKit with pro setup for Typescript, Tailwind, DaisyUI, PostCSS, and more

Basic Info
  • Host: GitHub
  • Owner: joelparkerhenderson
  • Language: Shell
  • Default Branch: main
  • Size: 31.3 KB
Statistics
  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created over 2 years ago · Last pushed 11 months ago
Metadata Files
Readme Citation

README-DRIZZLE.md

Demo SvelteKit: Drizzle

Database

Previously in this demo, we created a database connection and included the credentials in our .env environment variables.

Setup created a Drizzle configuration file drizzle.config.ts:

```ts import { defineConfig } from 'drizzle-kit'; if (!process.env.DATABASEURL) throw new Error('DATABASEURL is not set');

export default defineConfig({ schema: './src/lib/server/db/schema.ts',

dbCredentials: {
    url: process.env.DATABASE_URL
},

verbose: true,
strict: true,
dialect: 'postgresql'

}); ```

Schema

Setup created a Drizzle database schema file src/lib/server/db/schema.ts:

```js import { pgTable, serial, text, integer, timestamp } from 'drizzle-orm/pg-core';

export const user = pgTable('user', { id: text('id').primaryKey(), age: integer('age'), username: text('username').notNull().unique(), passwordHash: text('password_hash').notNull() });

export const session = pgTable('session', { id: text('id').primaryKey(), userId: text('userid') .notNull() .references(() => user.id), expiresAt: timestamp('expiresat', { withTimezone: true, mode: 'date' }).notNull() });

export type Session = typeof session.$inferSelect;

export type User = typeof user.$inferSelect; ```

Change id

We prefer the user id to be an integer primary key generated always as identity.

The session id stays as a text primary key because it will be sent to the browser as a cookie.

Change the user section line.

From:

ts id: text('id').primaryKey(),

Into:

ts id: integer('id').primaryKey().generatedAlwaysAsIdentity({ startWith: 1 }),

Change the session section line.

From:

ts userId: text('user_id')

Into:

ts userId: integer('user_id')

drizzle-kit generate

Generate the SQL needed to migrate the database:

sh npx drizzle-kit generate

Output:

``` 2 tables session 3 columns 0 indexes 1 fks user 4 columns 0 indexes 0 fks

[✓] Your SQL migration file ➜ drizzle/0000prettyrockslide.sql 🚀 ```

Change id again

The file drizzle/0000_pretty_rockslide.sql:

sql CREATE TABLE IF NOT EXISTS "session" ( "id" integer PRIMARY KEY NOT NULL, "user_id" integer NOT NULL, "expires_at" timestamp with time zone NOT NULL ); --> statement-breakpoint CREATE TABLE IF NOT EXISTS "user" ( "id" integer PRIMARY KEY NOT NULL, "age" integer, "username" text NOT NULL, "password_hash" text NOT NULL, CONSTRAINT "user_username_unique" UNIQUE("username") ); --> statement-breakpoint DO $$ BEGIN ALTER TABLE "session" ADD CONSTRAINT "session_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action; EXCEPTION WHEN duplicate_object THEN null; END $$;

Change the user section line from this…

sql "id" integer PRIMARY KEY NOT NULL,

…into this:

sql "id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,

drizzle-kit migrate

Run the migration:

sh npx drizzle-kit migrate

Verify tables:

sh psql -d "postgres://demo_sveltekit_owner:secret@localhost:5432/demo_sveltekit_development" \ -c "SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'information_schema');"

```txt

table_name

_drizzlemigrations user session ```

Verify tables and columns:

sh ➜ psql -d "postgres://demo_sveltekit_owner:secret@localhost:5432/demo_sveltekit_development" -c "SELECT table_name, column_name, data_type FROM information_schema.columns where table_schema = 'public' order by table_name;"

txt table_name | column_name | data_type ------------+---------------+-------------------------- session | id | integer session | user_id | integer session | expires_at | timestamp with time zone user | id | integer user | age | integer user | username | text user | password_hash | text

Owner

  • Name: Joel Parker Henderson
  • Login: joelparkerhenderson
  • Kind: user
  • Location: California

Software developer. Technology consultant. Creator of GitAlias.com, NumCommand.com, SixArm.com, and many open source projects.

Citation (CITATION.cff)

cff-version: 1.2.0
title: demo-sveltekit-pro
message: >-
  If you use this work and you want to cite it,
  then you can use the metadata from this file.
type: software
authors:
  - given-names: Joel Parker
    family-names: Henderson
    email: joel@joelparkerhenderson.com
    affiliation: joelparkerhenderson.com
    orcid: 'https://orcid.org/0009-0000-4681-282X'
identifiers:
  - type: url
    value: 'https://github.com/joelparkerhenderson/demo-sveltekit-pro/'
    description: demo-sveltekit-pro
repository-code: 'https://github.com/joelparkerhenderson/demo-sveltekit-pro/'
abstract: >-
  demo-sveltekit-pro
license: See license file

GitHub Events

Total
  • Push event: 16
Last Year
  • Push event: 16

Committers

Last synced: 10 months ago

All Time
  • Total Commits: 22
  • Total Committers: 1
  • Avg Commits per committer: 22.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 18
  • Committers: 1
  • Avg Commits per committer: 18.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Joel Parker Henderson j****l@j****m 22
Committer Domains (Top 20 + Academic)