Skip to content

Commit

Permalink
initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
fr33r committed Sep 3, 2019
1 parent c9749f8 commit f5b6f32
Show file tree
Hide file tree
Showing 22 changed files with 1,246 additions and 27 deletions.
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
@@ -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.
15 changes: 15 additions & 0 deletions .github/pull_request_template.md
@@ -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.
7 changes: 7 additions & 0 deletions .gitignore
Expand Up @@ -10,3 +10,10 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directory
vendor/

# Tag file
.tags
tags
15 changes: 15 additions & 0 deletions .travis.yml
@@ -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'
27 changes: 27 additions & 0 deletions CONTRIBUTING.md
@@ -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).

58 changes: 58 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Gopkg.toml
@@ -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
27 changes: 0 additions & 27 deletions LICENSE → LICENSE.txt
Expand Up @@ -172,30 +172,3 @@
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
12 changes: 12 additions & 0 deletions Makefile
@@ -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
123 changes: 123 additions & 0 deletions README.md
@@ -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/

0 comments on commit f5b6f32

Please sign in to comment.