OK here is some example code snippet where I load prepared SQL statements:

class FastDetailView(DetailView,FastView):

    c = connection.cursor()

    SQL_VIEW_DIRS = {
        'fashion': (
            'include/sql/materializedviews/headlines',
            'include/sql/materializedviews/latestCollections',
            'include/sql/materializedviews/allSeasons',
            'include/sql/materializedviews/fullSeason',
            'include/sql/materializedviews/gallery',
            'include/sql/materializedviews/indexView',
            'include/sql/materializedviews/cover',
            'include/sql/materializedviews/latestSeasonView',
            'include/sql/materializedviews/seasonView',
            'include/sql/materializedviews/collectionView',
            'include/sql/materializedviews/latestCollectionsJSON',
            'include/sql/materializedviews/collectionCardJSON',
            'include/sql/materializedviews/indexJSON',
            'include/sql/materializedviews/categoryJSON',
            'include/sql/materializedviews/articleJSON',
            'include/sql/triggers/globals',
            'include/sql/triggers/brand',
            'include/sql/triggers/collection',
            'include/sql/triggers/collectionlookassignment',
            'include/sql/triggers/cover',
            'include/sql/triggers/look',
            'include/sql/triggers/photo',
            'include/sql/triggers/season',
            'include/sql/triggers/fashion_headlinesviewmat',
            'include/sql/triggers/fashion_latestcollectionsviewmat',
            'include/sql/triggers/fashion_allseasonsviewmat',
            'include/sql/triggers/fashion_fullseasonviewmat',
            'include/sql/triggers/fashion_galleryviewmat',
            'include/sql/triggers/fashion_coverviewmat',
            'include/sql/triggers/fashion_indexviewmat',
            'include/sql/triggers/fashion_latestseasonviewmat',
            'include/sql/triggers/fashion_seasonviewmat',
            'include/sql/triggers/fashion_collectionviewmat',
            'include/sql/triggers/fashion_collectioncardjsonviewmat',
        ),
        'analytics': (
            'include/sql/analytics',
        ),
    }

    MATERIALIZED_VIEWS = True

    @classmethod
    def prepare_db_queries(self):
        logger.info('Reading fashion prepared SQL statements')
        cursor = connection.cursor()
        for sql_view_dir in SQL_VIEW_DIRS['fashion']:
            file_name = sql_view_dir + '/prepare.sql'
            try:
                with open(file_name, 'r') as file:
                    sql_prepare=file.read().strip()
                    if sql_prepare:
                        cursor.execute(sql_prepare)
            except (OSError, IOError) as e:
                pass
            except e:
                logger.info('Error reading SQL file: %s' % file_name)
                raise e
            if MATERIALIZED_VIEWS:
                file_name = sql_view_dir + '/prepare_materialized.sql'
                try:
                    with open(file_name, 'r') as file:
                        sql_prepare=file.read().strip()
                        if sql_prepare:
                            cursor.execute(sql_prepare)
                except (OSError, IOError) as e:
                    pass
                except e:
                    logger.info('Error reading SQL file: %s' % file_name)
                    raise e


It’s a custom view class that basically reads SQL from a separate list of files 
on initialization, and executes those SQL files.  

If I edit these SQL files, it won't restart the development server.

-bobby

> On Jan 4, 2017, at 4:03 PM, Tim Graham <timogra...@gmail.com> wrote:
> 
> Could you give us a code snippet (sample view, perhaps) demonstrating how 
> this caching happens?
> 
> On Wednesday, January 4, 2017 at 3:57:31 PM UTC-5, Bobby Mozumder wrote:
> Hi, 
> 
> Right now, Django only tracks Python module files for autoreload during 
> development. As a project starts to include more custom include files, such 
> as Javascript, SQL, Makefiles, etc.., the autoreload function doesn't apply 
> to these. 
> 
> For my use case, I have custom view functions that call in separate SQL & 
> Javascript files.  (I don’t use the template system.) 
> 
> If I edit these Javascript & SQL files, the Django server doesn’t autoreload. 
> 
> So, I made a pull-request where we can add a manual list of files to track 
> for autoreload: https://github.com/django/django/pull/7791 
> <https://github.com/django/django/pull/7791> 
> 
> In your project's settings.py file, assign a variable TRACK_FILES containing 
> a list of full file paths to track. This will track files to autoreload the 
> development run server as these files are updated. 
> 
> Is this OK?  This pull request is a basic option and I’m sure it can get more 
> complicated than that (directory tracking, Makefiles, Javscript builds, 
> etc..) 
> 
> -bobby
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-developers+unsubscr...@googlegroups.com 
> <mailto:django-developers+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-developers@googlegroups.com 
> <mailto:django-developers@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-developers 
> <https://groups.google.com/group/django-developers>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-developers/c857c334-6388-4e10-8367-ffbee08acc10%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-developers/c857c334-6388-4e10-8367-ffbee08acc10%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/605A1262-888E-4039-8071-F0F19640F1C0%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to