diff --git a/.env b/.env new file mode 100644 index 0000000..c01d9a3 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +DB_FILE_NAME=db.sqlite diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/.mise.toml b/.mise.toml new file mode 100644 index 0000000..a94d1ed --- /dev/null +++ b/.mise.toml @@ -0,0 +1,2 @@ +[tools] +bun = "latest" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..5323e73 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,21 @@ +# GMScreen Contributing + +## Project Setup + +### Dependencies + +- [mise-en-place](https://mise.jdx.dev/) globally installed +- `mise use` will install tools such as `bun` and potentially more + +### Stack + +- Bun (Serverside JS Runner, Server) +- LibSQL (SQLite replacement, database) + - Drizzle + - DrizzleKit + +### Updating Data + +Data is stored in `./db.sqlite` + +To update it, modify the files in `./src/db` and run `bun src/db/index.ts`. diff --git a/README.md b/README.md index 5c524cb..b445a1c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # gmscreen -GM Screen Printing Tool \ No newline at end of file +GM Screen Printing Tool + +--- + +Project setup can be found in [CONTRIBUTING.md](./CONTRIBUTING.md) diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..8a12484 Binary files /dev/null and b/bun.lockb differ diff --git a/db.sqlite b/db.sqlite new file mode 100644 index 0000000..89f4c0d Binary files /dev/null and b/db.sqlite differ diff --git a/drizzle.config.ts b/drizzle.config.ts new file mode 100644 index 0000000..dc28f14 --- /dev/null +++ b/drizzle.config.ts @@ -0,0 +1,11 @@ +import 'dotenv/config'; +import { defineConfig } from 'drizzle-kit'; + +export default defineConfig({ + out: './drizzle', + schema: './src/db/schema.ts', + dialect: 'sqlite', + dbCredentials: { + url: process.env.DB_FILE_NAME!, + }, +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..e0c223a --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { "drizzle-kit": "^0.28.0", "drizzle-orm": "^0.36.1" }, + "devDependencies": { + "@types/bun": "^1.1.13", + "better-sqlite3": "^11.5.0", + "dotenv": "^16.4.5" + } +} diff --git a/src/db/index.ts b/src/db/index.ts new file mode 100644 index 0000000..1c10c0d --- /dev/null +++ b/src/db/index.ts @@ -0,0 +1,33 @@ +import 'dotenv/config'; +import { drizzle } from 'drizzle-orm/bun-sqlite'; +import { publisherTable, sourceTable } from './schema'; +import publishers from './publishers'; +import sources from './sources'; + +const db = drizzle({ connection: { source: process.env.DB_FILE_NAME! } }); + +async function deleteData() { + await db.delete(publisherTable) + console.log('- Publishers Deleted') + + await db.delete(sourceTable) + console.log('- Sources Deleted') +} + +async function seedData() { + await db.insert(publisherTable).values(publishers) + console.log('- Publishers Created') + + await db.insert(sourceTable).values(sources) + console.log('- Sources Created') +} + +(async () => { + console.log('Deleting Existing Data...') + await deleteData(); + console.log('Data Deleted!\n=====\nSeeding Data...') + await seedData(); + console.log('Data Seeded!') +})().catch(err => { + console.error(err); +}); diff --git a/src/db/publishers.ts b/src/db/publishers.ts new file mode 100644 index 0000000..1160b8e --- /dev/null +++ b/src/db/publishers.ts @@ -0,0 +1,12 @@ +import { publisherTable } from './schema'; + +type Publisher = typeof publisherTable.$inferInsert; + +const publishers: Array = [ + { + name: 'Limithron', + url: 'https://www.limithron.com/', + } +] + +export default publishers; diff --git a/src/db/schema.ts b/src/db/schema.ts new file mode 100644 index 0000000..e08bcb0 --- /dev/null +++ b/src/db/schema.ts @@ -0,0 +1,14 @@ +import { int, sqliteTable, text } from "drizzle-orm/sqlite-core"; + +export const publisherTable = sqliteTable("publisher", { + id: int().primaryKey({ autoIncrement: true }), + name: text().notNull().unique(), + url: text().notNull().unique(), +}); + +export const sourceTable = sqliteTable("source", { + id: int().primaryKey({ autoIncrement: true }), + name: text().notNull().unique(), + url: text().notNull().unique(), +}); + diff --git a/src/db/sources.ts b/src/db/sources.ts new file mode 100644 index 0000000..b7514c1 --- /dev/null +++ b/src/db/sources.ts @@ -0,0 +1,12 @@ +import { sourceTable } from './schema'; + +type Source = typeof sourceTable.$inferInsert; + +const sources: Array = [ + { + name: 'Pirate Borg', + url: 'https://www.limithron.com/pirateborg', + } +] + +export default sources;