WIP db with sources and publishers, contributing.md
This commit is contained in:
parent
062f323313
commit
4027bab5fb
13 changed files with 120 additions and 1 deletions
1
.env
Normal file
1
.env
Normal file
|
@ -0,0 +1 @@
|
|||
DB_FILE_NAME=db.sqlite
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
node_modules
|
2
.mise.toml
Normal file
2
.mise.toml
Normal file
|
@ -0,0 +1,2 @@
|
|||
[tools]
|
||||
bun = "latest"
|
21
CONTRIBUTING.md
Normal file
21
CONTRIBUTING.md
Normal file
|
@ -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`.
|
|
@ -1,3 +1,7 @@
|
|||
# gmscreen
|
||||
|
||||
GM Screen Printing Tool
|
||||
|
||||
---
|
||||
|
||||
Project setup can be found in [CONTRIBUTING.md](./CONTRIBUTING.md)
|
||||
|
|
BIN
bun.lockb
Executable file
BIN
bun.lockb
Executable file
Binary file not shown.
BIN
db.sqlite
Normal file
BIN
db.sqlite
Normal file
Binary file not shown.
11
drizzle.config.ts
Normal file
11
drizzle.config.ts
Normal file
|
@ -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!,
|
||||
},
|
||||
});
|
8
package.json
Normal file
8
package.json
Normal file
|
@ -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"
|
||||
}
|
||||
}
|
33
src/db/index.ts
Normal file
33
src/db/index.ts
Normal file
|
@ -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);
|
||||
});
|
12
src/db/publishers.ts
Normal file
12
src/db/publishers.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { publisherTable } from './schema';
|
||||
|
||||
type Publisher = typeof publisherTable.$inferInsert;
|
||||
|
||||
const publishers: Array<Publisher> = [
|
||||
{
|
||||
name: 'Limithron',
|
||||
url: 'https://www.limithron.com/',
|
||||
}
|
||||
]
|
||||
|
||||
export default publishers;
|
14
src/db/schema.ts
Normal file
14
src/db/schema.ts
Normal file
|
@ -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(),
|
||||
});
|
||||
|
12
src/db/sources.ts
Normal file
12
src/db/sources.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { sourceTable } from './schema';
|
||||
|
||||
type Source = typeof sourceTable.$inferInsert;
|
||||
|
||||
const sources: Array<Source> = [
|
||||
{
|
||||
name: 'Pirate Borg',
|
||||
url: 'https://www.limithron.com/pirateborg',
|
||||
}
|
||||
]
|
||||
|
||||
export default sources;
|
Loading…
Add table
Reference in a new issue