예제 #1
0
    def GET(self, local=None):
        if local is None:
            l = []
            with cnx.cursor() as c:
                sql = 'SELECT * FROM bins  ORDER BY ID'
                c.execute(sql, )
                rows = c.fetchall()

                for row in rows:
                    bin = Bin()
                    bin.ID = row[0]
                    bin.volume = row[1]
                    bin.local = row[2]
                    print(bin.__dict__)
                    l.append(bin.return_JSON())
            c.close()
            return ('Bins \n: %s' % str(l))
        else:
            with cnx.cursor() as c:
                sql = 'SELECT * FROM bins WHERE local like %s'
                c.execute(sql, local)
                variavel = c.fetchone()
            c.close()
            if variavel is not None:
                bin = Bin()
                bin.ID = variavel[0]
                bin.volume = variavel[1]
                bin.local = variavel[2]
                return (bin.return_JSON())
            else:
                return None
예제 #2
0
    def GET(self, name=None):
        if name is None:
            l = []
            with cnx.cursor() as c:
                sql = 'SELECT * FROM users'
                c.execute(sql, )
                rows = c.fetchall()

                for row in rows:
                    user = User()
                    user.name = row[0]
                    user.email = row[1]
                    user.password = row[2]
                    l.append(user.return_JSON())
            c.close()
            return (str(l))
        else:
            with cnx.cursor() as c:
                sql = 'SELECT * FROM users WHERE name like %s'
                c.execute(sql, nome)
                variavel = c.fetchone()
            c.close()
            if variavel is not None:
                user = User()
                user.name = variavel[0]
                user.email = variavel[1]
                user.password = variavel[2]
                return (user.return_JSON())
            else:
                return None
예제 #3
0
    def GET(self, nome=None):
        if nome is None:
            l = []
            with cnx.cursor() as c:
                sql = 'SELECT * FROM usuarios'
                c.execute(sql, )
                rows = c.fetchall()

                for row in rows:
                    usuario = Usuario()
                    usuario.nome = row[0]
                    usuario.email = row[1]
                    usuario.senha = row[2]
                    print(usuario.__dict__)
                    l.append(usuario.return_JSON())
            c.close()
            return (str(l))
        else:
            with cnx.cursor() as c:
                sql = 'SELECT * FROM usuarios WHERE nome like %s'
                c.execute(sql, nome)
                variavel = c.fetchone()
            c.close()
            if variavel is not None:
                usuario = Usuario()
                usuario.nome = variavel[0]
                usuario.email = variavel[1]
                usuario.senha = variavel[2]
                return (usuario.return_JSON())
            else:
                return None
예제 #4
0
    def POST(self):
        data = cherrypy.request.json
        bin = Bin()
        bin.__dict__ = data

        with cnx.cursor() as c:
            sql = "INSERT INTO bins  VALUES (%s, %s, %s)"
            c.execute(sql, (bin.ID, bin.volume, bin.local))
        cnx.commit()
        c.close()
        return 'done'
예제 #5
0
    def POST(self):
        data = cherrypy.request.json
        user = User()
        user.__dict__ = data

        with cnx.cursor() as c:
            sql = "INSERT INTO users VALUES (%s, %s, %s)"
            c.execute(sql, (user.name, user.email, user.password))
        cnx.commit()
        c.close()
        return 'done'
예제 #6
0
    def POST(self):
        data = cherrypy.request.json
        usuario = Usuario()
        usuario.__dict__ = data

        with cnx.cursor() as c:
            sql = "INSERT INTO usuarios  VALUES (%s, %s, %s)"
            c.execute(sql, (usuario.nome, usuario.email, usuario.senha))
        cnx.commit()
        c.close()
        return 'done'
예제 #7
0
def cleanup_database():
    """
    Destruir tabela de bins
    """
    try:
        with cnx.cursor() as con:
            con.execute("DROP TABLE bins")
            con.execute("DROP TABLE truckers")
            cnx.commit()

    except:
        print('don´t exist')
예제 #8
0
def setup_database():
    """
    Criando tabela bins
    """
    with cnx.cursor() as con:
        try:
            con.execute(
                "CREATE TABLE bins (ID varchar(255) NOT NULL, volume int, local varchar(255) NOT NULL)"
            )
            con.execute(
                "CREATE TABLE truckers (ID varchar(255) NOT NULL, volume int, local varchar(255) NOT NULL)"
            )
            con.close()
        except:
            print('already exists')
예제 #9
0
 def DELETE(self, ID):
     with cnx.cursor() as c:
         sql = 'DELETE FROM bins WHERE id = %s'
         c.execute(sql, (ID, ))
     cnx.commit()
     c.close()
예제 #10
0
 def DELETE(self, name):
     with cnx.cursor() as c:
         sql = 'DELETE FROM users WHERE name = %s'
         c.execute(sql, (name, ))
     cnx.commit()
     c.close()