Skip to content
Extraits de code Groupes Projets
Valider d56d77e6 rédigé par Will Hunt's avatar Will Hunt
Parcourir les fichiers

Add missing schema and data item.

parent babb9fb1
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
import { DiscordStore } from "../store";
import { IDbData } from "./dbdatainterface";
import * as log from "npmlog";
export class DbEvent implements IDbData {
public MatrixId: string;
public DiscordId: string;
public Result: boolean;
public async RunQuery(store: DiscordStore, params: any): Promise<null> {
log.silly("DiscordStore", "_get_schema_version");
let row = null;
if (params.matrix_id) {
row = await store.db.getAsync(`
SELECT *
FROM event_store
WHERE matrix_id = $id`, {
$id: params.matrix_id,
});
} else if (params.discord_id) {
row = await store.db.getAsync(`
SELECT *
FROM event_store
WHERE discord_id = $id`, {
$id: params.discord_id,
});
} else {
throw new Error("Unknown row given as a param");
}
this.Result = row !== undefined;
if (this.Result) {
this.MatrixId = row.matrix_id;
this.DiscordId = row.discord_id;
}
return null;
}
public Insert(store: DiscordStore): Promise<null> {
return store.db.runAsync(`
INSERT INTO event_store
(matrix_id,discord_id)
VALUES ($matrix_id,$discord_id);`, {
$matrix_id: this.MatrixId,
$discord_id: this.DiscordId,
});
}
public Update(store: DiscordStore): Promise<null> {
throw new Error("Update is not implemented");
}
public Delete(store: DiscordStore): Promise<null> {
return store.db.runAsync(`
DELETE FROM event_store
WHERE matrix_id = $matrix_id
AND discord_id = $discord_id;`, {
$matrix_id: this.MatrixId,
$discord_id: this.DiscordId,
});
}
}
import {IDbSchema} from "./dbschema";
import {DiscordStore} from "../../store";
import {DiscordClientFactory} from "../../clientfactory";
import * as log from "npmlog";
import * as Bluebird from "bluebird";
export class Schema implements IDbSchema {
public description = "create event_store table";
public run(store: DiscordStore): Promise<null> {
return store.create_table(`
CREATE TABLE event_store (
matrix_id TEXT NOT NULL,
discord_id TEXT NOT NULL,
PRIMARY KEY(matrix_id, discord_id)
);`, "event_store");
}
public rollBack(store: DiscordStore): Promise <null> {
return store.db.execAsync(
`DROP TABLE IF EXISTS guild_emoji;`,
);
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter