tarsius
v0.2.2
Published
Tarsius CLI Development Tools
Readme
tarsius
TARSIUS MANIFEST
Tables
Structure
tables:
<name_table>:
<name_field>:
<properties>example
tables :
# Create table author
author:
id:
type: serial
notNull: true
primaryKey: true
name:
type: varchar(100)
notNull: true
email:
type: varchar(150)
notNull: true
created:
type: timestamptzInclude Table
You can include table resource from other tarsius manifest
tables :
# Create table posts
author: ../author/tarsius.yml
post:
id:
type: serial
notNull: true
primaryKey: true
title:
type: varchar(100)
notNull: true
content:
type: text
authorid:
type: author.id # Set set authorid as a FK author table
notNull: true
isCascade: true
created:
type: timestamptzType Data of Field
Type | Description ---|--- bool | A Boolean data type can hold one of three possible values: true, false or null. varchar | VARCHAR(n) is the variable-length character string. int | Integer is a numeric types timestamp | TIMESTAMP stores both date and time values. timestamptz | TIMESTAMPTZ is a timezone-aware timestamp data type. It is the abbreviation for timestamp with time zone.
Properties
properties | description | value
---|---|---
type | Type data of field | String
notNull | set field as a NOT NULL type | Bool
primaryKey | set field as a primary key | Bool
isCascade | set field as ON DELETE CASCADE and ON UPDATE CASCADE | Bool
isUnique | set field as UNIQUE data | Bool
Create project
Create new project
$ mkdir project-test
$ cd project-testCreate tarsius.yml for data modeling
tables :
# Create table author
author:
id:
type: serial
notNull: true
primaryKey: true
name:
type: varchar(100)
notNull: true
email:
type: varchar(150)
notNull: true
created:
type: timestamptz
# Create table post
post:
id:
type: serial
notNull: true
primaryKey: true
title:
type: varchar(100)
notNull: true
content:
type: text
authorid:
type: author.id
notNull: true
created:
type: timestamptzuse anchor
tables :
# Create table author
author:
id: &idAnchor
type: serial
notNull: true
primaryKey: true
name: &nameAnchor
type: varchar(100)
notNull: true
email:
<<: *nameAnchor
created: &dateAnchor
type: timestamptz
# Create table post
post:
id:
<<: *idAnchor
title:
<<: *nameAnchor
content:
type: text
authorid:
# Set joining to `authors` table
type: author.id
notNull: true
created:
<<: *dateAnchorSQL
Configuration
$ tarsius sql configCreate table
$ tarsius sql createInitialize your project
$ tarsius init
or
$ tarsius init -s go -p ../project-directoryEnvironment Variables
The generated code accepts env vars as well. They are :
TS_DB_HOSTTS_DB_PORTTS_DB_NAMETS_DB_USERTS_DB_PASSTS_CORS_ORIGINTS_CORS_METHODSTS_CORS_HEADERS
TS_CORS_ORIGIN will also automaticaly sets basic CORS methods and headers. You can override them with TS_CORS_METHODS and TS_CORS_HEADERS.
Run project
$ tarsius runAccess it on http://localhost:8000
GraphQL
Query to get the all authors
query {
authors {
id
name
email
created
}
}Query to get a specific author
query {
author(id: 1) {
id
name
email
}
}Query with pagination
query{
authors(page:1,pageSize:4){
id
name
email
}
}Create new author using mutation
mutation {
createAuthor(name: "Ibnu Yahya", email: "[email protected]") {
id
name
email
}
}Update an author using mutation
mutation {
updateAuthor(id: 2, name: "ibnu Yahya", email: "[email protected]") {
id
name
email
}
}Delete an author using mutation
mutation {
deleteAuthor(id: 2) {
id
}
}Query to get the posts with its relation author
query {
posts {
id
title
content
author {
id
name
email
}
}
}