# Path: statik/utils.py
# def camel_to_snake(camel):
#     return '_'.join(re.findall(r'[A-Z][a-z]*', camel))


import os.path
import psycopg2
import yaml
from statik.errors import *
from statik.utils import camel_to_snake
            if not name:
                raise ValueError('name is required to generate external database')
            cls._external_databases[name] = target

            return target

        return decorator


    def factory(self):
        try:
            return ExternalDatabase._external_databases[self.type](self.params, self.error_context)
        except KeyError:
            raise ProjectConfigurationError(
                message="%s is not supported database." % self.type,
                context=self.error_context,
            )


@ExternalDatabase.external_database(name='postgresql')
class PostgreSQL(ExternalDatabase):
    def __init__(self, params=None, error_context=None):
        super(PostgreSQL, self).__init__(params, error_context)

        conn = psycopg2.connect(**self.params)
        self.cur = conn.cursor()

    def write_files(self, base_path, models, **kwargs):
        for model in models:
            try:

# Path: statik/utils.py
# def camel_to_snake(camel):
#     return '_'.join(re.findall(r'[A-Z][a-z]*', camel))


# Path: statik/external_database.py
import os.path
import psycopg2
import yaml
from statik.errors import *
from statik.utils import camel_to_snake

            if not name:
                raise ValueError('name is required to generate external database')
            cls._external_databases[name] = target

            return target

        return decorator


    def factory(self):
        try:
            return ExternalDatabase._external_databases[self.type](self.params, self.error_context)
        except KeyError:
            raise ProjectConfigurationError(
                message="%s is not supported database." % self.type,
                context=self.error_context,
            )


@ExternalDatabase.external_database(name='postgresql')
class PostgreSQL(ExternalDatabase):
    def __init__(self, params=None, error_context=None):
        super(PostgreSQL, self).__init__(params, error_context)

        conn = psycopg2.connect(**self.params)
        self.cur = conn.cursor()

    def write_files(self, base_path, models, **kwargs):
        for model in models:
            try:

                self.cur.execute("SELECT pk FROM %s", camel_to_snake(model.name))