Skip to content

Commit 40a183d

Browse files
committed
feat: prepare publish
1 parent 83530fa commit 40a183d

4 files changed

Lines changed: 132 additions & 0 deletions

File tree

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ name = "sqlx-gen"
33
version = "0.1.0"
44
edition = "2021"
55
description = "Generate Rust structs from database schema introspection"
6+
license = "MIT"
7+
repository = "https://github.com/LeadcodeDev/sqlx-gen"
8+
readme = "README.md"
9+
keywords = ["sqlx", "codegen", "postgres", "mysql", "sqlite"]
10+
categories = ["database", "development-tools"]
611

712
[dependencies]
813
sqlx = { version = "0.8", features = [

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 LeadcodeDev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# sqlx-gen
2+
3+
Generate Rust structs from your database schema — with correct types, derives, and `sqlx::FromRow` annotations.
4+
5+
Supports **PostgreSQL**, **MySQL**, and **SQLite**. Introspects tables, enums, composite types, and domains.
6+
7+
[![Crates.io](https://img.shields.io/crates/v/sqlx-gen.svg)](https://crates.io/crates/sqlx-gen)
8+
[![docs.rs](https://docs.rs/sqlx-gen/badge.svg)](https://docs.rs/sqlx-gen)
9+
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
10+
11+
## Features
12+
13+
- Multi-database: PostgreSQL, MySQL, SQLite
14+
- Multi-schema support (PostgreSQL)
15+
- Generates `#[derive(sqlx::FromRow)]` structs
16+
- PostgreSQL enums → `#[derive(sqlx::Type)]` enums
17+
- PostgreSQL composite types and domains
18+
- MySQL inline ENUM detection
19+
- Correct nullable handling (`Option<T>`)
20+
- Custom derives (`--derives Serialize,Deserialize`)
21+
- Type overrides (`--type-overrides jsonb=MyType`)
22+
- Table filtering (`--tables users,orders`)
23+
- Single-file or multi-file output
24+
- Dry-run mode (preview on stdout)
25+
26+
## Installation
27+
28+
```sh
29+
cargo install sqlx-gen
30+
```
31+
32+
## Usage
33+
34+
### PostgreSQL (multi-schema)
35+
```sh
36+
sqlx-gen -u postgres://user:pass@localhost/mydb -s public,auth -o src/models
37+
```
38+
39+
### MySQL
40+
```sh
41+
sqlx-gen -u mysql://user:pass@localhost/mydb -o src/models
42+
```
43+
44+
### SQLite
45+
```sh
46+
sqlx-gen -u sqlite:./local.db -o src/models
47+
```
48+
49+
### With extra derives
50+
```sh
51+
sqlx-gen -u postgres://... --derives Serialize,Deserialize -o src/models
52+
```
53+
54+
### Dry run (preview without writing)
55+
```sh
56+
sqlx-gen -u postgres://... --dry-run
57+
```
58+
59+
## CLI Options
60+
61+
| Flag | Short | Description | Default |
62+
|------|-------|-------------|---------|
63+
| `--database-url` | `-u` | Database connection URL (or `DATABASE_URL` env) | required |
64+
| `--output-dir` | `-o` | Output directory | `src/models` |
65+
| `--schemas` | `-s` | Schemas to introspect (comma-separated) | `public` |
66+
| `--derives` | | Additional derive macros (comma-separated) | none |
67+
| `--type-overrides` | | Type overrides `sql_type=RustType` (comma-separated) | none |
68+
| `--tables` | | Only generate these tables (comma-separated) | all |
69+
| `--single-file` | | Write everything to a single `models.rs` | false |
70+
| `--dry-run` | | Print to stdout, don't write files | false |
71+
72+
## Example Output
73+
74+
```rust
75+
// Auto-generated by sqlx-gen. Do not edit.
76+
// Table: public.users
77+
78+
use chrono::{DateTime, Utc};
79+
use uuid::Uuid;
80+
81+
#[derive(Debug, Clone, sqlx::FromRow)]
82+
pub struct Users {
83+
pub id: Uuid,
84+
pub email: String,
85+
pub name: Option<String>,
86+
pub created_at: DateTime<Utc>,
87+
}
88+
```
89+
90+
Enums:
91+
```rust
92+
#[derive(Debug, Clone, PartialEq, sqlx::Type)]
93+
#[sqlx(type_name = "status")]
94+
pub enum Status {
95+
#[sqlx(rename = "active")]
96+
Active,
97+
98+
#[sqlx(rename = "inactive")]
99+
Inactive,
100+
}
101+
```
102+
103+
## License
104+
105+
MIT

src/introspect/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod postgres;
33
pub mod sqlite;
44

55
#[derive(Debug, Clone)]
6+
#[allow(unused)]
67
pub struct ColumnInfo {
78
pub name: String,
89
/// High-level data type (e.g. "integer", "character varying")

0 commit comments

Comments
 (0)