SeaQL / SeaQL/sea-orm

Support Postgres Composite Types

Open
#2,895 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

help-wanted
Dominant language
Rust
Stars
9.9k
Forks
734
Avg merge
6h 36m
Merged PRs (30d)
8

Description

Discussed in https://github.com/SeaQL/sea-orm/discussions/1816

Originally posted by wyatt-herkamp August 20, 2023
Support for Postgres Composite Types
As a note. I do not know a lot about databases. I am just starting to move my own projects from Mysql to Postgres due to its wide range of features.

Motivation

Using JSON for complex types is great because it allows for more compatibility for Mysql, Sqlite, and Postgres. However, if you are working on something that is Postgres only using the natively supported Composite Type would be a lot cleaner and nicer.

Proposed Solutions

Macro

A macro to auto implement any needed traits to do a composite type

/// A modified version of some code from one of my projects to show an example
#[derive(Debug, Clone, Serialize, PostgresCompositeType)]
#[sea_orm(type_name = "file_type")] // Optional
pub struct FileType {
    pub mime_type: String,
    pub charset: String,
    pub programming_language: Option<String>,
    pub content_language: Option<String>,
}
/// A modified version of some code from one of my projects to show an example
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize)]
#[sea_orm(table_name = "paste_file")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: i64,
    pub post_id: i64,
    pub file_name: String,
    pub file_type: FileType,
    pub content: String,
    #[sea_orm(default_expr = "Expr::current_timestamp()")]
    pub created: DateTimeWithTimeZone,
}
Traits That need to be implemeneted
  • FromValue

  • TryGetable

Other Changes

sea_orm::Value will also need a new Row type I think

This will also need any code needed to generate the Postgres Statement to make the type.

Documentation

We will also need to provide documenation on building composite types.

Current Workarounds

Using Json or using a seperate table.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining the Postgres integration and the existing PostgresCompositeType, FromValue, TryGetable, and sea_orm::Value entry points named in the issue; no specific files or tests are provided. Done would require agreed support for composite types, including type creation and documentation, but the proposed scope still needs design decisions.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, rust
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.