Exemple #1
0
    def __init__(self, flags, port):
        ip = ipgetter.myip()  # Get external IP

        self.databaseReference = database.Database(ip)  # Init db

        if port == 0 or port is none:
            port = 3000

        self.port = port

        try:
            self.databaseReference.ReadFromMemory(
            )  # Attempt to read from memory
        except Exception as e:
            print(e)  # Log found exception
            self.databaseReference.WriteToMemory(
            )  # Write new to memory if nonexistent

        self.startServer(flags, self.port)  # start server
Exemple #2
0
    def create_user(self, discord_id, token):
        self._database.execute(
            sql="INSERT INTO user(discordid, token) VALUES(:discord_id, :token)",
            dic={"discord_id": discord_id,
                 "token": token},
            commit=True)

    def insert_user(self, discord_id: int, key: int, val):
        """
        :param val: value to add to user
        :param key: {0: gwaccount, 1: discordid, 2: token}
        :param discord_id: user to add data too
        """
        self._database.execute(
            sql="INSERT OR REPLACE INTO user(discordid, {}) VALUES(:discord_id, :val)".format(self._column.get(key)),
            dic={"discord_id": discord_id,
                 "val": val},
            commit=True)


if __name__ == '__main__':
    database = db.Database(debug=True)
    if not database.check_tables("shard"):
        database.execute(sql=db.sql_create_shard_table, commit=True)
    user = User(database)
    user.create_user(discord_id=0)
    user.insert_user(discord_id=0, key=0, val="123456789")
    row = user.get_user(discord_id=0)
    database.dump()
    database.close()
def TestWriteToMemory():
    db = database.Database('192.168.1.14')  # Init new database

    db.WriteToMemory()  # Write Database to memory
def TestReadFromMemory():
    db = database.Database('192.168.1.14')  # Init new database

    db.WriteToMemory()  # Write Database to memory

    db.ReadFromMemory()  # Attempt to read database from memory
Exemple #5
0
#!/usr/bin/env python3.7

import src.database.database as db

if __name__ == '__main__':
    database = db.Database()
    for table in db.tables:
        database.execute(table)
    database.close()