Skip to content

Commit

Permalink
feat(*): first draft
Browse files Browse the repository at this point in the history
implemented database provider
  • Loading branch information
thetutlage committed Feb 16, 2016
1 parent 3b5c5ab commit 4eda47c
Show file tree
Hide file tree
Showing 20 changed files with 1,352 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage
node_modules
.DS_Store
npm-debug.log
8 changes: 8 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
coverage
node_modules
.DS_Store
npm-debug.log
test
.travis.yml
.editorconfig
benchmarks
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
language: node_js
env:
- CXX=g++-4.8
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
node_js:
- 5.3.0
- 4.0.0
sudo: false
install:
- npm install --no-optional
notifications:
slack:
secure: m91zkX2cLVDRDMBAUnR1d+hbZqtSHXLkuPencHadhJ3C3wm53Box8U25co/goAmjnW5HNJ1SMSIg+DojtgDhqTbReSh5gSbU0uU8YaF8smbvmUv3b2Q8PRCA7f6hQiea+a8+jAb7BOvwh66dV4Al/1DJ2b4tCjPuVuxQ96Wll7Pnj1S7yW/Hb8fQlr9wc+INXUZOe8erFin+508r5h1L4Xv0N5ZmNw+Gqvn2kPJD8f/YBPpx0AeZdDssTL0IOcol1+cDtDzMw5PAkGnqwamtxhnsw+i8OW4avFt1GrRNlz3eci5Cb3NQGjHxJf+JIALvBeSqkOEFJIFGqwAXMctJ9q8/7XyXk7jVFUg5+0Z74HIkBwdtLwi/BTyXMZAgsnDjndmR9HsuBP7OSTJF5/V7HCJZAaO9shEgS8DwR78owv9Fr5er5m9IMI+EgSH3qtb8iuuQaPtflbk+cPD3nmYbDqmPwkSCXcXRfq3IxdcV9hkiaAw52AIqqhnAXJWZfL6+Ct32i2mtSaov9FYtp/G0xb4tjrUAsDUd/AGmMJNEBVoHtP7mKjrVQ35cEtFwJr/8SmZxGvOaJXPaLs43dhXKa2tAGl11wF02d+Rz1HhbOoq9pJvJuqkLAVvRdBHUJrB4/hnTta5B0W5pe3mIgLw3AmOpk+s/H4hAP4Hp0gOWlPA=
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Contributing

In favor of active development we accept contributions from everyone. You can contribute by submitting a bug, creating pull requests or even by improving documentation.

Below is the guide to be followed strictly before submitting your pull requests.
http://adonisjs.com/docs/2.0/contributing
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# AdonisJS Framework

[![Gitter](https://img.shields.io/badge/+%20GITTER-JOIN%20CHAT%20%E2%86%92-1DCE73.svg?style=flat-square)](https://gitter.im/adonisjs/adonis-framework)
[![Trello](https://img.shields.io/badge/TRELLO-%E2%86%92-89609E.svg?style=flat-square)](https://trello.com/b/yzpqCgdl/adonis-for-humans)
[![Version](https://img.shields.io/npm/v/adonis-framework.svg?style=flat-square)](https://www.npmjs.com/package/adonis-framework)
[![Build Status](https://img.shields.io/travis/adonisjs/adonis-framework/master.svg?style=flat-square)](https://travis-ci.org/adonisjs/adonis-framework)
[![Coverage Status](https://img.shields.io/coveralls/adonisjs/adonis-framework/master.svg?style=flat-square)](https://coveralls.io/github/adonisjs/adonis-framework?branch=master)
[![Downloads](https://img.shields.io/npm/dt/adonis-framework.svg?style=flat-square)](https://www.npmjs.com/package/adonis-framework)
[![License](https://img.shields.io/npm/l/adonis-framework.svg?style=flat-square)](https://opensource.org/licenses/MIT)

> :pray: This repository contains the core of the AdonisJS framework.
Adonis is a MVC framework for NodeJS built on solid foundations.

It is the first NodeJS framework with support for [Dependency Injection](http://adonisjs.com/docs/2.0/dependency-injection) and has a lean [IoC Container](http://adonisjs.com/docs/2.0/ioc-container) to resolve and mock dependencies. It borrows the concept of [Service Providers](http://adonisjs.com/docs/2.0/service-providers) from the popular [PHP framework Laravel](https://laravel.com) to write scalable applications.

You can learn more about AdonisJS and all of its awesomeness on http://adonisjs.com :evergreen_tree:

## Table of Contents

* [Team Members](#team-members)
* [Requirements](#requirements)
* [Getting Started](#getting-started)
* [Contribution Guidelines](#contribution-guidelines)

## <a name="team-members"></a>Team Members

* Harminder Virk ([Caffiene Blogging](http://amanvirk.me/)) <virk.officials@gmail.com>

## <a name="requirements"></a>Requirements

AdonisJS is build on the top of ES2015, which makes the code more enjoyable and cleaner to read. It doesn't make use of any transpiler and depends upon Core V8 implemented features.

For these reasons, AdonisJS require you to use `node >= 4.0` and `npm >= 3.0`.

## <a name="getting-started"></a>Getting Started

AdonisJS provide a [CLI tool](https://github.com/AdonisJs/adonis-cli) to scaffold and generate a project with all required dependencies.

```bash
$ npm install -g adonis-cli
```

```bash
$ adonis new awesome-project
$ cd awesome-project
$ npm run start
```

[Official Documentation](http://adonisjs.com/docs/2.0/installation)

## <a name="contribution-guidelines"></a>Contribution Guidelines

In favor of active development we accept contributions for everyone. You can contribute by submitting a bug, creating pull requests or even improving documentation.

You can find a complete guide to be followed strictly before submitting your pull requests in the [Official Documentation](http://adonisjs.com/docs/2.0/contributing).
202 changes: 202 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
'use strict'

/**
* adonis-framework
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

const i = require('inflect')
const _ = require('lodash')
const util = exports = module.exports = {}

/**
* makes table name from a class defination
*
* @method makeTableName
*
* @param {Object} Model
* @return {String}
*
* @public
*/
util.makeTableName = function (Model) {
let modelName = Model.name
modelName = i.pluralize(modelName)
return i.underscore(modelName)
}

/**
* makes a foreign key from a class
* defination
*
* @method makeForeignKey
* @param {Object} Model
* @return {String}
*
* @public
*/
util.makeForeignKey = function (Model) {
let modelName = Model.name
modelName = i.singularize(modelName)
return `${i.underscore(modelName)}_id`
}

/**
* omits key/values pairs from an objec
* @method omit
*
* @param {Object} values
* @param { valuesToOmit
* @return {Array|Object}
*
* @public
*/
util.omit = function (values, valuesToOmit) {
return _.omit(values, valuesToOmit)
}

/**
* pick key/values pairs from an object
*
* @method pick
* @param {Object} values
* @param {Array} valuesToOmit
* @return {Object}
*
* @public
*/
util.pick = function (values, valuesToOmit) {
return _.pick(values, valuesToOmit)
}

/**
* wraps an object into lodash collection
*
* @method toCollection
* @param {Array|Object} values
* @return {Array|Object}
*
* @public
*/
util.toCollection = function (values) {
return _(values)
}

/**
* makes a getter name for a given field
*
* @method makeGetterName
* @param {String} name
* @return {String}
*
* @public
*/
util.makeGetterName = function (name) {
return `get${i.camelize(i.underscore(name))}`
}

/**
* makes a getter name for a given field
*
* @method makeSetterName
* @param {String} name
* @return {String}
*
* @public
*/
util.makeSetterName = function (name) {
return `set${i.camelize(i.underscore(name))}`
}

/**
* map values for a given key and returns
* the transformed array with that key only
*
* @method mapValuesForAKey
* @param {Array} values
* @param {String} key
* @return {Array}
*
* @public
*/
util.mapValuesForAKey = function (values, key) {
return _.map(values, function (value) {
return value[key]
})
}

/**
* calculates offset for a given page using
* page and perPage options
*
* @method returnOffset
* @param {Number} page
* @param {Number} perPage
* @return {Number}
*
* @public
*/
util.returnOffset = function (page, perPage) {
return page === 1 ? 0 : ((perPage * (page - 1)))
}

/**
* validates a page to be a number and greater
* than 0. this is something required to paginate results.
*
* @method validatePage
* @param {Number} page
* @return {void}
* @throws {Error} If page is not a number of less than 1
*
* @public
*/
util.validatePage = function (page) {
if (typeof (page) !== 'number') {
throw new Error('page parameter is required to paginate results')
}
if (page < 1) {
throw new Error('cannot paginate results for page less than 1')
}
}

/**
* make meta data for paginated results.
*
* @method makePaginateMeta
*
* @param {Number} total
* @param {Number} page
* @param {Number} perPage
* @return {Object}
*
* @public
*/
util.makePaginateMeta = function (total, page, perPage) {
const resultSet = {
total: total,
currentPage: page,
perPage: perPage,
lastPage: 0,
data: []
}
if (total > 0) {
resultSet.lastPage = Math.ceil(total / perPage)
}
return resultSet
}

/**
* capitalizes a given string
*
* @method capitalize
* @param {String} value
* @return {String}
*
* @public
*/
util.capitalize = i.capitalize
40 changes: 40 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "adonis-lucid",
"version": "3.0.0",
"description": "[![Gitter](https://img.shields.io/badge/+%20GITTER-JOIN%20CHAT%20%E2%86%92-1DCE73.svg?style=flat-square)](https://gitter.im/adonisjs/adonis-framework) [![Trello](https://img.shields.io/badge/TRELLO-%E2%86%92-89609E.svg?style=flat-square)](https://trello.com/b/yzpqCgdl/adonis-for-humans) [![Version](https://img.shields.io/npm/v/adonis-framework.svg?style=flat-square)](https://www.npmjs.com/package/adonis-framework) [![Build Status](https://img.shields.io/travis/adonisjs/adonis-framework/master.svg?style=flat-square)](https://travis-ci.org/adonisjs/adonis-framework) [![Coverage Status](https://img.shields.io/coveralls/adonisjs/adonis-framework/master.svg?style=flat-square)](https://coveralls.io/github/adonisjs/adonis-framework?branch=master) [![Downloads](https://img.shields.io/npm/dt/adonis-framework.svg?style=flat-square)](https://www.npmjs.com/package/adonis-framework) [![License](https://img.shields.io/npm/l/adonis-framework.svg?style=flat-square)](https://opensource.org/licenses/MIT)",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "npm run standard && node --harmony_proxies ./node_modules/.bin/_mocha test --recursive",
"standard": "standard src/**/*.js lib/*.js test/**/*.js"
},
"author": "adonisjs",
"license": "MIT",
"devDependencies": {
"bluebird": "^3.3.1",
"chai": "^3.5.0",
"co-fs-extra": "^1.1.0",
"co-mocha": "^1.1.2",
"coveralls": "^2.11.6",
"cz-conventional-changelog": "^1.1.5",
"istanbul": "^0.4.2",
"mocha": "^2.4.5",
"mysql": "^2.10.2",
"sqlite3": "^3.1.1",
"standard": "^6.0.5"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"dependencies": {
"co": "^4.6.0",
"harmony-reflect": "^1.4.2",
"inflect": "^0.3.0",
"knex": "^0.10.0",
"lodash": "^4.3.0"
}
}

0 comments on commit 4eda47c

Please sign in to comment.