Skip to content

Commit

Permalink
feat(database): setup basic data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Apr 15, 2024
1 parent 46cc98d commit e5829d1
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 1 deletion.
47 changes: 47 additions & 0 deletions packages/database/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@satorijs/database",
"description": "Database for Satori protocol",
"version": "0.1.0",
"type": "module",
"main": "lib/index.cjs",
"module": "lib/index.mjs",
"types": "lib/index.d.ts",
"exports": {
".": {
"require": "./lib/index.cjs",
"import": "./lib/index.mjs",
"types": "./lib/index.d.ts"
},
"./package.json": "./package.json"
},
"files": [
"lib",
"src"
],
"author": "Shigma <[email protected]>",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/satorijs/satori.git",
"directory": "packages/database"
},
"bugs": {
"url": "https://github.com/satorijs/satori/issues"
},
"homepage": "https://github.com/satorijs/satori/tree/master/packages/database",
"keywords": [
"satori",
"protocol",
"server",
"basic",
"api",
"database"
],
"devDependencies": {
"@satorijs/server-satori": "^2.4.3"
},
"peerDependencies": {
"@satorijs/satori": "^3.6.6",
"minato": "^3.1.1"
}
}
84 changes: 84 additions & 0 deletions packages/database/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import {} from 'minato'
import { Context, Schema, Service } from '@satorijs/satori'
import { Channel, Guild, Message, User } from '@satorijs/protocol'

declare module 'minato' {
namespace Database {
export interface Tables {
'satori.message': Message & { platform: string }
'satori.user': User & { platform: string }
'satori.guild': Guild & { platform: string }
'satori.channel': Channel & { platform: string }
}
}
}

declare module '@satorijs/core' {
interface Context {
sdb: SDB
}
}

declare module '@satorijs/protocol' {
interface Message {
uid?: number
}
}

class SDB extends Service<SDB.Config> {
[Service.provide] = 'sdb'
inject = ['database']

constructor(ctx: Context, config: SDB) {
super(ctx, config)

ctx.model.extend('satori.message', {
'uid': 'unsigned(8)', // int64
'id': 'char(255)',
'platform': 'char(255)',
'user.id': 'char(255)',
'channel.id': 'char(255)',
'guild.id': 'char(255)',
'quote.id': 'char(255)',
'content': 'text',
'createdAt': 'unsigned(8)',
'updatedAt': 'unsigned(8)',
}, {
primary: 'uid',
})

ctx.model.extend('satori.user', {
'id': 'char(255)',
'platform': 'char(255)',
'name': 'char(255)',
'nick': 'char(255)',
'avatar': 'char(255)',
}, {
primary: ['id', 'platform'],
})

ctx.model.extend('satori.guild', {
'id': 'char(255)',
'platform': 'char(255)',
'name': 'char(255)',
}, {
primary: ['id', 'platform'],
})

ctx.model.extend('satori.channel', {
'id': 'char(255)',
'platform': 'char(255)',
'name': 'char(255)',
}, {
primary: ['id', 'platform'],
})
}
}

namespace SDB {
export interface Config {}

export const Config: Schema<Config> = Schema.object({})
}

export default SDB
12 changes: 12 additions & 0 deletions packages/database/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.base",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"strict": true,
"noImplicitAny": false,
},
"include": [
"src",
],
}
2 changes: 1 addition & 1 deletion packages/server-satori/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"bugs": {
"url": "https://github.com/satorijs/satori/issues"
},
"homepage": "https://github.com/satorijs/satori/tree/master/packages/server",
"homepage": "https://github.com/satorijs/satori/tree/master/packages/server-satori",
"keywords": [
"satori",
"protocol",
Expand Down

0 comments on commit e5829d1

Please sign in to comment.