diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2018-07-16 15:58:38 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2018-07-16 18:24:51 +0200 |
commit | 561e55eb6c67f96ea05b471930bbd365dc44629d (patch) | |
tree | c4ff489df8b57d66a15ed8005637d230f4cf4de0 /platform | |
parent | 6c9b627eaa17b06e1762addb4bf1ff182a340086 (diff) | |
download | qtlocation-mapboxgl-561e55eb6c67f96ea05b471930bbd365dc44629d.tar.gz |
[core] make the offline DB schema a regular include file
Diffstat (limited to 'platform')
-rw-r--r-- | platform/default/mbgl/storage/offline_database.cpp | 6 | ||||
-rw-r--r-- | platform/default/mbgl/storage/offline_schema.hpp (renamed from platform/default/mbgl/storage/offline_schema.cpp.include) | 12 | ||||
-rw-r--r-- | platform/default/mbgl/storage/offline_schema.js | 37 |
3 files changed, 30 insertions, 25 deletions
diff --git a/platform/default/mbgl/storage/offline_database.cpp b/platform/default/mbgl/storage/offline_database.cpp index 92e534634d..8f7f0965f4 100644 --- a/platform/default/mbgl/storage/offline_database.cpp +++ b/platform/default/mbgl/storage/offline_database.cpp @@ -6,6 +6,8 @@ #include <mbgl/util/chrono.hpp> #include <mbgl/util/logging.hpp> +#include "offline_schema.hpp" + #include "sqlite3.hpp" namespace mbgl { @@ -82,8 +84,6 @@ void OfflineDatabase::ensureSchema() { } try { - #include "offline_schema.cpp.include" - // When downgrading the database, or when the database is corrupt, we've deleted the old database handle, // so we need to reopen it. if (!db) { @@ -95,7 +95,7 @@ void OfflineDatabase::ensureSchema() { db->exec("PRAGMA auto_vacuum = INCREMENTAL"); db->exec("PRAGMA journal_mode = DELETE"); db->exec("PRAGMA synchronous = FULL"); - db->exec(schema); + db->exec(offlineDatabaseSchema); db->exec("PRAGMA user_version = 6"); } catch (...) { Log::Error(Event::Database, "Unexpected error creating database schema: %s", util::toString(std::current_exception()).c_str()); diff --git a/platform/default/mbgl/storage/offline_schema.cpp.include b/platform/default/mbgl/storage/offline_schema.hpp index 41af81e55b..e177d0dbd3 100644 --- a/platform/default/mbgl/storage/offline_schema.cpp.include +++ b/platform/default/mbgl/storage/offline_schema.hpp @@ -1,5 +1,11 @@ -/* THIS IS A GENERATED FILE; EDIT offline_schema.sql INSTEAD */ -static const char * schema = +#pragma once + +// THIS IS A GENERATED FILE; EDIT offline_schema.sql INSTEAD +// To regenerate, run `node platform/default/mbgl/storage/offline_schema.js` + +namespace mbgl { + +static constexpr const char* offlineDatabaseSchema = "CREATE TABLE resources (\n" " id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,\n" " url TEXT NOT NULL,\n" @@ -53,3 +59,5 @@ static const char * schema = "CREATE INDEX region_tiles_tile_id\n" "ON region_tiles (tile_id);\n" ; + +} // namespace mbgl diff --git a/platform/default/mbgl/storage/offline_schema.js b/platform/default/mbgl/storage/offline_schema.js index 153ba34e38..fdb7dc6405 100644 --- a/platform/default/mbgl/storage/offline_schema.js +++ b/platform/default/mbgl/storage/offline_schema.js @@ -1,24 +1,21 @@ -// To regenerate: -// (cd platform/default/mbgl/storage && node offline_schema.js) - var fs = require('fs'); -var readline = require('readline'); +fs.writeFileSync('platform/default/mbgl/storage/offline_schema.hpp', `#pragma once + +// THIS IS A GENERATED FILE; EDIT offline_schema.sql INSTEAD +// To regenerate, run \`node platform/default/mbgl/storage/offline_schema.js\` + +namespace mbgl { -var lineReader = readline.createInterface({ - input: fs.createReadStream('offline_schema.sql') -}); +static constexpr const char* offlineDatabaseSchema = +${fs.readFileSync('platform/default/mbgl/storage/offline_schema.sql', 'utf8') + .replace(/ *--.*/g, '') + .split('\n') + .filter(a => a) + .map(line => '"' + line + '\\n"') + .join('\n') +} +; -var lines = [ - "/* THIS IS A GENERATED FILE; EDIT offline_schema.sql INSTEAD */", - "static const char * schema = ", -]; +} // namespace mbgl +`); -lineReader - .on('line', function (line) { - line = line.replace(/ *--.*/, ''); - if (line) lines.push('"' + line + '\\n"'); - }) - .on('close', function () { - lines.push(';\n'); - fs.writeFileSync('offline_schema.cpp.include', lines.join('\n')); - }); |