-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #214 from psrenergy/pr/sql-read-only
Add read only mode
- Loading branch information
Showing
5 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module TestReadOnly | ||
|
||
using PSRClassesInterface.PSRDatabaseSQLite | ||
using SQLite | ||
using Dates | ||
using Test | ||
|
||
function test_read_only() | ||
path_schema = joinpath(@__DIR__, "test_read_only.sql") | ||
db_path = joinpath(@__DIR__, "test_read_only.sqlite") | ||
db = PSRDatabaseSQLite.create_empty_db_from_schema(db_path, path_schema; force = true) | ||
PSRDatabaseSQLite.create_element!( | ||
db, | ||
"Configuration"; | ||
label = "Toy Case", | ||
date_initial = DateTime(2020, 1, 1), | ||
) | ||
PSRDatabaseSQLite.create_element!( | ||
db, | ||
"Resource"; | ||
label = "Resource 1", | ||
) | ||
PSRDatabaseSQLite.create_element!( | ||
db, | ||
"Resource"; | ||
label = "Resource 2", | ||
) | ||
|
||
PSRDatabaseSQLite.close!(db) | ||
|
||
db = PSRDatabaseSQLite.load_db(db_path; read_only = true) | ||
|
||
@test PSRDatabaseSQLite.read_scalar_parameters(db, "Configuration", "label") == | ||
["Toy Case"] | ||
@test PSRDatabaseSQLite.read_scalar_parameters(db, "Resource", "label") == | ||
["Resource 1", "Resource 2"] | ||
@test PSRDatabaseSQLite.read_scalar_parameter(db, "Resource", "label", "Resource 1") == | ||
"Resource 1" | ||
|
||
@test_throws SQLite.SQLiteException PSRDatabaseSQLite.create_element!( | ||
db, | ||
"Resource"; | ||
label = "Resource 3", | ||
) | ||
|
||
PSRDatabaseSQLite.close!(db) | ||
return rm(db_path) | ||
end | ||
|
||
function runtests() | ||
Base.GC.gc() | ||
Base.GC.gc() | ||
for name in names(@__MODULE__; all = true) | ||
if startswith("$name", "test_") | ||
@testset "$(name)" begin | ||
getfield(@__MODULE__, name)() | ||
end | ||
end | ||
end | ||
end | ||
|
||
TestReadOnly.runtests() | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
PRAGMA user_version = 1; | ||
PRAGMA foreign_keys = ON; | ||
|
||
CREATE TABLE Configuration ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
label TEXT UNIQUE, | ||
value1 REAL NOT NULL DEFAULT 100, | ||
date_initial TEXT, | ||
enum1 TEXT NOT NULL DEFAULT 'A' CHECK(enum1 IN ('A', 'B', 'C')) | ||
) STRICT; | ||
|
||
|
||
CREATE TABLE Resource ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
label TEXT UNIQUE, | ||
type TEXT NOT NULL DEFAULT "D" CHECK(type IN ('D', 'E', 'F')) | ||
) STRICT; |
ebd81b0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
ebd81b0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/104575
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: