Created: 2020-05-06 Wed 18:57
安装PostgreSQL和Postgrest, 使用pgloader导入部分数据进行测试.
安装并且作为一个系统服务
brew doctor
brew update
brew install postgresql
brew services start postgresql
brew install postgrest
brew install pgloader
# default user postgres
# psql DBNAME USERNAME
psql postgres
CREATE USER dbuser WITH PASSWORD 'password';
CREATE DATABASE demodb OWNER dbuser;
GRANT ALL PRIVILEGES ON DATABASE demodb to dbuser;
\z
\dt
\d
\?
\conninfo
\d+
\l
\dn
\e
Add to [mysqld] section of my.cnf file (found in /usr/local/etc/ for Homebrew's installation):
default-authentication-plugin=mysql_native_password
mysql -u root -p
ALTER USER 'root'@'localhost'
IDENTIFIED WITH mysql_native_password
BY 'password';
# reboot service
brew services restart mysql
pgloader mysql://root:007a007b@localhost/pdb pgsql:///demodb
create tutorial.conf
db-uri = "postgres://lizy:lizy@localhost:5433/demodb"
db-schema = "pdb"
db-anon-role = "lizy"
run with conf:
postgrest tutorial.conf
grant select on pdb.t_index_category to lizy;
grant select on pdb.t_activity_product to lizy;
grant select on pdb.t_category to lizy;
ALTER TABLE pdb.t_index_category
DROP CONSTRAINT constraint_fk;
ALTER TABLE pdb.t_index_category
ADD CONSTRAINT constraint_fk
FOREIGN KEY (category_id)
REFERENCES t_category(category_id);
\d pdb.t_index_category
\d pdb.t_category
\d+
GET http://localhost:3000/t_index_category?select=index_category_id&order=index_category_id.desc
GET http://localhost:3000/t_activity_product
GET http://localhost:3000/t_index_category?select=index_category_id, company_id, app_id, t_category(category_id)