-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
497 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
POSTGRES_USER=naphtha | ||
POSTGRES_PASSWORD=naphtha | ||
POSTGRES_DB=naphtha |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
[package] | ||
name = "naphtha-proc-macro" | ||
version = "0.4.1" | ||
version = "0.5.0" | ||
authors = ["Lewin Probst <[email protected]>"] | ||
edition = "2018" | ||
edition = "2021" | ||
license = "MIT OR Apache-2.0" | ||
description = "Supporting macro crate for naphtha" | ||
homepage = "https://github.com/emirror-de/naphtha" | ||
|
@@ -17,14 +17,16 @@ proc-macro = true | |
|
||
[features] | ||
default = [] | ||
full = ["sqlite", "mysql", "barrel-full"] | ||
barrel-full = ["barrel-sqlite", "barrel-mysql"] | ||
full = ["sqlite", "mysql", "pg", "barrel-full"] | ||
barrel-full = ["barrel-sqlite", "barrel-mysql", "barrel-pg"] | ||
sqlite = [] | ||
mysql = [] | ||
pg = [] | ||
barrel-sqlite = [] | ||
barrel-mysql = [] | ||
barrel-pg = [] | ||
|
||
[dependencies] | ||
syn = { version = "^1.0.74", features = ["parsing"] } | ||
proc-macro2 = "^1.0.28" | ||
quote = "^1.0.9" | ||
syn = { version = "1.0.86", features = ["parsing"] } | ||
proc-macro2 = "1.0.36" | ||
quote = "1.0.15" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#[cfg(feature = "barrel-mysql")] | ||
pub(crate) mod mysql; | ||
#[cfg(feature = "barrel-pg")] | ||
pub(crate) mod pg; | ||
#[cfg(feature = "barrel-sqlite")] | ||
pub(crate) mod sqlite; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use {quote::quote, syn::DeriveInput}; | ||
|
||
pub(crate) fn impl_pg(ast: &DeriveInput) -> ::proc_macro2::TokenStream { | ||
let name = &ast.ident; | ||
|
||
quote! { | ||
impl ::naphtha::barrel::DatabaseSqlMigrationExecutor<::naphtha::diesel::PgConnection, usize> for #name | ||
where | ||
Self: ::naphtha::barrel::DatabaseSqlMigration, | ||
{ | ||
fn execute_migration_up(conn: &::naphtha::DatabaseConnection<::naphtha::diesel::PgConnection>) -> Result<usize, String> { | ||
use { | ||
::naphtha::{barrel::Migration, DatabaseConnection, log::error, diesel::RunQueryDsl}, | ||
}; | ||
let mut m = Migration::new(); | ||
Self::migration_up(&mut m); | ||
let m = m.make::<::naphtha::barrel::backend::Pg>(); | ||
|
||
let c = match conn.lock() { | ||
Ok(c) => c, | ||
Err(msg) => { | ||
error!("Could not aquire lock on DatabaseSqlMigrationExecutor::execute_migration_up: {}", msg.to_string()); | ||
return Err(msg.to_string()); | ||
} | ||
}; | ||
|
||
match ::naphtha::diesel::sql_query(m).execute(&*c) { | ||
Ok(u) => Ok(u), | ||
Err(msg) => Err(msg.to_string()), | ||
} | ||
} | ||
|
||
fn execute_migration_down(conn: &::naphtha::DatabaseConnection<::naphtha::diesel::PgConnection>) -> Result<usize, String> { | ||
use { | ||
::naphtha::{barrel::Migration, DatabaseConnection, log::error, diesel::RunQueryDsl}, | ||
}; | ||
let mut m = Migration::new(); | ||
Self::migration_down(&mut m); | ||
let m = m.make::<::naphtha::barrel::backend::Pg>(); | ||
|
||
let c = match conn.lock() { | ||
Ok(c) => c, | ||
Err(msg) => { | ||
error!("Could not aquire lock on DatabaseSqlMigrationExecutor::execute_migration_down for model: {}", msg.to_string()); | ||
return Err(msg.to_string()); | ||
} | ||
}; | ||
|
||
match ::naphtha::diesel::sql_query(m).execute(&*c) { | ||
Ok(u) => Ok(u), | ||
Err(msg) => Err(msg.to_string()), | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
#[cfg(feature = "mysql")] | ||
pub(crate) mod mysql; | ||
#[cfg(feature = "pg")] | ||
pub(crate) mod pg; | ||
#[cfg(feature = "sqlite")] | ||
pub(crate) mod sqlite; |
Oops, something went wrong.