gorm 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ <% if tool.explicit_require %>require '<%= tool.path %>'
2
+ <% else %>require '<%= tool.name %>'
3
+ <% end %>
4
+
5
+ Gorm.schema '<%= name %>', :namespace => '<%= camelized %>' do |s|
6
+
7
+ s.migration do |m|
8
+ m.create_table :widgets do |t|
9
+ t.string :name
10
+ t.integer :size
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,124 @@
1
+ <%= stamp 'warning.h' %>
2
+
3
+ #include "<%= output_path %>.h"
4
+ #include "Bump/Bump.h"
5
+ #include <QFile>
6
+ #include <QtSql>
7
+
8
+ using namespace <%= namespace %>;
9
+
10
+ const QString DATABASE_FILENAME = "<%= namespace %>.sqlite";
11
+
12
+ <%= class_name %>::<%= class_name %>(QObject *parent) :
13
+ QObject(parent)
14
+ {
15
+ }
16
+
17
+ <%= class_name %>::~<%= class_name %>()
18
+ {
19
+ }
20
+
21
+ bool <%= class_name %>::open()
22
+ {
23
+ _qDatabase = QSqlDatabase::addDatabase("QSQLITE");
24
+ _qDatabase.setDatabaseName(sandboxPath(DATABASE_FILENAME));
25
+ return _qDatabase.open() && updateSchema();
26
+ }
27
+
28
+ bool <%= class_name %>::close()
29
+ {
30
+ _qDatabase.close();
31
+ return true;
32
+ }
33
+
34
+ bool <%= class_name %>::erase()
35
+ {
36
+ _qDatabase.close();
37
+ return QFile::remove(sandboxPath(DATABASE_FILENAME));
38
+ }
39
+
40
+ bool <%= class_name %>::updateSchema()
41
+ {
42
+ int nextVersion;
43
+ int version = currentSchemaVersion();
44
+ while (version < APP_SCHEMA_VERSION)
45
+ {
46
+ if (!applyIncrementalMigration(version + 1))
47
+ {
48
+ qCritical() << "Could not apply incremental migration" << QString::number(version + 1)
49
+ << _qDatabase.lastError();
50
+ return false;
51
+ }
52
+ nextVersion = currentSchemaVersion();
53
+ if (nextVersion <= version)
54
+ {
55
+ qCritical() << "Incremental migration failed to increment the database schema number";
56
+ return false;
57
+ }
58
+ version = nextVersion;
59
+ }
60
+ return true;
61
+ }
62
+
63
+ int <%= class_name %>::currentSchemaVersion() const
64
+ {
65
+ Q_ASSERT(_qDatabase.isOpen() && _qDatabase.isValid());
66
+ if (_qDatabase.tables().count() == 0) return -1;
67
+ QSqlQuery query;
68
+ if (!query.exec("SELECT schema_version FROM meta WHERE id = 1") || !query.next())
69
+ {
70
+ qCritical() << "Unable to determine the current database schema version. The database is corrupt.";
71
+ abort();
72
+ }
73
+ return query.value(0).toInt();
74
+ }
75
+
76
+ bool <%= class_name %>::applyIncrementalMigration(int migrationVersion)
77
+ {
78
+ switch(migrationVersion)
79
+ {
80
+ <% migrations.each do |m| %>
81
+ case <%= m.index %>: return <%= m.method_call %>;
82
+ <% end %>
83
+ default:
84
+ qCritical() << "No such schema migration version" << QString::number(migrationVersion);
85
+ return false;
86
+ }
87
+ }
88
+
89
+ <% migrations.each do |m| %>
90
+ <%= m.method_stub :qualify => true %>
91
+ {
92
+ QSqlQuery query;
93
+ _qDatabase.transaction();
94
+ // TODO: migration body
95
+ query.exec("UPDATE meta SET schema_version = <%= m.index %> WHERE id = 1");
96
+ return _qDatabase.commit();
97
+ }
98
+ <% end %>
99
+
100
+ // bool <%= class_name %>::applyMigration0()
101
+ // {
102
+ // QSqlQuery query;
103
+ // _qDatabase.transaction();
104
+ // query.exec("CREATE TABLE meta (id INTEGER PRIMARY KEY, schema_version INTEGER)");
105
+ // query.exec("INSERT INTO meta VALUES (1, 1);");
106
+ // return _qDatabase.commit();
107
+ // }
108
+ //
109
+ // bool <%= class_name %>::applyMigration1()
110
+ // {
111
+ // QSqlQuery query;
112
+ // _qDatabase.transaction();
113
+ // query.exec("CREATE TABLE file_types (id INTEGER PRIMARY KEY, name VARCHAR(256))");
114
+ // query.exec("CREATE TABLE file_type_recognizers (id INTEGER PRIMARY KEY, file_type_id INTEGER, extension VARCHAR(16), path_pattern TEXT)");
115
+ // query.exec("CREATE TABLE matchers (id INTEGER PRIMARY KEY, file_type_id INTEGER, pattern TEXT)");
116
+ // query.exec("INSERT INTO file_types VALUES (NULL, 'Bump Log')");
117
+ // int fileTypeId = query.lastInsertId().toInt();
118
+ // query.prepare("INSERT INTO matchers VALUES (NULL, ?, ?)");
119
+ // query.bindValue(0, fileTypeId);
120
+ // query.bindValue(1, "(?P<year>\\d{4})-(?P<month>\\d{2})-(?P<day>\\d{2})");
121
+ // query.exec();
122
+ // query.exec("UPDATE meta SET schema_version = 2 WHERE id = 1");
123
+ // return _qDatabase.commit();
124
+ // }
@@ -0,0 +1,76 @@
1
+ <%= stamp 'warning.h' %>
2
+
3
+ <%= include_guard_begin include_guard_name %>
4
+
5
+ #include <QObject>
6
+ #include <QString>
7
+ #include <QSqlDatabase>
8
+
9
+ <%= namespace_begin namespace %>
10
+
11
+
12
+ class <%= class_name %> : public QObject
13
+ {
14
+ Q_OBJECT
15
+ QSqlDatabase _qDatabase;
16
+
17
+ /** The schema version required by this release of the app. */
18
+ static const int APP_SCHEMA_VERSION = <%= app_schema_version %>;
19
+
20
+ public:
21
+
22
+ explicit <%= class_name %>(QObject *parent = 0);
23
+ virtual ~<%= class_name %>();
24
+
25
+ /** Open the database. */
26
+ bool open();
27
+
28
+ /** Close the database. */
29
+ bool close();
30
+
31
+ /** Erase the database. */
32
+ bool erase();
33
+
34
+ private:
35
+
36
+ /**
37
+ Apply the given incremental migration.
38
+ @param migrationVersion An integer indicating which migration to apply.
39
+ A migration version of 1 applies the migration which takes the database
40
+ from schema version 0 to 1. A migration version of 2 takes it from 1 to
41
+ 2, and so on.
42
+ @returns @c false if the migration could not be applied.
43
+ */
44
+ bool applyIncrementalMigration(int migrationVersion);
45
+
46
+ /**
47
+ The schema version of the current database.
48
+ Schema versions start at 0 and increase at integer intervals. Schema
49
+ version -1 has a special meaning: the database is empty. Schema version
50
+ 0 installs a meta table for keeping track of the current database schema.
51
+ Schema version 1 is the schema used by the first release of the app,
52
+ version 2 by the second release, and so on.
53
+ @returns The schema version.
54
+ */
55
+ int currentSchemaVersion() const;
56
+
57
+ /**
58
+ Update the database schema if necessary.
59
+ @returns @c false if the update failed.
60
+ */
61
+ bool updateSchema();
62
+
63
+ private: // Schema Migrations
64
+ <% migrations.each do |m| %>
65
+ <%= m.method_stub %>;
66
+ <% end %>
67
+
68
+ signals:
69
+
70
+ public slots:
71
+
72
+ };
73
+
74
+
75
+ <%= namespace_end namespace %>
76
+ <%= include_guard_end %>
@@ -0,0 +1 @@
1
+ <%= stamp 'warning.h' %>
@@ -0,0 +1 @@
1
+ <%= stamp 'warning.h' %>
@@ -1,5 +1,5 @@
1
1
  module Gorm
2
2
  unless const_defined? :VERSION
3
- VERSION = '0.0.6'
3
+ VERSION = '0.0.7'
4
4
  end
5
5
  end
@@ -0,0 +1,6 @@
1
+ #toc {
2
+ -webkit-box-shadow: 0px 0px 2px #bbb;
3
+ }
4
+ #search a:link, #search a:visited {
5
+ -webkit-box-shadow: 0px 0px 2px #eee;
6
+ }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gorm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kevin Tonon
@@ -32,7 +32,7 @@ dependencies:
32
32
  type: :development
33
33
  version_requirements: *id001
34
34
  - !ruby/object:Gem::Dependency
35
- name: rdoc
35
+ name: yard
36
36
  prerelease: false
37
37
  requirement: &id002 !ruby/object:Gem::Requirement
38
38
  none: false
@@ -45,36 +45,6 @@ dependencies:
45
45
  version: "0"
46
46
  type: :development
47
47
  version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: aruba
50
- prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
60
- type: :development
61
- version_requirements: *id003
62
- - !ruby/object:Gem::Dependency
63
- name: gli
64
- prerelease: false
65
- requirement: &id004 !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - "="
69
- - !ruby/object:Gem::Version
70
- hash: 29
71
- segments:
72
- - 2
73
- - 4
74
- - 1
75
- version: 2.4.1
76
- type: :runtime
77
- version_requirements: *id004
78
48
  description:
79
49
  email: kevin@betweenconcepts.com
80
50
  executables: []
@@ -85,6 +55,11 @@ extra_rdoc_files: []
85
55
 
86
56
  files:
87
57
  - LICENSE
58
+ - cog/templates/gorm/generator.rb.erb
59
+ - cog/templates/gorm/schema.cpp.erb
60
+ - cog/templates/gorm/schema.h.erb
61
+ - cog/templates/gorm/table.cpp.erb
62
+ - cog/templates/gorm/table.h.erb
88
63
  - lib/gorm/cog_tool.rb
89
64
  - lib/gorm/column.rb
90
65
  - lib/gorm/migration.rb
@@ -92,14 +67,13 @@ files:
92
67
  - lib/gorm/table.rb
93
68
  - lib/gorm/version.rb
94
69
  - lib/gorm.rb
70
+ - yard-templates/default/fulldoc/html/css/common.css
95
71
  homepage: https://github.com/ktonon/gorm
96
72
  licenses: []
97
73
 
98
74
  post_install_message:
99
- rdoc_options:
100
- - --title
101
- - gorm
102
- - -ri
75
+ rdoc_options: []
76
+
103
77
  require_paths:
104
78
  - lib
105
79
  - lib