PgRoutiner是一組PostgreSQL數據庫和PostgreSQL .NET項目的命令行工具。
使用您的.NET配置項目連接字符串(或自定義定義連接) - 您可以:
輕鬆瀏覽並蒐索數據庫。
生成C#和TS模型和代碼。
生成數據庫腳本和運行工具。
生成Markdown文檔。
生成CRUD命令函數。
查看演示幻燈片
查看Pgroutiner博客
請參閱Pgroutiner概念博客
請參閱Pgroutiner數據庫管理博客
請參閱Pgroutiner代碼 - 天文博客
請參閱Pgroutiner文檔博客
注意:此讀取文件中的所有示例以及上面的演示文稿中使用[PostgreSQL Tutorial]的PostgreSQL示例數據庫
快速開始:
- 從“版本”頁面下載最新版本的本機可執行文件(不取決於任何框架)。
- 將適當的路徑設置為下載的可執行文件。
- 類型
pgroutiner --info- 注意:使用本機可執行文件的速度更快,它們的啟動時間很短,並且提供了很多倍更好的用戶體驗。
目錄:
這是使用Pgroutiner工具開始的最快,最簡單的方法。該版本頁麵包含可下載的可執行文件,這些可執行文件不取決於任何內容。不需要框架或碼頭,只需簡單的舊本機可執行即可。
實際上,這是使用Pgroutiner工具的優選方法。本地可執行文件非常優化,啟動時間很短,它們提供了多倍更好的用戶體驗。
這是步驟:
pgroutiner --info以查看f。就是這樣。
安裝全局工具(建議):
$ 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 Switch的工具。
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 Project root運行 - 它將從標準配置JSON文件(例如appsettings.Development.json and appsettings.json ,按此順序讀取任何可用的連接)。
它將使用ConnectionStrings部分中的第一個可用連接字符串:
AppSettings.json
{
"ConnectionStrings" : {
"DvdRental" : " Server=localhost;Db=dvdrental;Port=5432;User Id=postgres;Password=postgres; "
}
}注意:這是NPGSQL連接字符串格式,但是,它還可以使用標準的Postgresql URL連接格式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:連接服務器,端口,數據庫和用戶具有預定義的默認值( localhost , 5432 , postgres , postgres ) - 點擊Enter以跳過並使用默認值。
命令行可以將整個連接字符串與-c或--connection - 而不是連接名稱:
~$ pgroutiner --connection "Server=localhost;Db=test;Port=5432;User Id=postgres;Password=postgres;" --infopostgresql://{user}:{password}@{server}:{port}/{database} - 而不是npgsql Connection strint: {
"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-prompt promptSchemaSimilarTo ,命令行: --schema-similar-to例如,許多設置也具有快捷方式別名,例如, Connection設置可以是: -c -conn --conn -connection --connection 。
布爾設置是開關,足以在沒有價值的情況下包含一個開關以打開它: pgroutiner --skip-connection-prompt
添加false或0以將其關閉: pgroutiner --skip-connection-prompt false
您可以使用--settings Switch檢查當前應用的設置。 pgroutiner --settings將迫使跳過任何操作,並且只會顯示所有當前設置。它還將在評論標題中顯示命令行別名。
您還可以運行pgroutiner --info ,除其他外,它將顯示與默認值不同的當前應用設置。
如果在任何地方都沒有配置部分PgRoutiner ,並且如果您沒有任何參數運行pgroutiner ,則將提供創建默認配置文件appsettings.PgRoutiner.json :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, -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)
);
...根據命令,此工具將使用PostgreSQL客戶端工具(例如psql , pg_dump或pg_restore啟動外部進程。
這意味著,必須在系統上安裝PostgreSQL客戶端工具。默認情況下,每個PostgreSQL安裝都將安裝PostgreSQL客戶端工具。
如果您不想要服務器,而只需要客戶端工具:
$ sudo apt-get install -y postgresql-client postgresql-client ,但取決於系統。當pgroutiner調用外部工具時,它將首先嘗試調用默認別名psql或pg_dump 。然後,如果該工具的版本與連接中的版本不匹配,它將嘗試在默認位置找到可執行文件:
C:Program FilesPostgreSQL{0}binpg_dump.exe和C:Program FilesPostgreSQL{0}binpsql.exe用於Windows Systems。/usr/lib/postgresql/{0}/bin/pg_dump和/usr/lib/postgresql/{0}/bin/psql用於Linux Systems。{0}是主要版本號。這些路徑默認情況下是postgresql安裝二進製文件。
當Pgroutiner看到版本不匹配時,它將引起警告並帶有適當的版本號到該路徑的後備。
可以分別通過設置PgDumpFallback和PsqlFallback設置值來避免這種行為。
這是開發和維護的開源軟件,而無需任何薪酬。
版權所有(C)VedranBilopavlović -VB諮詢和VB軟件2020此源代碼已根據MIT許可獲得許可。