简介
本文介绍怎么在本地启动一个hasura,并且初步尝试一下graphql的能力。
初始化postgres
启动进入postgres
# The default postgres user and database are created in the entrypoint with initdb.
# POSTGRES_USER postgres
docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=password -d postgres
docker exec -it postgres psql -h localhost -U postgres
CREATE DATABASE dbname;
-- 显示所有数据库
\l
-- 进入数据库:
\c dbanme
-- CREATE SCHEMA myschema;
-- PG
CREATE TABLE shipments (
shipment_id SERIAL NOT NULL PRIMARY KEY,
order_id SERIAL NOT NULL,
origin VARCHAR(255) NOT NULL,
destination VARCHAR(255) NOT NULL,
is_arrived BOOLEAN NOT NULL
);
ALTER SEQUENCE public.shipments_shipment_id_seq RESTART WITH 1001;
ALTER TABLE public.shipments REPLICA IDENTITY FULL;
INSERT INTO shipments
VALUES (default,10001,'Beijing','Shanghai',false),
(default,10002,'Hangzhou','Shanghai',false),
(default,10003,'Shanghai','Hangzhou',false);
select * from shipments;
初始化Hasura
docker run -d -p 8080:8080 --link postgres:postgres -e HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:password@postgres:5432/dbname -e HASURA_GRAPHQL_ENABLE_CONSOLE=true hasura/graphql-engine:latest
# postgres://admin:password@localhost:5432/my-db
# postgres://admin:@localhost:5432/my-db (if there is no password)
# graphql-engine:v2.10.2
# http://localhost:8080
网友评论