{"id":13636959,"url":"https://github.com/SeaQL/sea-schema","last_synced_at":"2025-04-19T08:33:36.193Z","repository":{"id":37136823,"uuid":"347671583","full_name":"SeaQL/sea-schema","owner":"SeaQL","description":"🌿 SQL schema definition and discovery","archived":false,"fork":false,"pushed_at":"2024-10-25T10:11:42.000Z","size":3899,"stargazers_count":192,"open_issues_count":9,"forks_count":40,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-29T15:26:45.807Z","etag":null,"topics":["database","database-schema","hacktoberfest","mysql","postgresql","rust","sql","sqlite"],"latest_commit_sha":null,"homepage":"https://docs.rs/sea-schema","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SeaQL.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"SeaQL"}},"created_at":"2021-03-14T15:17:43.000Z","updated_at":"2024-10-25T13:18:46.000Z","dependencies_parsed_at":"2024-01-01T04:13:27.457Z","dependency_job_id":"abcac63a-8be0-4c9d-809f-7c15a49740c0","html_url":"https://github.com/SeaQL/sea-schema","commit_stats":{"total_commits":407,"total_committers":19,"mean_commits":21.42105263157895,"dds":0.6167076167076166,"last_synced_commit":"c6aee41b5bb159f626663404ee261f006eb73a9b"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeaQL%2Fsea-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeaQL%2Fsea-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeaQL%2Fsea-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SeaQL%2Fsea-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SeaQL","download_url":"https://codeload.github.com/SeaQL/sea-schema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223055967,"owners_count":17080481,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","database-schema","hacktoberfest","mysql","postgresql","rust","sql","sqlite"],"created_at":"2024-08-02T00:01:08.414Z","updated_at":"2024-11-09T06:31:03.546Z","avatar_url":"https://github.com/SeaQL.png","language":"Rust","readme":"\u003cdiv align=\"center\"\u003e\n\n  \u003cimg src=\"docs/SeaQL logo dual.png\" width=\"320\"/\u003e\n\n  \u003ch1\u003eSeaSchema\u003c/h1\u003e\n\n  \u003cp\u003e\n    \u003cstrong\u003e🌿 SQL schema definition and discovery\u003c/strong\u003e\n  \u003c/p\u003e\n\n  [![crate](https://img.shields.io/crates/v/sea-schema.svg)](https://crates.io/crates/sea-schema)\n  [![docs](https://docs.rs/sea-schema/badge.svg)](https://docs.rs/sea-schema)\n  [![build status](https://github.com/SeaQL/sea-schema/actions/workflows/rust.yml/badge.svg)](https://github.com/SeaQL/sea-schema/actions/workflows/rust.yml)\n\n\u003c/div\u003e\n\n## About\n\nSeaSchema is a library to help you manage database schema for MySQL, Postgres and SQLite. It provides 1) type definitions for representing database schema mapping each database closely and 2) utilities to discover them.\n\n[![GitHub stars](https://img.shields.io/github/stars/SeaQL/sea-schema.svg?style=social\u0026label=Star\u0026maxAge=1)](https://github.com/SeaQL/sea-schema/stargazers/)\nIf you like what we do, consider starring, commenting, sharing and contributing!\n\n[![Discord](https://img.shields.io/discord/873880840487206962?label=Discord)](https://discord.com/invite/uCPdDXzbdv)\nJoin our Discord server to chat with others in the SeaQL community!\n\n## Architecture\n\nThe crate is divided into different modules:\n\n+ `def`: type definitions\n+ `query`, `parser`: for querying and parsing information_schema\n+ `discovery`: connect to a live database and discover a `Schema`\n+ `writer`: for exporting `Schema` into SeaQuery and SQL statements\n\nJSON de/serialize on type definitions can be enabled with `with-serde`.\n\n## Schema Discovery\n\nTake the MySQL [Sakila Sample Database](tests/sakila/mysql/sakila-schema.sql) as example, given the following table:\n\n```SQL\nCREATE TABLE film_actor (\n  actor_id SMALLINT UNSIGNED NOT NULL,\n  film_id SMALLINT UNSIGNED NOT NULL,\n  last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n  PRIMARY KEY  (actor_id,film_id),\n  KEY idx_fk_film_id (`film_id`),\n  CONSTRAINT fk_film_actor_actor FOREIGN KEY (actor_id) REFERENCES actor (actor_id) ON DELETE RESTRICT ON UPDATE CASCADE,\n  CONSTRAINT fk_film_actor_film FOREIGN KEY (film_id) REFERENCES film (film_id) ON DELETE RESTRICT ON UPDATE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;\n\n```\n\nThe [discovered schema result](tests/discovery/mysql/schema.rs):\n\n```rust\nTableDef {\n    info: TableInfo {\n        name: \"film_actor\",\n        engine: InnoDb,\n        auto_increment: None,\n        char_set: Utf8Mb4,\n        collation: Utf8Mb40900AiCi,\n        comment: \"\",\n    },\n    columns: [\n        ColumnInfo {\n            name: \"actor_id\",\n            col_type: SmallInt(\n                NumericAttr {\n                    maximum: None,\n                    decimal: None,\n                    unsigned: Some(true),\n                    zero_fill: None,\n                },\n            ),\n            null: false,\n            key: Primary,\n            default: None,\n            extra: ColumnExtra {\n                auto_increment: false,\n                on_update_current_timestamp: false,\n                generated: false,\n                default_generated: false,\n            },\n            expression: None,\n            comment: \"\",\n        },\n        ColumnInfo {\n            name: \"film_id\",\n            col_type: SmallInt(\n                NumericAttr {\n                    maximum: None,\n                    decimal: None,\n                    unsigned: Some(true),\n                    zero_fill: None,\n                },\n            ),\n            null: false,\n            key: Primary,\n            default: None,\n            extra: ColumnExtra {\n                auto_increment: false,\n                on_update_current_timestamp: false,\n                generated: false,\n                default_generated: false,\n            },\n            expression: None,\n            comment: \"\",\n        },\n        ColumnInfo {\n            name: \"last_update\",\n            col_type: Timestamp(TimeAttr { fractional: None }),\n            null: false,\n            key: NotKey,\n            default: Some(ColumnDefault::CurrentTimestamp),\n            extra: ColumnExtra {\n                auto_increment: false,\n                on_update_current_timestamp: true,\n                generated: false,\n                default_generated: true,\n            },\n            expression: None,\n            comment: \"\",\n        },\n    ],\n    indexes: [\n        IndexInfo {\n            unique: false,\n            name: \"idx_fk_film_id\",\n            parts: [\n                IndexPart {\n                    column: \"film_id\",\n                    order: Ascending,\n                    sub_part: None,\n                },\n            ],\n            nullable: false,\n            idx_type: BTree,\n            comment: \"\",\n            functional: false,\n        },\n        IndexInfo {\n            unique: true,\n            name: \"PRIMARY\",\n            parts: [\n                IndexPart {\n                    column: \"actor_id\",\n                    order: Ascending,\n                    sub_part: None,\n                },\n                IndexPart {\n                    column: \"film_id\",\n                    order: Ascending,\n                    sub_part: None,\n                },\n            ],\n            nullable: false,\n            idx_type: BTree,\n            comment: \"\",\n            functional: false,\n        },\n    ],\n    foreign_keys: [\n        ForeignKeyInfo {\n            name: \"fk_film_actor_actor\",\n            columns: [ \"actor_id\" ],\n            referenced_table: \"actor\",\n            referenced_columns: [ \"actor_id\" ],\n            on_update: Cascade,\n            on_delete: Restrict,\n        },\n        ForeignKeyInfo {\n            name: \"fk_film_actor_film\",\n            columns: [ \"film_id\" ],\n            referenced_table: \"film\",\n            referenced_columns: [ \"film_id\" ],\n            on_update: Cascade,\n            on_delete: Restrict,\n        },\n    ],\n}\n```\n\n## License\n\nLicensed under either of\n\n-   Apache License, Version 2.0\n    ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n-   MIT license\n    ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n\nSeaSchema is a community driven project. We welcome you to participate, contribute and together build for Rust's future.\n\nA big shout out to our contributors:\n\n[![Contributors](https://opencollective.com/sea-schema/contributors.svg?width=1000\u0026button=false)](https://github.com/SeaQL/sea-schema/graphs/contributors)\n","funding_links":["https://github.com/sponsors/SeaQL"],"categories":["库 Libraries","Libraries","Database libraries","Rust","sqlite"],"sub_categories":["数据库 Database","Database"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSeaQL%2Fsea-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSeaQL%2Fsea-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSeaQL%2Fsea-schema/lists"}