Skip to content

Commit

Permalink
add pg ci
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Sep 27, 2023
1 parent 2b8d8d8 commit 668a868
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 5 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ jobs:
sqlness-cli:
runs-on: ubuntu-latest
timeout-minutes: 60
# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
strategy:
matrix:
rust: [stable]
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ clippy:
cd $(DIR); cargo clippy --all-targets --all-features --workspace -- -D warnings

cli-test:
cd $(DIR)/sqlness-cli; cargo run -- -c tests -i 127.0.0.1 -p 3306 -u root -P 1a2b3c -d public
cd $(DIR)/sqlness-cli; cargo run -- -c tests/mysql -i 127.0.0.1 -p 3306 -u root -P 1a2b3c -d public
cd $(DIR)/sqlness-cli; cargo run -- -c tests/postgresql -i localhost -p 5432 -u postgres -P postgres -d postgres

example: good-example bad-example

Expand Down
File renamed without changes.
File renamed without changes.
38 changes: 38 additions & 0 deletions sqlness-cli/tests/postgresql/local/input.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
DROP TABLE if exists categories;

(Empty response)

CREATE TABLE categories (
category_id SERIAL NOT NULL PRIMARY KEY,
category_name VARCHAR(255),
description VARCHAR(255)
);

(Empty response)

INSERT INTO categories (category_name, description)
VALUES
('Beverages', 'Soft drinks, coffees, teas, beers, and ales'),
('Condiments', 'Sweet and savory sauces, relishes, spreads, and seasonings'),
('Confections', 'Desserts, candies, and sweet breads'),
('Dairy Products', 'Cheeses'),
('Grains/Cereals', 'Breads, crackers, pasta, and cereal'),
('Meat/Poultry', 'Prepared meats'),
('Produce', 'Dried fruit and bean curd'),
('Seafood', 'Seaweed and fish');

(Empty response)

select * from categories;

category_id,category_name,description,
Row { columns: [Column { name: "category_id", type: Int4 }, Column { name: "category_name", type: Varchar }, Column { name: "description", type: Varchar }] }
Row { columns: [Column { name: "category_id", type: Int4 }, Column { name: "category_name", type: Varchar }, Column { name: "description", type: Varchar }] }
Row { columns: [Column { name: "category_id", type: Int4 }, Column { name: "category_name", type: Varchar }, Column { name: "description", type: Varchar }] }
Row { columns: [Column { name: "category_id", type: Int4 }, Column { name: "category_name", type: Varchar }, Column { name: "description", type: Varchar }] }
Row { columns: [Column { name: "category_id", type: Int4 }, Column { name: "category_name", type: Varchar }, Column { name: "description", type: Varchar }] }
Row { columns: [Column { name: "category_id", type: Int4 }, Column { name: "category_name", type: Varchar }, Column { name: "description", type: Varchar }] }
Row { columns: [Column { name: "category_id", type: Int4 }, Column { name: "category_name", type: Varchar }, Column { name: "description", type: Varchar }] }
Row { columns: [Column { name: "category_id", type: Int4 }, Column { name: "category_name", type: Varchar }, Column { name: "description", type: Varchar }] }


22 changes: 22 additions & 0 deletions sqlness-cli/tests/postgresql/local/input.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

DROP TABLE if exists categories;

CREATE TABLE categories (
category_id SERIAL NOT NULL PRIMARY KEY,
category_name VARCHAR(255),
description VARCHAR(255)
);

INSERT INTO categories (category_name, description)
VALUES
('Beverages', 'Soft drinks, coffees, teas, beers, and ales'),
('Condiments', 'Sweet and savory sauces, relishes, spreads, and seasonings'),
('Confections', 'Desserts, candies, and sweet breads'),
('Dairy Products', 'Cheeses'),
('Grains/Cereals', 'Breads, crackers, pasta, and cereal'),
('Meat/Poultry', 'Prepared meats'),
('Produce', 'Dried fruit and bean curd'),
('Seafood', 'Seaweed and fish');


select * from categories;
9 changes: 5 additions & 4 deletions sqlness/src/database_impl/postgresql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ struct PostgresqlFormatter {

impl Display for PostgresqlFormatter {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.rows.is_empty() {
return f.write_fmt(format_args!("(Empty response)"));
}

let top = &self.rows[0];
let columns = top
.columns()
Expand All @@ -74,10 +78,7 @@ impl Display for PostgresqlFormatter {
f.write_str("\n")?;

for row in &self.rows {
for column in &columns {
f.write_fmt(format_args!("{:?},", row.get::<&str, &str>(column)))?;
}
f.write_str("\n")?;
f.write_fmt(format_args!("{:?}\n", row))?;
}

Ok(())
Expand Down

0 comments on commit 668a868

Please sign in to comment.