/[sudobot]/trunk/src/client/Database.ts
ViewVC logotype

Diff of /trunk/src/client/Database.ts

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/src/Database.js revision 45 by rakin, Mon Jul 29 17:28:20 2024 UTC trunk/src/client/Database.ts revision 342 by rakin, Mon Jul 29 17:29:39 2024 UTC
# Line 1  Line 1 
1  const { Database: DB } = require('sqlite3');  import { Sequelize } from 'sequelize';
2    import { Database as DB } from 'sqlite3';
3    import DiscordClient from './Client';
4    import mongoose from "mongoose";
5    
6    export default class Database {
7        client: DiscordClient;
8        dbpath: string;
9    
10  class Database {      constructor(dbpath: string, client: DiscordClient) {
11      constructor(dbpath) {          this.client = client;
12          this.dbpath = dbpath;          this.dbpath = dbpath;
         this.db = new DB(dbpath, (err) => {  
             if (err) {  
                 console.log(err);  
             }  
         });  
     }  
   
     get(sql, callback1, callback2) {  
         return this.db.get(sql, callback1, callback2);  
     }  
13    
14      all(sql, callback1, callback2) {          mongoose.connect(process.env.MONGO_URI!)
15          return this.db.all(sql, callback1, callback2);              .then(() => console.log("Connected to MongoDB"))
16                .catch(console.error);
17      }      }
   
     runAsync(sql, paramsOrCallback = []) {  
         return new Promise((resolve, reject) => {  
             this.db.run(sql, paramsOrCallback, err => {  
                 if (err) {  
                     reject(err);  
                     return;  
                 }  
   
                 resolve();  
             });  
         });  
     }  
   
     getAsync(sql, paramsOrCallback = []) {  
         return new Promise((resolve, reject) => {  
             this.db.get(sql, paramsOrCallback, (err, data) => {  
                 if (err) {  
                     reject(err);  
                     return;  
                 }  
   
                 resolve(data);  
             });  
         });  
     }  
   
     allAsync(sql, paramsOrCallback = []) {  
         return new Promise((resolve, reject) => {  
             this.db.all(sql, paramsOrCallback, (err, data) => {  
                 if (err) {  
                     reject(err);  
                     return;  
                 }  
   
                 resolve(data);  
             });  
         });  
     }  
 }  
   
 module.exports = Database;  
18    }

Legend:
Removed from v.45  
changed lines
  Added in v.342

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26