Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor of AlgebraicRelations #31

Merged
merged 7 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .buildkite/build_docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash


pwd; hostname; date

if [ $# -ne 1 ]; then
echo "Usage: $0 VERSION"
echo "Example: $0 1.10.0"
exit 1
fi

VERSION=$1

module load julia/$VERSION

echo "Building documentation..."
julia --project=docs -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.status(); Pkg.instantiate(); include("docs/make.jl")'
11 changes: 11 additions & 0 deletions .buildkite/jobscript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

pwd; hostname; date

module load julia

echo "Running Tests..."
julia --project -e 'using Pkg; Pkg.status(); Pkg.test()'

echo "Building Documentation..."
julia --project=docs -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.status(); Pkg.instantiate(); include("docs/make.jl")'
7 changes: 7 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
steps:

- label: ":arrow_down: Load AlgebraicJulia pipeline"
command: |
curl -s https://raw.githubusercontent.com/AlgebraicJulia/.github/main/buildkite/pipeline.yml | buildkite-agent pipeline upload

- wait
16 changes: 16 additions & 0 deletions .buildkite/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

pwd; hostname; date

if [ $# -ne 1 ]; then
echo "Usage: $0 VERSION"
echo "Example: $0 1.10.0"
exit 1
fi

VERSION=$1

module load julia/$VERSION

echo "Running tests..."
julia --project -e "using Pkg; Pkg.status(); Pkg.test()"
28 changes: 20 additions & 8 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,34 @@ authors = ["bosonbaas <[email protected]>"]
version = "0.3.1"

[deps]
AlgebraicPetri = "4f99eebe-17bf-4e98-b6a1-2c4f205a959b"
AutoHashEquals = "15f4f7f2-30c1-5605-9d31-71845cf9641f"
Catlab = "134e5e36-593f-5add-ad60-77f754baafbe"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
FunSQL = "cf6cc811-59f4-4a10-b258-a8547a8f6407"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LibPQ = "194296ae-ab2e-5f79-8cd4-7183a0a5a0d1"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SQLite = "0aa819cd-b072-5ff4-a722-6bc24af294d9"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[weakdeps]
DuckDB = "d2f5444f-75bc-4fdf-ac35-56f514c445e1"
LibPQ = "2196b101-3ac0-4e12-b5a8-532424305d17"
MySQL = "39abe10b-433b-5dbd-92d4-e302a9df00cd"

[extensions]
DuckDBAlgRelExt = "DuckDB"
LibPQAlgRelExt = "LibPQ"
MySQLACSetsExt = "MySQL"
SQLiteAlgRelExt = "SQLite"

[compat]
AlgebraicPetri = "0.6, 0.7"
AutoHashEquals = "0.2.0, 1, 2"
Catlab = "0.14"
Catlab = "0.16"
DataFrames = "1.0"
LibPQ = "1.4.0"
julia = "1.0"
Reexport = "1.2.2"
SQLite = "1.6.1"
julia = "1.6"

[extras]
SQLite = "0aa819cd-b072-5ff4-a722-6bc24af294d9"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
Expand Down
35 changes: 35 additions & 0 deletions ext/DuckDBAlgRelExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module SQLiteInterop
using AlgebraicRelations.Schemas
using Catlab.CategoricalAlgebra
using Tables
using ...SQLite

function AlgebraicRelations.SQLSchema(db::SQLite.DB)
sch = SQLSchema()
tables = [t.name for t in SQLite.tables(db)]
tab_ind = add_parts!(sch, :Table, length(tables), tname=tables)
tab2ind = Dict([tables[t] => t for t in tab_ind])

col2ind = Dict{String, Dict{String, Int64}}()
for t in tables
col2ind[t] = Dict{String, Int64}()
cols = SQLite.columns(db, t)
for c in 1:length(cols.cid)
type = cols.type[c]
if cols.pk[c] == 1
type *= " PRIMARY KEY"
end
c_ind = add_part!(sch, :Column, table=tab2ind[t], cname=cols.name[c], type=type)
col2ind[t][cols.name[c]] = c_ind
end
end
for t in tables
res = DBInterface.execute(db, "PRAGMA foreign_key_list($t);")
for r in res
add_part!(sch, :FK, from = col2ind[t][r.from],
to = col2ind[r.table][r.to])
end
end
sch
end
end
35 changes: 35 additions & 0 deletions ext/LibPQAlgRelExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module SQLiteInterop
using AlgebraicRelations.Schemas
using Catlab.CategoricalAlgebra
using Tables
using ...SQLite

function AlgebraicRelations.SQLSchema(db::SQLite.DB)
sch = SQLSchema()
tables = [t.name for t in SQLite.tables(db)]
tab_ind = add_parts!(sch, :Table, length(tables), tname=tables)
tab2ind = Dict([tables[t] => t for t in tab_ind])

col2ind = Dict{String, Dict{String, Int64}}()
for t in tables
col2ind[t] = Dict{String, Int64}()
cols = SQLite.columns(db, t)
for c in 1:length(cols.cid)
type = cols.type[c]
if cols.pk[c] == 1
type *= " PRIMARY KEY"
end
c_ind = add_part!(sch, :Column, table=tab2ind[t], cname=cols.name[c], type=type)
col2ind[t][cols.name[c]] = c_ind
end
end
for t in tables
res = DBInterface.execute(db, "PRAGMA foreign_key_list($t);")
for r in res
add_part!(sch, :FK, from = col2ind[t][r.from],
to = col2ind[r.table][r.to])
end
end
sch
end
end
35 changes: 35 additions & 0 deletions ext/MySQLAlgRelExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module SQLiteInterop
using AlgebraicRelations.Schemas
using Catlab.CategoricalAlgebra
using Tables
using ...SQLite

function AlgebraicRelations.SQLSchema(db::SQLite.DB)
sch = SQLSchema()
tables = [t.name for t in SQLite.tables(db)]
tab_ind = add_parts!(sch, :Table, length(tables), tname=tables)
tab2ind = Dict([tables[t] => t for t in tab_ind])

col2ind = Dict{String, Dict{String, Int64}}()
for t in tables
col2ind[t] = Dict{String, Int64}()
cols = SQLite.columns(db, t)
for c in 1:length(cols.cid)
type = cols.type[c]
if cols.pk[c] == 1
type *= " PRIMARY KEY"
end
c_ind = add_part!(sch, :Column, table=tab2ind[t], cname=cols.name[c], type=type)
col2ind[t][cols.name[c]] = c_ind
end
end
for t in tables
res = DBInterface.execute(db, "PRAGMA foreign_key_list($t);")
for r in res
add_part!(sch, :FK, from = col2ind[t][r.from],
to = col2ind[r.table][r.to])
end
end
sch
end
end
36 changes: 36 additions & 0 deletions ext/SQLiteAlgRelExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module SQLiteAlgRelExt

using AlgebraicRelations
using Catlab.CategoricalAlgebra
using Tables
using SQLite

function AlgebraicRelations.SQLSchema(db::SQLite.DB)
sch = SQLSchema()
tables = [t.name for t in SQLite.tables(db)]
tab_ind = add_parts!(sch, :Table, length(tables), tname=tables)
tab2ind = Dict([tables[t] => t for t in tab_ind])

col2ind = Dict{String, Dict{String, Int64}}()
for t in tables
col2ind[t] = Dict{String, Int64}()
cols = SQLite.columns(db, t)
for c in 1:length(cols.cid)
type = cols.type[c]
if cols.pk[c] == 1
type *= " PRIMARY KEY"
end
c_ind = add_part!(sch, :Column, table=tab2ind[t], cname=cols.name[c], type=type)
col2ind[t][cols.name[c]] = c_ind
end
end
for t in tables
res = DBInterface.execute(db, "PRAGMA foreign_key_list($t);")
for r in res
add_part!(sch, :FK, from = col2ind[t][r.from],
to = col2ind[r.table][r.to])
end
end
sch
end
end
13 changes: 9 additions & 4 deletions src/AlgebraicRelations.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
module AlgebraicRelations
include("DB.jl")
include("Queries.jl")
include("Interface.jl")
include("Presentations.jl")

using Reexport

include("Schemas.jl")
include("Queries.jl")

@reexport using .Schemas
@reexport using .Queries

end
62 changes: 0 additions & 62 deletions src/DB.jl

This file was deleted.

Loading