Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lucianolorenti/structdatabasemapping.jl
Struct mapping to database in Julia
https://github.com/lucianolorenti/structdatabasemapping.jl
database julia orm
Last synced: about 2 months ago
JSON representation
Struct mapping to database in Julia
- Host: GitHub
- URL: https://github.com/lucianolorenti/structdatabasemapping.jl
- Owner: lucianolorenti
- License: mit
- Archived: true
- Created: 2020-02-18T15:58:07.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-06T08:20:03.000Z (about 3 years ago)
- Last Synced: 2024-09-30T15:18:07.376Z (about 2 months ago)
- Topics: database, julia, orm
- Language: Julia
- Homepage:
- Size: 254 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Coverage Status](https://coveralls.io/repos/github/lucianolorenti/StructDatabaseMapping.jl/badge.svg)](https://coveralls.io/github/lucianolorenti/StructDatabaseMapping.jl) [![](https://img.shields.io/badge/docs-dev-blue.svg)](https://lucianolorenti.github.io/StructDatabaseMapping.jl/dev/index.html)
# Installation
```julia
] add StructDatabaseMapping
```# Compatibility
* [SQLite](https://github.com/JuliaDatabases/SQLite.jl)
* [PostgreSQL](https://github.com/invenia/LibPQ.jl)
* [Redis](https://github.com/JuliaDatabases/Redis.jl)
* Possibly every relational DB that supports the DBInterface# Simple example
[For a better example see the docs](https://lucianolorenti.github.io/StructDatabaseMapping.jl/dev/example.html)
```julia
using StructDatabaseMapping
using Dates
using SQLite
using Testmutable struct Author <: Model
id::DBId{Integer}
name::String
age::Integer
date::DateTime
end
function Author(;id::Union{Integer, Nothing} = nothing,
name::String="",
age::Integer=0,
date::DateTime=now())
return Author(id, name, age, date)
end
mutable struct Book <: Model
id::DBId{String}
author::ForeignKey{Author}
data::Dict{String, Integer}
end
function Book(;id::Union{String, Nothing}=nothing,
author::Foreign{Author}=Author(),
data::Dict{String, Integer}=Dict())
return Book(id, author, data)
endDB_FILE = "test_db"
using SQLite
creator = ()->SQLite.DB(DB_FILE)
mapper = DBMapper(creator)register!(mapper, Author)
register!(mapper, Book)configure_relation(mapper, Book, :author, on_delete=Cascade())
create_table(mapper, Author)
create_table(mapper, Book)
author = Author(name="pirulo", age=50)
insert!(mapper, author)
```