Skip to content

Commit

Permalink
docs: add Jorm serialize fxns
Browse files Browse the repository at this point in the history
  • Loading branch information
Jcharis committed Sep 8, 2024
1 parent ed789ce commit 363526a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 45 deletions.
92 changes: 48 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
### Overview

`Jorm.jl` is a simple Julia package designed to simplify interactions between Julia code and databases. It provides a straightforward Object-Relational Mapping (ORM) layer, allowing you to work with databases using Julia structs and functions.
The current database support include SQLite.
+ Future supporting database will include PostGreSQL, MySQL and more.
The current database support includes SQLite.
+ Future plan is to offer support for databases such as PostGreSQL, MySQL and more.

### Installation

Expand Down Expand Up @@ -94,49 +94,53 @@ Jorm.delete_db(connection_string)
Here is a complete example demonstrating the usage of `Jorm.jl`:

```julia
@testset "CRUD Test" begin
struct BlogArticle
title::String
content::String
end

connection_string = Jorm.SQLiteConnectionString(database_name="test.db")
tb = Jorm.tablename(BlogArticle)
db = Jorm.connect(connection_string)
Jorm.create_table(db, BlogArticle, tb)

# Create a new record
data = BlogArticle("First Title", "My Blog Post")
Jorm.insert!(db, BlogArticle, data)

# Read all records
results = Jorm.read_all(db, BlogArticle)
for row in results
@test row.id == 1
end

# Update an existing record
updated_data = BlogArticle("First Title", "Updated Blog Post")
Jorm.update!(db, BlogArticle, 1, updated_data)

# Read one record by ID
result = Jorm.read_one(db, BlogArticle, 1)
println(result)

for row in results
@test row.id == 1
@test row.content == "Updated Blog Post"
end

# Delete a record
result = Jorm.delete!(db, BlogArticle, 1)
result = Jorm.read_one(db, BlogArticle, 1)
@test isempty(result)

# Close the database connection
Jorm.disconnect(db)
Jorm.delete_db(connection_string)

struct BlogArticle
title::String
content::String
end

connection_string = Jorm.SQLiteConnectionString(database_name="test.db")
tb = Jorm.tablename(BlogArticle)
db = Jorm.connect(connection_string)
Jorm.create_table(db, BlogArticle, tb)

# Create a new record
data = BlogArticle("First Title", "My Blog Post")
Jorm.insert!(db, BlogArticle, data)

# Read all records
results = Jorm.read_all(db, BlogArticle)
for row in results
@test row.id == 1
end

# Serialize the data
Jorm.serialize_to_list(results)

# Update an existing record
updated_data = BlogArticle("First Title", "Updated Blog Post")
Jorm.update!(db, BlogArticle, 1, updated_data)

# Read one record by ID
result = Jorm.read_one(db, BlogArticle, 1)
println(result)


for row in results
println(row.id)
println(row.content)
end

# Delete a record
result = Jorm.delete!(db, BlogArticle, 1)
result = Jorm.read_one(db, BlogArticle, 1)
@test isempty(result)

# Close the database connection
Jorm.disconnect(db)
Jorm.delete_db(connection_string)

```

### API Documentation
Expand Down
4 changes: 3 additions & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ CurrentModule = Jorm
The current database support include SQLite.
+ Future supporting database will include PostGreSQL, MySQL and more.

You can use Jorm.jl as an ORM Layer with Oxygen.jl Framework to handle your database operations. The name `Jorm.jl` is a combination of `Julia` + `ORM`.
You can use Jorm.jl as an ORM Layer with Oxygen.jl Web Framework to handle your database operations. This was part of the initial driving goals for designing Jorm.jl.

**The name `Jorm.jl` is a combination of `Julia` + `ORM`.**

### Installation

Expand Down

2 comments on commit 363526a

@Jcharis
Copy link
Member Author

@Jcharis Jcharis commented on 363526a Sep 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release Notes:

  • First Jorm.jl Release
  • ORM package for Julia designed with Oxygen.jl Framework and other WebApps in Mind
  • SQLite Support

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: "Pre-release version not allowed"

Please sign in to comment.