Skip to content

Instantly share code, notes, and snippets.

@atg
Created May 18, 2012 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atg/2725278 to your computer and use it in GitHub Desktop.
Save atg/2725278 to your computer and use it in GitHub Desktop.
//
// CHXMainDatabase.m
// Chocolat
//
// Created by Alex Gordon on 07/03/2011.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "CHXMainDatabase.h"
#import "FMDatabase.h"
@implementation CHXMainDatabase
@synthesize projectName;
@synthesize dirPath;
- (NSArray *)tables
{
return [NSArray arrayWithObjects:@"resources", @"passes", @"symbols", nil];
}
- (NSArray *)migrations
{
NSMutableDictionary *baseMigration = [NSMutableDictionary dictionary];
[baseMigration setValue:[NSNumber numberWithInteger:0] forKey:@"version"];
[baseMigration setValue:@"baseMigration" forKey:@"selector"];
return [NSArray arrayWithObjects:baseMigration, nil];
}
- (void)willLoad
{
// This will not corrupt the database if Diglett crashes, but it might if the OS crashes or loses power
[self.db executeUpdate:@"PRAGMA synchronous = OFF"];
[self.db executeUpdate:@"PRAGMA auto_vacuum = INCREMENTAL"];
}
- (void)baseMigration
{
[self.db executeUpdate:
@"CREATE TABLE resources (id INTEGER PRIMARY KEY AUTOINCREMENT, "
@" name TEXT," // The name of the file, including extension
@" path TEXT," // A full path to the file
@" language TEXT," // A full identifier for the base language this file has been detected as
@" is_ignored INTEGER" // Was it decided that this resource should be ignored?
@")"];
[self.db executeUpdate:
@"CREATE INDEX resources_index ON resources (path COLLATE NOCASE)"];
//[self.db executeUpdate:
// @"CREATE INDEX resources_index ON resources (path COLLATE BINARY)"];
[self.db executeUpdate:
@"CREATE TABLE passes (id INTEGER PRIMARY KEY AUTOINCREMENT, "
@" resource INTEGER REFERENCES resources(id) ON DELETE CASCADE," // id of the parent resource row
@" timestamp REAL," // An NSDate timestamp for when this pass was started
@" generator_type TEXT," // The type of the generator, for example "index"
@" generator_name TEXT" //The name of the generator, for example "ctags"
@")"];
[self.db executeUpdate:
@"CREATE INDEX passes_index ON passes (resource)"];
[self.db executeUpdate:
@"CREATE TABLE symbols (id INTEGER PRIMARY KEY AUTOINCREMENT,"
@" pass INTEGER REFERENCES passes(id) ON DELETE CASCADE," // id of the parent pass row
@" name TEXT," // The symbol's identifier
@" qualified_name TEXT," // A qualified name like std::string::find. This is option --extra=+q in ctags
@" regex TEXT," // A regex used to locate the symbol (ctags only)
@" type_code TEXT," // A standardized type code used to identify the symbol
@" parent_id INTEGER," // id of the parent symbol's row in this table
@" parent_name TEXT," // name of the parent symbol
@" parent_type_code TEXT," // the standardized type code of the parent symbol
@" range_line INTEGER," // 0-based line index
@" range_column INTEGER," // 0-based column index
@" range_length INTEGER," // length of the symbol
@" UNIQUE (pass, range_line) ON CONFLICT REPLACE"
@")"];
[self.db executeUpdate:
@"CREATE INDEX symbols_index ON symbols (name COLLATE NOCASE, type_code)"];
[self.db executeUpdate:
@"CREATE INDEX symbols_index ON symbols (range_line, pass)"];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment