changing name of sql table to be more intuitive.

This commit is contained in:
Stefan Midjich 2017-11-16 20:48:13 +01:00
parent 07f68b91b5
commit 2faac71fe5
2 changed files with 7 additions and 7 deletions

View File

@ -8,7 +8,7 @@ BEGIN
--more types here... --more types here...
END$$; END$$;
create table if not exists client ( create table if not exists authenticated_clients (
client_id uuid NOT NULL unique, client_id uuid NOT NULL unique,
created timestamp NOT NULL, created timestamp NOT NULL,
ip_address inet NOT NULL, ip_address inet NOT NULL,
@ -20,4 +20,4 @@ create table if not exists client (
primary key (client_id, ip_address, protocol) primary key (client_id, ip_address, protocol)
); );
create index if not exists client_ip_address_index on client (ip_address); create index if not exists client_ip_address_index on authenticated_clients (ip_address);

View File

@ -35,14 +35,14 @@ class StoragePostgres(object):
def client_ids(self): def client_ids(self):
self.cur.execute( self.cur.execute(
'select client_id from client' 'select client_id from authenticated_clients'
) )
return self.cur.fetchall() return self.cur.fetchall()
def get_client_by_id(self, client_id): def get_client_by_id(self, client_id):
self.cur.execute( self.cur.execute(
'select * from client where client_id=%s', 'select * from authenticated_clients where client_id=%s',
(client_id,) (client_id,)
) )
return self.cur.fetchone() return self.cur.fetchone()
@ -54,7 +54,7 @@ class StoragePostgres(object):
""" """
self.cur.execute( self.cur.execute(
'select * from client where ip_address=%s and protocol=%s', 'select * from authenticated_clients where ip_address=%s and protocol=%s',
(ip_address, protocol, ) (ip_address, protocol, )
) )
return self.cur.fetchone() return self.cur.fetchone()
@ -62,7 +62,7 @@ class StoragePostgres(object):
def write_client(self, client): def write_client(self, client):
query = ( query = (
'insert into client (client_id, created, ip_address, protocol, ' 'insert into authenticated_clients (client_id, created, ip_address, protocol, '
'enabled, last_packets, last_activity, expires) values ' 'enabled, last_packets, last_activity, expires) values '
'(%s, %s, %s, %s, %s, %s, %s, %s) on conflict (client_id, ' '(%s, %s, %s, %s, %s, %s, %s, %s) on conflict (client_id, '
'ip_address, protocol) do update set (enabled, last_packets, ' 'ip_address, protocol) do update set (enabled, last_packets, '
@ -86,7 +86,7 @@ class StoragePostgres(object):
def remove_client(self, client): def remove_client(self, client):
query = 'delete from client where client_id=%s' query = 'delete from authenticated_clients where client_id=%s'
self.cur.execute(query, (client.client_id,)) self.cur.execute(query, (client.client_id,))
self.conn.commit() self.conn.commit()