# 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
        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))
            except psycopg2.ProgrammingError as e:
                self._report_query_error(e)

            pks = []

            row = self.cur.fetchone()
            while row:
                pks.append(row[0])

                row = self.cur.fetchone()

            for pk in pks:
                path = os.path.join(base_path, "%s.yaml" % pk)

                if not self.override and os.path.isfile(path):
                    continue
                with open(path, "w") as f:
                    yaml.dump(self.to_dict(model, pk), f, default_flow_style=False)


    def to_dict(self, model, pk):
        try:
            self.cur.execute(
                "SELECT %s FROM %s WHERE pk = %s",

# 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

        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))
            except psycopg2.ProgrammingError as e:
                self._report_query_error(e)

            pks = []

            row = self.cur.fetchone()
            while row:
                pks.append(row[0])

                row = self.cur.fetchone()

            for pk in pks:
                path = os.path.join(base_path, "%s.yaml" % pk)

                if not self.override and os.path.isfile(path):
                    continue
                with open(path, "w") as f:
                    yaml.dump(self.to_dict(model, pk), f, default_flow_style=False)


    def to_dict(self, model, pk):
        try:
            self.cur.execute(
                "SELECT %s FROM %s WHERE pk = %s",

                (','.join(model.field_names), camel_to_snake(model.name), pk),