Ruster is a library using ffi for database management with psql/pg_dump + mysql/mysqldump written in Rust.
The generated C static and shared libraries can be reused in other languages (Golang for example).
The build of project produces 2 go binaries, 1 static library (libruster.a) and 1 shared library (libruster.so).
The headers of C functions are in lib/ruster.h and must be present before code generation.
bash
make build-shared
bash
make build-static
```go /*
*/ import "C"
import ( "os" )
func main() { os.Getenv("PGPASSWORD") err := func() error { C.pgdumpdatabase( C.CString("localhost"), C.CString("5432"), C.CString("postgres"), C.CString("postgres"), C.CString("pgdump.sql"), C.CString("true"), ); return nil } if err() == nil { func() { C.psqlrestoredatabase( C.CString("localhost"), C.CString("5432"), C.CString("postgres"), C.CString("postgres"), C.CString("pgdump.sql"), C.CString("true"), ); }() } } ```
```go /*
*/ import "C"
import ( "os" )
func main() { os.Getenv("MYSQLPWD") err := func() error { C.mysqldumpdatabase( C.CString("localhost"), C.CString("3306"), C.CString("root"), C.CString("mysql"), C.CString("dump.sql"), C.CString("true"), ); return nil } time.Sleep(time.Duration(250)*time.Millisecond) if err() == nil { func() { C.mysqlrestoredatabase( C.CString("localhost"), C.CString("3306"), C.CString("root"), C.CString("mysql"), C.CString("dump.sql"), C.CString("true"), ); }() } } ```
bash
make run-shared
bash
make run-static
bash
./time main_shared
./time main_static
bash
./time test-rust-lib