postgresql.py 717 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter database
  5. name:postgresql.py
  6. author:rabin
  7. """
  8. import psycopg2
  9. class Postgresql(object):
  10. instance = None
  11. def __new__(cls, *args, **kwd):
  12. if Postgresql.instance is None:
  13. Postgresql.instance = object.__new__(cls, *args, **kwd)
  14. return Postgresql.instance
  15. def __init__(self, config):
  16. self.connect = psycopg2.connect(host=config['host'], port=config['port'], user=config['username'], password=config['password'], database=config['dbname'])
  17. def get(self):
  18. return self.connect
  19. def create(self, name):
  20. 'psql -U postgres'
  21. sql = 'CREATE DATABASE '+name+' WITH OWNER = postgres ENCODING = "UTF8"'
  22. return sql