PgRoutiner 는 PostgreSQL 데이터베이스 및 PostgreSQL .NET 프로젝트를위한 명령 줄 도구 세트입니다.
.NET 구성 프로젝트 연결 문자열 (또는 사용자 정의 정의 된 연결) 사용 - 할 수 있습니다.
데이터베이스를 쉽게 탐색하고 검색하십시오.
C# 및 TS 모델 및 코드를 생성하십시오.
데이터베이스 스크립트를 생성하고 도구를 실행하십시오.
마크 다운 문서를 생성합니다.
CRUD 명령 함수를 생성합니다.
프레젠테이션 슬라이드를 참조하십시오
Pgroutiner 블로그를 참조하십시오
Pgroutiner 개념 블로그를 참조하십시오
Pgroutiner 데이터베이스 관리 블로그를 참조하십시오
pgroutiner 코드-그린 블로그를 참조하십시오
Pgroutiner 문서 블로그를 참조하십시오
참고 :이 readme의 모든 예와 위의 프레젠테이션에서 [PostgreSQL 자습서]의 PostgreSQL 샘플 데이터베이스를 사용합니다.
빠른 시작 :
- 릴리스 페이지의 최신 버전에 대한 기본 실행 파일 (프레임 워크에 의존하지 않음)을 다운로드하십시오.
- 다운로드 된 실행 파일로 적절한 경로를 설정하십시오.
pgroutiner --info- 참고 : 원주민 실행 파일로 작업하는 것이 여러 번 더 빠르며 시작 시간이 매우 짧으며 여러 번 더 나은 사용자 경험을 제공합니다.
목차 :
이것은 Pgroutiner 도구를 시작하는 가장 빠르고 쉬운 방법입니다. 릴리스 페이지에는 아무것도 의존하지 않는 다운로드 가능한 실행 파일이 포함되어 있습니다. 프레임 워크 나 도커가 필요하지 않으며 평범한 오래된 원주민 실행 가능.
이것은 실제로 Pgroutiner 도구를 사용하는 것이 바람직한 방법입니다. 기본 실행 파일은 매우 최적화되어 있으며 시작 시간이 매우 짧으며 더 나은 사용자 경험을 제공합니다.
다음은 다음과 같습니다.
pgroutiner --info .그게 다야.
글로벌 도구를 설치하려면 (권장) :
$ dotnet tool install --global dotnet-pgroutiner
Tool 'dotnet-pgroutiner' (version '5.4.0') was successfully installed.글로벌 도구를 업데이트하려면 :
$ dotnet tool update --global dotnet-pgroutiner
Tool 'dotnet-pgroutiner' was successfully updated from version '5.0.7' to version '5.0.8'. 이를 통해 글로벌 명령 줄 도구 pgroutiner 가능합니다. pgroutiner --help 입력하십시오.
프로젝트에 로컬 도구를 추가하려면이 튜토리얼에 설명 된대로 --global 스위치없이 매니페스트 파일을 만들고 도구를 추가해야합니다.
TL-DR :
프로젝트 또는 솔루션에 .config 디렉토리를 추가하십시오.
다음 내용이있는이 디렉토리에 dotnet-tools.json 파일을 추가하십시오.
{
"version" : 1 ,
"isRoot" : true ,
"tools" : {
"dotnet-pgroutiner" : {
"version" : " 5.0.6 " ,
"commands" : [
" pgroutiner "
]
}
}
} 명령 줄에서 dotnet tool restore
dotnet tool run pgroutiner [arguments] 로 도구 실행, 예를 들어 dotnet tool run pgroutiner --help
pgroutiner 설치 (위의 지침 참조)pgroutiner --help 입력하여 사용 가능한 명령과 스위치를 볼 수 있습니다 (목록은 길다).pgroutiner 입력하여 연결이없는 경우 새 연결을 정의 하고이 DIR의 기본 구성 파일을 작성하십시오. 연결 관리에 대해 자세히 알아보십시오pgroutiner --info 데이터베이스에 연결할 수 있는지 확인하고 다른 환경 정보를 볼 수 있는지 확인하십시오.pgroutiner --list 모든 객체의 목록을보십시오.pgroutiner --ddl [object_name] 입력하여 두 번째 매개 변수의 객체에 대한 데이터 정의 언어를 볼 수 있습니다.pgroutiner --search [search expression] 입력하십시오. pgroutiner .NET 프로젝트 루트 에서 실행되도록 설계되었으며 표준 구성 JSON 파일 ( appsettings.Development.json 및 appsettings.json )에서 사용 가능한 모든 연결을 읽습니다.
ConnectionStrings 섹션에서 사용 가능한 첫 번째 연결 문자열을 사용합니다.
AppSettings.json
{
"ConnectionStrings" : {
"DvdRental" : " Server=localhost;Db=dvdrental;Port=5432;User Id=postgres;Password=postgres; "
}
} 참고 : 이것은 NPGSQL 연결 문자열 형식이지만 표준 PostgreSQL URL Connection 형식 postgresql://{user}:{password}@{server}:{port}/{database} 사용할 수도 있습니다.
간단한 정보 명령 실행 환경을보기 위해 연결을 테스트하기위한 실행 :
~$ pgroutiner --info
Version:
5.0.3.0
Executable dir:
/home/vbilopav/.dotnet/tools
OS:
Unix 5.10.102.1
Using configuration files:
appsettings.Development.json
appsettings.json
Using dir:
/home/vbilopav/dev/dvdrental
Using settings:
--info
Using connection DvdRental:
Host=localhost;Database=dvdrental;Port=5432;Username=postgres (PostgreSQL 13.8)
Using project file:
dvdrental.csproj
pg_dump:
pg_dump
pg_restore:
/usr/lib/postgresql/13/bin/pg_restore ~$ pgroutiner
Connection server [localhost]:
Connection port [5432]:
Connection database [postgres]:
Connection user [postgres]:
Connection password [environment var.]:-c 또는 --connection 매개 변수를 사용하십시오. ~$ pgroutiner -c ConnectionString2 --info ~$ pgroutiner --connection ConnectionString2 --info Connection server [localhost]:
Connection port [5432]:
Connection database [postgres]:
Connection user [postgres]:
Connection password: Connection Server, Port, Database 및 사용자는 기본값 ( localhost , 5432 , postgres , postgres )을 사전 정의했습니다.
명령 줄은 연결 이름 대신 -c 또는 --connection 사용하여 전체 연결 문자열을 사용할 수 있습니다.
~$ pgroutiner --connection "Server=localhost;Db=test;Port=5432;User Id=postgres;Password=postgres;" --infopostgresql://{user}:{password}@{server}:{port}/{database} NPGSQL Connection : 대신 활용할 수 있습니다. {
"ConnectionStrings" : {
"TestConnection" : " postgresql://postgres:postgres@localhost:5432/test "
}
} ~$ pgroutiner --connection "postgresql://postgres:postgres@localhost:5432/test" --info연결 문자열 또는 연결 URL에서 연결의 모든 부분 (서버, 포트, 데이터베이스, 사용자 및 비밀번호)을 생략 할 수 있으며 다음 환경 변수로 대체됩니다.
누락 된 서버 매개 변수를 교체하려면 PGHOST 또는 PGSERVER .
누락 된 포트 매개 변수를 교체하는 PGPORT .
누락 된 데이터베이스 매개 변수를 대체하려면 PGDATABASE 또는 PGDB .
누락 된 서버 매개 변수를 교체하려면 PGHOST 또는 PGSERVER .
누락 된 사용자 매개 변수를 교체하는 PGUSER .
누락 된 비밀번호 매개 변수를 대체하려면 PGPASSWORD 또는 PGPASS .
가능한 모든 명령 줄 옵션 및 스위치는 구성 파일에서 구성 할 수 있습니다.
JSON 구성 ( appsettings.json 또는 appsettings.Development.json )에서 PgRoutiner 구성 섹션을 사용하십시오.
{
"ConnectionStrings" : {
"TestConnection" : " postgresql://postgres:postgres@localhost:5432/test "
},
"PgRoutiner" : {
// pgroutiner settings
}
} pgroutiner 구성 섹션 PgRoutiner 존재하는 경우 구성 설정을 기본값으로 읽고 적용합니다.
명령 줄을 사용하여 구성 설정을 무시하십시오.
일반적으로, 모든 구성 설정은 두 개의 대시로 시작하는 케밥 케이스 Sitch와 명령 줄에 해당됩니다. 예 :
SkipConnectionPrompt , 명령 줄 : --skip-connection-promptSchemaSimilarTo , 명령 줄 : --schema-similar-to 예를 들어, 많은 설정에는 단축 컷 별칭이 있습니다. 예를 들어 Connection 설정은 -c -conn --conn -connection --connection 될 수 있습니다.
부울 설정은 스위치이며, 값을 켤 수없는 스위치 pgroutiner --skip-connection-prompt 포함시키기에 충분합니다.
false 또는 0 을 추가하여 끄기 : pgroutiner --skip-connection-prompt false
--settings 스위치로 현재 적용된 설정을 검사 할 수 있습니다. pgroutiner --settings 모든 작업을 건너 뛰도록 강요하며 모든 현재 설정 만 표시됩니다. 또한 주석 헤더에 명령 줄 별칭이 표시됩니다.
또한 기본값과 다른 현재 적용된 설정을 표시하는 pgroutiner --info 실행할 수도 있습니다.
구성 섹션이없는 경우 PgRoutiner 어디에나 존재하고 매개 변수가없는 pgroutiner 실행하면 기본 구성 파일 appsettings.PgRoutiner.json 작성하도록 제공됩니다.
You don't seem to be using any available command-line commands and PgRoutiner configuration seems to be missing.
Would you like to create a custom settings file "appsettings.PgRoutiner.json" with your current values?
This settings configuration file can be used to change settings for this directory without using a command-line.
Create "appsettings.PgRoutiner.json" in this dir [Y/N]? appsettings.PgRoutiner.json 존재하는 경우 appsettings.json 및 appsettings.Development.json 후에 항상로드되고 해당 파일의 가능한 설정 값을 재정의합니다.
다른 위치에서 이러한 구성 파일을로드 해야하는 경우 --config-path, for example, pgroutiner-- -config-path ../../dir2/ 사용할 수 있습니다.
이러한 옵션을 사용하여 사용자 정의 구성 파일을로드 할 수 있습니다. -cf , --cf , -config , --config , -config-file , --config-file , 예를 들어 pgroutiner --config ../../dir2/my-config.json
또한 이러한 옵션 -wcf , --write-config-file (예 : pgroutiner --write-config-file ../../dir2/my-config.json 을 사용하여 사용자 정의 구성에 현재 설정을 작성할 수도 있습니다.
이 현재 버전의 모든 기본값이있는 전체 구성 파일
설명 : -l -ls --ls --list to dump or search object list to console. Use the switch to dump all objects or parameter values to search.
예 :
vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ pgroutiner --list
SCHEMA public
EXTENSION plpgsql
TYPE mpaa_rating
DOMAIN public.year
TABLE public.actor
VIEW public.actor_info
VIEW public.customer_list
... vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ pgroutiner -l
SCHEMA public
EXTENSION plpgsql
TYPE mpaa_rating
DOMAIN public.year
TABLE public.actor
VIEW public.actor_info
VIEW public.customer_list
... vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ pgroutiner -ls
SCHEMA public
EXTENSION plpgsql
TYPE mpaa_rating
DOMAIN public.year
TABLE public.actor
VIEW public.actor_info
VIEW public.customer_list
... vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ pgroutiner --list film
VIEW public.film_list
VIEW public.nicer_but_slower_film_list
VIEW public.sales_by_film_category
TABLE public.film_actor
TABLE public.film_category
TABLE public.film
SEQ public.film_film_id_seq
FUNCTION public.film_in_stock(integer, integer)
FUNCTION public.film_not_in_stock(integer, integer)
vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ pgroutiner --list actor
TABLE public.actor
VIEW public.actor_info
TABLE public.film_actor
SEQ public.actor_actor_id_seq
vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ 설명 : -def -ddl --ddl -definition --definition to dump object schema definition in console supplied as a value parameter.
예 :
vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ pgroutiner -ddl actor
--
-- Table: public.actor
--
CREATE TABLE public.actor (
actor_id integer DEFAULT nextval('public.actor_actor_id_seq'::regclass) NOT NULL PRIMARY KEY,
first_name character varying(45) NOT NULL,
last_name character varying(45) NOT NULL,
last_update timestamp without time zone DEFAULT now() NOT NULL
);
ALTER TABLE public.actor OWNER TO postgres;
CREATE INDEX idx_actor_last_name ON public.actor USING btree (last_name);
CREATE TRIGGER last_updated BEFORE UPDATE ON public.actor FOR EACH ROW EXECUTE FUNCTION public.last_updated();
vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ pgroutiner -ddl film
--
-- Table: public.film
--
CREATE TABLE public.film (
film_id integer DEFAULT nextval('public.film_film_id_seq'::regclass) NOT NULL PRIMARY KEY,
title character varying(255) NOT NULL,
description text,
release_year public.year,
language_id smallint NOT NULL,
rental_duration smallint DEFAULT 3 NOT NULL,
rental_rate numeric(4,2) DEFAULT 4.99 NOT NULL,
length smallint,
replacement_cost numeric(5,2) DEFAULT 19.99 NOT NULL,
rating public.mpaa_rating DEFAULT 'G'::public.mpaa_rating,
last_update timestamp without time zone DEFAULT now() NOT NULL,
special_features text[],
fulltext tsvector NOT NULL,
FOREIGN KEY (language_id) REFERENCES public.language(language_id) ON UPDATE CASCADE ON DELETE RESTRICT
);
ALTER TABLE public.film OWNER TO postgres;
CREATE INDEX film_fulltext_idx ON public.film USING gist (fulltext);
CREATE INDEX idx_fk_language_id ON public.film USING btree (language_id);
CREATE INDEX idx_title ON public.film USING btree (title);
CREATE TRIGGER film_fulltext_trigger BEFORE INSERT OR UPDATE ON public.film FOR EACH ROW EXECUTE FUNCTION tsvector_update_trigger('fulltext', 'pg_catalog.english', 'title', 'description');
CREATE TRIGGER last_updated BEFORE UPDATE ON public.film FOR EACH ROW EXECUTE FUNCTION public.last_updated();
vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ pgroutiner --ddl film_in_stock
--
-- Function: public.film_in_stock
--
CREATE FUNCTION public.film_in_stock(
p_film_id integer,
p_store_id integer,
OUT p_film_count integer
)
RETURNS SETOF integer
LANGUAGE sql
AS $_$
SELECT inventory_id
FROM inventory
WHERE film_id = $1
AND store_id = $2
AND inventory_in_stock(inventory_id);
$_$;
ALTER FUNCTION public.film_in_stock(p_film_id integer, p_store_id integer, OUT p_film_count integer) OWNER TO postgres;
vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ pgroutiner --ddl " actor;film_in_stock "
--
-- Table: public.actor
--
CREATE TABLE public.actor (
actor_id integer DEFAULT nextval('public.actor_actor_id_seq'::regclass) NOT NULL PRIMARY KEY,
first_name character varying(45) NOT NULL,
last_name character varying(45) NOT NULL,
last_update timestamp without time zone DEFAULT now() NOT NULL
);
ALTER TABLE public.actor OWNER TO postgres;
CREATE INDEX idx_actor_last_name ON public.actor USING btree (last_name);
CREATE TRIGGER last_updated BEFORE UPDATE ON public.actor FOR EACH ROW EXECUTE FUNCTION public.last_updated();
--
-- Function: public.film_in_stock
--
CREATE FUNCTION public.film_in_stock(
p_film_id integer,
p_store_id integer,
OUT p_film_count integer
)
RETURNS SETOF integer
LANGUAGE sql
AS $_$
SELECT inventory_id
FROM inventory
WHERE film_id = $1
AND store_id = $2
AND inventory_in_stock(inventory_id);
$_$;
ALTER FUNCTION public.film_in_stock(p_film_id integer, p_store_id integer, OUT p_film_count integer) OWNER TO postgres;
vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ 설명 : s --s --search to search object schema definitions and dump highlighted results to the console.
표현식이 포함 된 전체 정의 및 덤프를 검색합니다.
참고 : 검색 표현식 일치가 강조 표시됩니다.
vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ pgroutiner --search " select public.group_concat "
--
-- View: public.actor_info
--
CREATE VIEW public.actor_info AS
SELECT a.actor_id,
a.first_name,
a.last_name,
public.group_concat(DISTINCT (((c.name)::text || ': '::text) || ( SELECT public.group_concat((f.title)::text) AS group_concat
FROM ((public.film f
JOIN public.film_category fc_1 ON ((f.film_id = fc_1.film_id)))
JOIN public.film_actor fa_1 ON ((f.film_id = fa_1.film_id)))
WHERE ((fc_1.category_id = c.category_id) AND (fa_1.actor_id = a.actor_id))
GROUP BY fa_1.actor_id))) AS film_info
FROM (((public.actor a
LEFT JOIN public.film_actor fa ON ((a.actor_id = fa.actor_id)))
LEFT JOIN public.film_category fc ON ((fa.film_id = fc.film_id)))
LEFT JOIN public.category c ON ((fc.category_id = c.category_id)))
GROUP BY a.actor_id, a.first_name, a.last_name;
ALTER TABLE public.actor_info OWNER TO postgres;
vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ vbilopav@DESKTOP-O3A6QK2:~/dev/dvdrental $ pgroutiner --search smallint
--
-- Table: public.store
--
CREATE TABLE public.store (
store_id integer DEFAULT nextval('public.store_store_id_seq'::regclass) NOT NULL PRIMARY KEY,
manager_staff_id smallint NOT NULL,
address_id smallint NOT NULL,
last_update timestamp without time zone DEFAULT now() NOT NULL,
FOREIGN KEY (address_id) REFERENCES public.address(address_id) ON UPDATE CASCADE ON DELETE RESTRICT,
FOREIGN KEY (manager_staff_id) REFERENCES public.staff(staff_id) ON UPDATE CASCADE ON DELETE RESTRICT
);
ALTER TABLE public.store OWNER TO postgres;
CREATE UNIQUE INDEX idx_unq_manager_staff_id ON public.store USING btree (manager_staff_id);
CREATE TRIGGER last_updated BEFORE UPDATE ON public.store FOR EACH ROW EXECUTE FUNCTION public.last_updated();
--
-- Table: public.address
--
CREATE TABLE public.address (
address_id integer DEFAULT nextval('public.address_address_id_seq'::regclass) NOT NULL PRIMARY KEY,
address character varying(50) NOT NULL,
address2 character varying(50),
district character varying(20) NOT NULL,
city_id smallint NOT NULL,
postal_code character varying(10),
phone character varying(20) NOT NULL,
last_update timestamp without time zone DEFAULT now() NOT NULL,
CONSTRAINT fk_address_city FOREIGN KEY (city_id) REFERENCES public.city(city_id)
);
... 명령에 따라이 도구는 psql , pg_dump 또는 pg_restore 와 같은 PostgreSQL 클라이언트 도구를 사용하여 외부 프로세스를 시작합니다.
즉, PostgreSQL 클라이언트 도구는 시스템에 설치해야합니다. PostgreSQL 클라이언트 도구는 모든 PostgreSQL 설치와 함께 기본적으로 설치됩니다.
서버를 원하지 않고 클라이언트 도구 만 원한다면 :
postgresql-client 설치로 충분할 것입니다. $ sudo apt-get install -y postgresql-client 와 같은 것이지만 시스템에 따라 다릅니다. pgroutiner 외부 도구를 호출하면 먼저 기본 별명 psql 또는 pg_dump 호출하려고합니다. 그런 다음 도구 버전이 연결에서 버전과 일치하지 않으면 기본 위치에서 실행 파일을 찾으려고합니다.
C:Program FilesPostgreSQL{0}binpg_dump.exe 및 C:Program FilesPostgreSQL{0}binpsql.exe ./usr/lib/postgresql/{0}/bin/pg_dump 및 /usr/lib/postgresql/{0}/bin/psql .{0} 형식은 주요 버전 번호입니다.이러한 경로는 기본적으로 이진을 설치하는 PostgreSQL입니다.
Pgroutiner가 버전 불일치를 보면 적절한 버전 번호로 해당 경로로 경고 및 폴백을 표시합니다.
이 동작은 각각 PgDumpFallback 및 PsqlFallback 설정 값을 설정하여 피할 수 있습니다.
이것은 보상없이 자유롭게 개발되고 유지되는 오픈 소스 소프트웨어입니다.
저작권 (C) Vedran Bilopavlović -VB Consulting 및 VB Software 2020이 소스 코드는 MIT 라이센스에 따라 라이센스가 부여됩니다.