Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,246 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: '' | ||
labels: bug | ||
assignees: freerjm | ||
|
||
--- | ||
|
||
**Description** | ||
|
||
Clear and concise description of the issue. | ||
|
||
**Steps to Reproduce** | ||
|
||
1. [First Step] | ||
2. [Second Step] | ||
3. [and so on...] | ||
|
||
**Expected Behavior** | ||
|
||
What you expect to happen. | ||
|
||
**Actual Behavior** | ||
|
||
What actually happens. | ||
|
||
**Versions** | ||
|
||
It can be super helpful to get an idea of your environment when troubleshooting issues. We ask you include the following versions: | ||
|
||
- `Go` (`go version`) | ||
- `dep` (`dep version`) | ||
- the version of `morph` you are using | ||
|
||
**Additional Context** | ||
|
||
Any additional information, configuration or data that might be necessary to reproduce the issue. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
**Description** | ||
|
||
Clear and concise description of the changes. Make sure to include any open issues that these changes aim to resolve. | ||
|
||
**Rationale** | ||
|
||
Rationale of why consumers need this feature or fix. | ||
|
||
**Suggested Version** | ||
|
||
Dialog describing whether the change requires a bump in major, minor, or patch version number. | ||
|
||
**Example Usage** | ||
|
||
Walkthrough with code blocks to demonstrate the feature or fix. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
language: go | ||
go: | ||
- 1.11 | ||
jobs: | ||
include: | ||
- | ||
stage: 'unit test' | ||
install: | ||
- go get golang.org/x/tools/cmd/cover | ||
- go get github.com/mattn/goveralls | ||
before_script: | ||
- 'curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh' | ||
script: | ||
- 'make test' | ||
- '$HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken $COVERALLS_TOKEN' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Working on `morph` | ||
|
||
Looking to join us in evolving and improving `morph`? We put together a small guide to lay out the ground rules. | ||
|
||
Let's do this! 🤓 | ||
|
||
## How do I report a bug? | ||
|
||
Hey, nobody's perfect. As much as we test our code, a few bugs sneak past us. If you would like to report one you found, simply check our [Github issues](https://github.com/freerware/morph/issues) that have the `bug` tag to see if someone beat you to it! Otherwise, whip one up with [this](https://github.com/freerware/morph/issues/new?assignees=freerjm&labels=bug&template=bug_report.md) template. | ||
|
||
## How do I ask questions? | ||
|
||
Great question. We suggest checking for any Github issues with the `question` tag to see if anyone has asked the same question before. When you're not finding what you are looking for, we ask that you create an issue with the `question` tag, so that others can benefit from the conversation. | ||
|
||
## Where can I leave feedback? | ||
|
||
We would enjoy hearing your thoughts on the work we have done so far, how you use `morph`, and ideas you might have to make things better! Currently, just drop an email to the primary author at `freerware@gmail.com`. | ||
|
||
## How do I contribute changes? | ||
|
||
Want to lend us a hand? We welcome pull requests for fixes and new features! All we ask is that your pull request hits these checklist items: | ||
|
||
- [ ] Uses [well formed commit messages](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html). | ||
- [ ] Includes unit tests and maintains consistent or higher code coverage. | ||
- [ ] Makes changes to both comments and other documentation where appropriate. | ||
- [ ] Uses the following pull request [template](https://github.com/freerware/morph/blob/master/.github/pull_request_template.md). | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Gopkg.toml example | ||
# | ||
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
# | ||
# [prune] | ||
# non-go = false | ||
# go-tests = true | ||
# unused-packages = true | ||
|
||
|
||
[[constraint]] | ||
name = "github.com/stretchr/testify" | ||
version = "1.4.0" | ||
|
||
[prune] | ||
go-tests = true | ||
unused-packages = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
all: bins | ||
|
||
clean: | ||
go clean -x | ||
rm -r --force vendor/ | ||
|
||
bins: | ||
dep ensure -v | ||
go build | ||
|
||
test: bins | ||
go test -v -covermode=count -coverprofile=coverage.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,125 @@ | ||
# morph | ||
A compact package for organizing and maintaining your entity database metadata. | ||
|
||
[![GoDoc][doc-img]][doc] [![Build Status][ci-img]][ci] | ||
[![Coverage Status][coverage-img]][coverage] [![Release][release-img]][release] | ||
[![License][license-img]][license] | ||
|
||
## What is it? | ||
|
||
`morph` organizes and maintains the necessary metadata to map your entities to | ||
and from relational database tables. This is accomplished using the | ||
[Metadata Mapping][metadata-mapping] pattern popularized by Martin Fowler. | ||
With these metadata mappings, your application is empowered to construct SQL | ||
queries dynamically using the entities themselves. | ||
|
||
## Why use it? | ||
|
||
With `morph`, your application reaps several benefits: | ||
|
||
- dynamic construction of queries using entities and their fields. | ||
- metadata generation using files in several formats, including [YAML][yaml] and [JSON][json]. | ||
- decoupling of code responsible for manufacturing queries from code tasked with SQL generation. | ||
|
||
## How to use it? | ||
|
||
Using `morph` is super straightforward. You utilize [`Table`][table-doc] and | ||
[`Column`][column-doc] to organize metadata for your entities and their | ||
associated relational representations. Let's suppose you have a `User` entity | ||
in your application (`user`): | ||
```go | ||
var usernameCol morph.Column | ||
usernameCol.SetName("username") | ||
usernameCol.SetField(Fields.Username) | ||
|
||
var passwordCol morph.Column | ||
passwordCol.SetName("password") | ||
passwordCol.SetField(Fields.Password) | ||
|
||
var userTable morph.Table | ||
userTable.SetName("user") | ||
userTable.SetAlias("U") | ||
userTable.SetType(user) | ||
userTable.AddColumns(usernameCol, passwordCol) | ||
``` | ||
|
||
### Loading | ||
|
||
Capturing the metadata mappings can be tedious, especially if your application | ||
has many entities with corresponding relational representations. Instead | ||
of constructing them manually, we recommend loading in a file that | ||
specifies the metadata mapping configuration: | ||
```json | ||
{ | ||
"tables": [ | ||
{ | ||
"typeName": "example.User", | ||
"name": "user", | ||
"alias": "U", | ||
"columns": [ | ||
{ | ||
"name": "username", | ||
"field": "Username" | ||
}, | ||
{ | ||
"name": "password", | ||
"field": "Password" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` | ||
```go | ||
configuration, err := morph.Load("./metadata.json") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
tables := configuration.AsMetadata() | ||
``` | ||
|
||
### Custom Loader | ||
|
||
At this time, we currently support YAML (`.yaml`, `.yml`) and JSON (`.json`) | ||
configuration files. However, if you would like to utilize a different file | ||
format, you can construct a type that implements [`morph.Loader`][loader-doc] | ||
and add the appropriate entries in [`morph.Loaders`][loaders-doc]. The | ||
[`morph.Load`][load-doc] function will leverage `morph.Loaders` by extracting | ||
the file extension using the path provided to it. | ||
|
||
## Contribute | ||
|
||
Want to lend us a hand? Check out our guidelines for | ||
[contributing][contributing]. | ||
|
||
## License | ||
|
||
We are rocking an [Apache 2.0 license][apache-license] for this project. | ||
|
||
## Code of Conduct | ||
|
||
Please check out our [code of conduct][code-of-conduct] to get up to speed | ||
how we do things. | ||
|
||
[contributing]: https://github.com/freerware/morph/blob/master/CONTRIBUTING.md | ||
[apache-license]: https://github.com/freerware/morph/blob/master/LICENSE.txt | ||
[code-of-conduct]: https://github.com/freerware/morph/blob/master/CODE_OF_CONDUCT.md | ||
[doc-img]: https://godoc.org/github.com/freerware/morph?status.svg | ||
[doc]: https://godoc.org/github.com/freerware/morph | ||
[ci-img]: https://travis-ci.org/freerware/morph.svg?branch=master | ||
[ci]: https://travis-ci.org/freerware/morph | ||
[coverage-img]: https://coveralls.io/repos/github/freerware/morph/badge.svg?branch=master | ||
[coverage]: https://coveralls.io/github/freerware/morph?branch=master | ||
[license]: https://opensource.org/licenses/Apache-2.0 | ||
[license-img]: https://img.shields.io/badge/License-Apache%202.0-blue.svg | ||
[release]: https://github.com/freerware/morph/releases | ||
[release-img]: https://img.shields.io/github/tag/freerware/morph.svg?label=version | ||
[loaders-doc]: https://godoc.org/github.com/freerware/morph#Loaders | ||
[loader-doc]: https://godoc.org/github.com/freerware/morph#Loader | ||
[load-doc]: https://godoc.org/github.com/freerware/morph#Load | ||
[metadata-mapping]: https://www.martinfowler.com/eaaCatalog/metadataMapping.html | ||
[table-doc]: https://godoc.org/github.com/freerware/morph#Table | ||
[column-doc]: https://godoc.org/github.com/freerware/morph#Column | ||
[yaml]: https://yaml.org/ | ||
[json]: https://www.json.org/ |
Oops, something went wrong.