Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kohkimakimoto committed May 28, 2014
0 parents commit cbc53e2
Show file tree
Hide file tree
Showing 85 changed files with 9,011 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcworkspace/contents.xcworkspacedata
*.xcworkspace/xcuserdata
24 changes: 24 additions & 0 deletions FMDBx.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Be sure to run `pod spec lint FMDBx.podspec' to ensure this is a
# valid spec and to remove all comments including this before submitting the spec.
#
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#

Pod::Spec.new do |s|

s.name = "FMDBx"
s.version = "0.0.1"
s.summary = "An extension of FMDB. Provides ORM and migration functionality."
s.homepage = "https://github.com/kohkimakimoto/FMDBx"
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Kohki Makimoto' => '[email protected]' }
s.source = { :git => 'https://github.com/kohkimakimoto/FMDBx.git', :tag => s.version.to_s }
s.source_files = 'Classes/*.{h,m}'
s.library = 'sqlite3'
s.requires_arc = true
s.platform = :ios
s.dependency 'FMDB'

end
609 changes: 609 additions & 0 deletions FMDBx.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions FMDBx.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions FMDBx.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions FMDBx/Classes/FMDBx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import "FMXDatabaseConfiguration.h"
#import "FMXDatabaseManager.h"
#import "FMXDatabaseMigration.h"
#import "FMXHelpers.h"
#import "FMXModel.h"
#import "FMXTableMap.h"
#import "FMXColumnMap.h"
#import "FMXQuery.h"
29 changes: 29 additions & 0 deletions FMDBx/Classes/FMXColumnMap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// FMXColumnMap.h
// FMDBx
//
// Copyright (c) 2014 KohkiMakimoto. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSInteger, FMXColumnMapType) {
FMXColumnMapTypeInt = 0,
FMXColumnMapTypeLong,
FMXColumnMapTypeDouble,
FMXColumnMapTypeString,
FMXColumnMapTypeBool,
FMXColumnMapTypeDate,
FMXColumnMapTypeData
};

@interface FMXColumnMap : NSObject

@property (strong, nonatomic) NSString *name;
@property (assign, nonatomic) FMXColumnMapType type;
@property (assign, nonatomic) BOOL increments;

- (id)initWithName:(NSString *)name type:(FMXColumnMapType)type;
- (NSString *)propertyName;

@end
29 changes: 29 additions & 0 deletions FMDBx/Classes/FMXColumnMap.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// FMXColumnMap.m
// FMDBx
//
// Copyright (c) 2014 KohkiMakimoto. All rights reserved.
//

#import "FMXColumnMap.h"
#import "FMXHelpers.h"

@implementation FMXColumnMap

- (id)initWithName:(NSString *)name type:(FMXColumnMapType)type
{
self = [super init];
if (self) {
self.name = name;
self.type = type;
self.increments = NO;
}
return self;
}

-(NSString *)propertyName
{
return FMXLowerCamelCaseFromSnakeCase(self.name);
}

@end
23 changes: 23 additions & 0 deletions FMDBx/Classes/FMXDatabaseConfiguration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// FMXDatabaseConfigration.h
// FMDBx
//
// Copyright (c) 2014 KohkiMakimoto. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "FMDatabase.h"


@class FMXModelRepository;

@interface FMXDatabaseConfiguration : NSObject

@property (strong, nonatomic) NSString *databasePath;
@property (strong, nonatomic) NSString *databasePathInDocuments;

- (id)initWithDatabasePath:(NSString *)databasePath;

- (FMDatabase *)database;

@end
49 changes: 49 additions & 0 deletions FMDBx/Classes/FMXDatabaseConfiguration.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// FMXDatabaseConfigration.m
// FMDBx
//
// Copyright (c) 2014 KohkiMakimoto. All rights reserved.
//

#import "FMXDatabaseConfiguration.h"

@implementation FMXDatabaseConfiguration

/**
* Setup new database configuration with database path.
*
* @param databasePath database path
* @return FMXDatabaseConfiguration instance.
*/
- (id)initWithDatabasePath:(NSString *)databasePath
{
self = [super init];
if (self) {
self.databasePath = databasePath;

// Set a database file path in the documents directory.
NSString *dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
self.databasePathInDocuments = [dir stringByAppendingPathComponent:databasePath];

// Initialize database file.
NSFileManager *fm = [NSFileManager defaultManager];
if (![fm fileExistsAtPath:self.databasePathInDocuments]) {
// The database file is not found in the documents directory. Create empty database file.
[fm createFileAtPath:self.databasePathInDocuments contents:nil attributes:nil];
NSLog(@"[FMDBx] Create initial database file: %@", self.databasePathInDocuments);
}
}
return self;
}

/**
* Get a FMDatabase instance.
*
* @return FMDatabase instance.
*/
-(FMDatabase *)database
{
return [FMDatabase databaseWithPath:self.databasePathInDocuments];
}

@end
49 changes: 49 additions & 0 deletions FMDBx/Classes/FMXDatabaseManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// FMXDatabaseManager.h
// FMDBx
//
// Copyright (c) 2014 KohkiMakimoto. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "FMXDatabaseMigration.h"
#import "FMXDatabaseConfiguration.h"
#import "FMXTableMap.h"
#import "FMXModel.h"
#import "FMXHelpers.h"
#import "FMXQuery.h"

@class FMXDatabaseMigration;
@class FMXDatabaseConfiguration;
@class FMXQuery;

@interface FMXDatabaseManager : NSObject

+ (FMXDatabaseManager *)sharedInstance;

- (void)registerDatabaseWithName:(NSString *)database
path:(NSString *)databasePath
migration:(FMXDatabaseMigration *)migration;

- (void)registerDefaultDatabaseWithPath:(NSString *)databasePath
migration:(FMXDatabaseMigration *)migration;

- (void)destroyDatabase:(NSString *)database;

- (void)destroyDefaultDatabase;

- (FMXDatabaseConfiguration *)configuration:(NSString *)database;

- (FMXDatabaseConfiguration *)defaultConfiguration;

- (FMDatabase *)database:(NSString *)database;

- (FMDatabase *)databaseForModel:(Class)modelClass;

- (FMDatabase *)defaultDatabase;

- (FMXTableMap *)tableForModel:(Class)modelClass;

- (FMXQuery *)queryForModel:(Class)modelClass;

@end
Loading

0 comments on commit cbc53e2

Please sign in to comment.