Skip to content

Commit

Permalink
chore(docs): add Hugo site
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust committed Feb 3, 2020
1 parent f89ad3d commit 9c5ef1e
Show file tree
Hide file tree
Showing 19 changed files with 559 additions and 159 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "docs/themes/hugo-coder"]
path = docs/themes/hugo-coder
url = https://github.com/luizdepra/hugo-coder.git
[submodule "docs/themes/hugo-whisper-theme"]
path = docs/themes/hugo-whisper-theme
url = https://github.com/jugglerx/hugo-whisper-theme.git
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ lint: bin/golangci-lint
@echo
bin/golangci-lint run ./...

.PHONY: docs
docs:
@echo
@echo " (x x) < memefish: docs"
@echo " /|||\\"
@echo
cd docs && hugo

.PHONY: ci
ci: lint test

Expand Down
136 changes: 5 additions & 131 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
title: README
---

<p align="center">
<img src="icon/memefish.png" width="220px">
<img src="images/memefish.png" width="220px">
</p>

# méméfish
Expand All @@ -18,134 +22,6 @@
- Generate Spanner SQL from AST (unparse)
- Check expression type and semantics in SQL statement

Try it!

```console
$ go run ./tools/analyze -param ./tools/param.yml 'select 1 + @foo'
+-------+
| FOO |
+-------+
| INT64 |
+-------+

$ go run ./tools/analyze -param ./tools/param.yml 'select @bar + 1 as bar'
analyze error::1:8: operator + requires two INT64/FLOAT64, but: STRUCT<x INT64, y FLOAT64>, INT64

1: select @bar + 1 as bar
^~~~~~~~

exit status 1
```

## Example

### Parse + Unparse

```go
package main

import (
"fmt"
"log"

"github.com/MakeNowJust/memefish/pkg/parser"
"github.com/MakeNowJust/memefish/pkg/token"
"github.com/k0kubun/pp"
)

func main() {
// Create a new Parser instance.
file := &token.File{
Buffer: "SELECT * FROM customers",
}
p := &parser.Parser{
Lexer: &parser.Lexer{File: file},
}

// Do parsing!
stmt, err := p.ParseQuery()
if err != nil {
log.Fatal(err)
}

// Show AST.
log.Print("AST")
_, _ = pp.Println(stmt)

// Unparse AST to SQL source string.
log.Print("Unparse")
fmt.Println(stmt.SQL())
}
```

### Analyze

```go
package main

import (
"fmt"
"log"

"github.com/MakeNowJust/memefish/pkg/analyzer"
"github.com/MakeNowJust/memefish/pkg/parser"
"github.com/MakeNowJust/memefish/pkg/token"
)

func main() {
// Create a new Parser instance.
file := &token.File{
Buffer: "SELECT * FROM singers",
}
p := &parser.Parser{
Lexer: &parser.Lexer{File: file},
}

// Do parsing!
stmt, err := p.ParseQuery()
if err != nil {
log.Fatal(err)
}

// Create table catalog.
catalog := &analyzer.Catalog{
Tables: map[string]*analyzer.TableSchema{
"SINGERS": {
Name: "Singers",
Columns: []*analyzer.ColumnSchema{
{Name: "SingerId", Type: analyzer.Int64Type},
{Name: "FirstName", Type: analyzer.StringType},
{Name: "LastName", Type: analyzer.StringType},
},
},
},
}

// Create a new Analyzer instance.
a := &analyzer.Analyzer{
File: file,
Catalog: catalog,
}

// Analyze!
err = a.AnalyzeQueryStatement(stmt)
if err != nil {
log.Fatal(err)
}

// Get first column information.
columns := a.NameLists[stmt.Query]
fmt.Printf("1st column name : %s\n", columns[0].Text)
fmt.Printf("1st column type : %s\n", columns[0].Type)
fmt.Printf("1st column schema: %#v\n", columns[0].Deref().ColumnSchema) // == catalog.Tables["SINGERS"].Columns[0]
}
```

## TODO

- Make more compatibility
- Build Spanner emulator on memefish

## Notice

This project is originally developed under "Expert team Go Engineer (Backend)" of [Mercari Summer Internship for Engineer 2019](https://mercan.mercari.com/articles/13497/).
Expand All @@ -154,7 +30,5 @@ This project is originally developed under "Expert team Go Engineer (Backend)" o

This project is licensed under MIT license.

2019 (C) TSUYUSATO "MakeNowJust" Kitsune

[godoc-badge]: https://img.shields.io/badge/godoc-reference-black.svg?style=for-the-badge&colorA=%235272B4&logo=go&logoColor=white
[codecov-badge]: https://img.shields.io/codecov/c/github/MakeNowJust/memefish/master.svg?style=for-the-badge&colorA=FF005E&logo=codecov&logoColor=white
2 changes: 2 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resources/
public/
6 changes: 0 additions & 6 deletions docs/archetypes/default.md

This file was deleted.

44 changes: 41 additions & 3 deletions docs/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
baseURL = "http://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
baseurl = "https://makenowjust.github.io/memefish"
title = "méméfish"
theme = "hugo-whisper-theme"
languagecode = "en"
defaultcontentlanguage = "en"

paginate = 20
canonifyurls = true

pygmentsstyle = "bw"
pygmentscodefences = true
pygmentscodefencesguesssyntax = true

summaryLength = 30

[params]
homepage_button_link = "/docs"
homepage_button_text = "Read The Docs"
homepage_intro = "the foundation to analyze Spanner SQL"
homepage_image = "/images/terminal.svg"

[params.logo]
mobile = "/images/memefish.svg"
standard = "/images/memefish.svg"

[[menu.main]]
name = "Docs"
weight = 1
url = "/docs/"
[[menu.main]]
name = "Demo"
weight = 2
url = "/demo/"
[[menu.main]]
name = "GoDoc"
weight = 3
url = "https://godoc.org/github.com/MakeNowJust/memefish/pkg"
[[menu.main]]
name = "GitHub"
weight = 3
url = "https://github.com/MakeNowJust/memefish"
1 change: 1 addition & 0 deletions docs/content/docs/_index.md
76 changes: 76 additions & 0 deletions docs/content/docs/example-analyze/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
date: 2020-02-03 00:00:00 +0900
title: "Example: analyze"
weight: 2
---

This example shows how to analyze a Spanner SQL after parsing.

<!--more-->

## Code

```go
package main

import (
"fmt"
"log"

"github.com/MakeNowJust/memefish/pkg/analyzer"
"github.com/MakeNowJust/memefish/pkg/parser"
"github.com/MakeNowJust/memefish/pkg/token"
)

func main() {
// Create a new Parser instance.
file := &token.File{
Buffer: "SELECT * FROM singers",
}
p := &parser.Parser{
Lexer: &parser.Lexer{File: file},
}

// Do parsing!
stmt, err := p.ParseQuery()
if err != nil {
log.Fatal(err)
}

// Create table catalog.
catalog := &analyzer.Catalog{
Tables: map[string]*analyzer.TableSchema{
"SINGERS": {
Name: "Singers",
Columns: []*analyzer.ColumnSchema{
{Name: "SingerId", Type: analyzer.Int64Type},
{Name: "FirstName", Type: analyzer.StringType},
{Name: "LastName", Type: analyzer.StringType},
},
},
},
}

// Create a new Analyzer instance.
a := &analyzer.Analyzer{
File: file,
Catalog: catalog,
}

// Analyze!
err = a.AnalyzeQueryStatement(stmt)
if err != nil {
log.Fatal(err)
}

// Get first column information.
columns := a.NameLists[stmt.Query]
fmt.Printf("1st column name : %s\n", columns[0].Text)
fmt.Printf("1st column type : %s\n", columns[0].Type)
fmt.Printf("1st column schema: %#v\n", columns[0].Deref().ColumnSchema) // == catalog.Tables["SINGERS"].Columns[0]
}
```

## Links

- [analyzer - GoDoc](https://godoc.org/github.com/MakeNowJust/memefish/pkg/analyzer)
54 changes: 54 additions & 0 deletions docs/content/docs/example-parse/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
date: 2020-02-03 00:00:00 +0900
title: "Example: parse and unparse"
weight: 1
---

This example shows how to parse a Spanner SQL and unparse it.

<!--more-->

## Code

```go
package main

import (
"fmt"
"log"

"github.com/MakeNowJust/memefish/pkg/parser"
"github.com/MakeNowJust/memefish/pkg/token"
"github.com/k0kubun/pp"
)

func main() {
// Create a new Parser instance.
file := &token.File{
Buffer: "SELECT * FROM customers",
}
p := &parser.Parser{
Lexer: &parser.Lexer{File: file},
}

// Do parsing!
stmt, err := p.ParseQuery()
if err != nil {
log.Fatal(err)
}

// Show AST.
log.Print("AST")
_, _ = pp.Println(stmt)

// Unparse AST to SQL source string.
log.Print("Unparse")
fmt.Println(stmt.SQL())
}
```

## Links

- [ast - GoDoc](https://godoc.org/github.com/MakeNowJust/memefish/pkg/ast)
- [parser - GoDoc](https://godoc.org/github.com/MakeNowJust/memefish/pkg/parser)
- [Query Syntax |  Cloud Spanner  |  Google Cloud](https://cloud.google.com/spanner/docs/query-syntax)
12 changes: 12 additions & 0 deletions docs/layouts/_default/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{ define "header_css" }}{{ end }}
{{ define "body_classes" }}page-default-list{{ end }}
{{ define "header_classes" }}{{ end }}

{{ define "main" }}

<h1 class="title">{{ .Title }}</h1>
<div class="content">
{{ .Content }}
</div>

{{ end }}
Loading

0 comments on commit 9c5ef1e

Please sign in to comment.