Database functionality
CStarSurfaces.jl has the ability to interact with database connections for saving and retrieving Mori dream spaces and their properties. The interface here is generic, but currently only an SQLite database holding SurfaceWithTorusAction's is supported.
A connection to the online ldp-database is planned.
CStarSurfaces.DatabaseAdapter — TypeDatabaseAdapter{T <: MoriDreamSpace}Abstract type of a database adapter holding objects of a common subtype of MoriDreamSpace. Subtypes of DatabaseAdapter{T} should at least implement the following functions:
import_from_database, find_in_database.
If the database is writeable, the following functions should be implemented as well:
export_to_database, update_in_database.
CStarSurfaces.SQLiteAdapter — TypeSQLiteAdapter{T} <: DatabaseAdapter{T}An adapter to an SQLite database holding objects of type T where T <: MoriDreamSpace. The type T should at least implement the following methods: create_table, default_column_functions, find_in_database, sqlite_import_row.
CStarSurfaces.SQLiteAdapterSurfaces — TypeSQLiteAdapterSurfaces = SQLiteAdapter{SurfaceWithTorusAction}An adapter to an SQLite database holding objects of type SurfaceWithTorusAction.
CStarSurfaces.create_table — Functioncreate_table(db :: SQLiteAdapterSurfaces; temp = false, ifnotexists = true)Create a new SQLite table with default column definitions holding SurfaceWithTorusActions.
Example
Create a new SQLite database for holding SurfaceWithTorusActions. The resulting table can be inspected with SQLite.jl:
julia> db = SQLiteAdapterSurfaces("my_database.db", "surfaces", "surface_id")
SQLiteAdapterSurfaces(SQLite.DB("my_database.db"), "my_database.db", "surfaces", "surface_id")
julia> create_table(db);
julia> using SQLite
julia> SQLite.tables(db.db)
1-element Vector{SQLite.DBTable}:
SQLite.DBTable("surfaces", Tables.Schema:
:surface_id Union{Missing, Int64}
:is_toric Union{Missing, Int64}
:gen_matrix Union{Missing, String}
:rays Union{Missing, String}
:nrays Union{Missing, Int64}
:lss Union{Missing, String}
:dss Union{Missing, String}
:case_ Union{Missing, String}
:block_sizes Union{Missing, String}
:nblocks Union{Missing, Int64}
:number_of_parabolic_fixed_point_curves Union{Missing, Int64}
:orientation Union{Missing, Int64}
:is_intrinsic_quadric Union{Missing, Int64}
:class_group_rank Union{Missing, Int64}
:class_group_torsion Union{Missing, String}
:class_group_torsion_order Union{Missing, Int64}
:degree_matrix Union{Missing, String}
:canonical_divisor_class Union{Missing, String}
:gorenstein_index Union{Missing, Int64}
:picard_index Union{Missing, Int64}
:log_canonicity_numerator Union{Missing, Int64}
:log_canonicity_denominator Union{Missing, Int64}
:log_canonicity Union{Missing, Float64}
:anticanonical_self_intersection_numerator Union{Missing, Int64}
:anticanonical_self_intersection_denominator Union{Missing, Int64}
:anticanonical_self_intersection Union{Missing, Float64}
:admits_kaehler_ricci_soliton Union{Missing, Int64}
:admits_kaehler_einstein_metric Union{Missing, Int64}
:admits_sasaki_einstein_metric Union{Missing, Int64}
:is_quasismooth Union{Missing, Int64}
:is_factorial Union{Missing, Int64}
:is_smooth Union{Missing, Int64}
:number_of_singularities Union{Missing, Int64}
:singularity_types_string Union{Missing, String}
:number_of_exceptional_prime_divisors Union{Missing, Int64}
:singularity_kind_x_plus Union{Missing, String}
:number_of_exceptional_prime_divisors_x_plus Union{Missing, Int64}
:singularity_kind_x_minus Union{Missing, String}
:number_of_exceptional_prime_divisors_x_minus Union{Missing, Int64}
:is_combinatorially_minimal Union{Missing, Int64})
CStarSurfaces.import_from_database — Functionimport_from_database(db :: SQLiteAdapter{T}; sql :: String = "TRUE", import_attributes = false, showinfo = true) where {T <: MoriDreamSpace}Return a list of objects of type T that match a given sql query. The string sql is used after the WHERE in a SELECT statement, hence can contain restrictions on the columns as well as an ORDER BY and a LIMIT clause.
import_from_database(db :: SQLiteAdapter{T}, ids :: AbstractVector{Int}; import_attributes = false, showinfo = true) where {T <: MoriDreamSpace}Return the list of objects of type T from an SQLite database with the given ids.
import_from_database(db :: SQLiteAdapter{T}, id :: Int; import_attributes = false, showinfo = true)Return the object of type T from an SQLite database with the given id.
CStarSurfaces.find_in_database — Functionfind_in_database(db :: SQLiteAdapterSurfaces, X :: SurfaceWithTorusAction)Tries to find a SurfaceWithTorusAction in an SQLite database. If the surface is in the database, this function returns its id. Otherwise, it returns nothing.
CStarSurfaces.default_column_functions — Functiondefault_column_functions(::Type{T}) where {T <: MoriDreamSpace}Returns a Dict{Symbol, Function} that serves as a default for the names of the columns to export and how to export them for a given subtype of MoriDreamSpace. This should be implemented by all subtypes of MoriDreamSpace where database functionality is desired.
The fallback definition for a general T returns an empty dictionary.
default_column_functions(::Type{<:SurfaceWithTorusAction})The default columns names and how to compute them when exporting objects of type SurfaceWithTorusAction to an SQLite database.
The function names all have the prefix _db_ followed by the name of the column, for instance CStarSurfaces._db_gen_matrix (they are not exported by default). They basically wrap the corresponding attribute function, giving the result as a language-agnostic string for database storage instead of a Julia type.
CStarSurfaces.default_insert_predicate — Functiondefault_insert_predicate(::Type{T}) where {T <: MoriDreamSpace}Returns a function of type (db :: SQLiteAdapter{T}, X :: T) -> Bool that serves as the default insert predicate when exporting objects of type T to an SQLite database. The default implementation returns true if and only if find_in_database(db, X) returns nothing, hence avoiding duplicate entries in the database. Note that there is no default implementation for find_in_database, it has to be implemented for each subtype of MoriDreamSpace where database functionality is desired.
CStarSurfaces.sqlite_import_row — Functionsqlite_import_row(::Type{SurfaceWithTorusAction}, row :: Union{SQLite.Row, NamedTuple})Imports a single row from an SQLiteAdapterSurfaces into a SurfaceWithTorusAction.
CStarSurfaces.export_to_database — Functionexport_to_database(db_adapter :: SQLiteAdapter{T}, Xs :: AbstractVector; kwargs...) where {T <: MoriDreamSpace}Export a list Xs of varieties of type T to an SQLite database. The following keyword arguments are supported:
column_functions: Defaults todefault_column_functions(T). A dictionary of typeDict{Symbol, Function}containing for each exported column name a function that tellsexport_to_databasehow to compute that column. Each function takes an object of typeTand returns an SQLite compatible data type (Int,Float,StringorNothing).insert_predicate: Defaults todefault_insert_predicate(T). A function of type(db :: SQLiteAdapter{T}, X :: T) -> Bool. Only objects where this predicate evaluates totrueare exported.showinfo: Defaults totrue.
CStarSurfaces.update_in_database — Functionupdate_in_database(db :: SQLiteAdapter{T}, column_functions :: Dict{Symbol, <:Function}; sql :: String, column_function_args :: AbstractVector{Symbol}, showinfo = true) where {T <: MoriDreamSpace}Update all rows in an SQLite database matching a given SQL query by recomputing the columns given by column_functions. See also export_to_database and import_from_database.
Keyword arguments:
sql :: String, defaults to"TRUE". The SQL expression used for filtering the rows in the database that should be updated. It is inserted into a SELECT statement after the WHERE, hence can contain restrictions on the columns as well as an ORDER BY and a LIMIT clause.column_function_args :: AbstractVector{String}, defaults to[:variety]. The list of arguments that each column function receives. These can either be names of columns in the database, or the special symbol:variety, in which case the variety corresponding to the row is imported usingsqlite_import_rowand then passed as an argument.showinfo: Defaults totrue.
update_in_database(db :: SQLiteAdapter{T}, ids :: AbstractVector{Int}, column_functions :: Dict{Symbol, <:Function}; column_function_args :: AbstractVector{Symbol}, showinfo = true) where {T <: MoriDreamSpace})Update all rows in an SQLite database with the given ids by recomputing the columns given by column_functions.
update_in_database(db :: SQLiteAdapter{T}, id :: Int, column_functions :: Dict{Symbol, <:Function}, column_function_args :: AbstractVector{Symbol}, showinfo = true) where {T <: MoriDreamSpace}))Update all rows in an SQLite database with the given id by recomputing the columns given by column_functions.
CStarSurfaces.execute_on_database — Functionexecute_on_database(f :: Function, db :: SQLiteAdapter{T}; sql :: String = "TRUE", function_args :: AbstractVector{Symbol} = [:variety], showinfo = true) where {T <: MoriDreamSpace}Executes f on all rows of an SQLite database that are filtered sql. The argument function_args can be used to control the arguments that will be passed to f. See also update_in_database.