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 Jul 16, 2017
1 parent 0c79fe8 commit e1916ae
Show file tree
Hide file tree
Showing 12 changed files with 466 additions and 0 deletions.
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
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< 0c79fe8a64afbfdac9792c5cf526a16594bf5228
# Query Builder Features

- [x] Paginate method
Expand Down Expand Up @@ -40,3 +41,61 @@ Models.register('App/Model/City', require('./models/City'))

const User = Models.get('App/Model/User')
```
=======
# 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).
>>>>>>> feat(*): first draft
20 changes: 20 additions & 0 deletions test/unit/fixtures/files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

/**
* adonis-lucid
* Copyright(c) 2015-2015 Harminder Virk
* MIT Licensed
*/

const fs = require('co-fs-extra')
const path = require('path')

module.exports = {
cleanStorage: function * () {
return yield fs.emptyDir(path.join(__dirname,'../storage'))
},
createDir: function * () {
return yield fs.ensureDir(path.join(__dirname,'../storage'))
}
}

85 changes: 85 additions & 0 deletions test/unit/fixtures/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
'use strict'

const bluebird = require('bluebird')

module.exports = {
up: function (knex) {
const tables = [
knex.schema.createTable('users', function (table) {
table.increments()
table.string('username')
table.string('firstname')
table.string('lastname')
table.string('status')
table.timestamps()
table.timestamp('deleted_at').nullable()
}),
knex.schema.createTable('accounts', function (table) {
table.increments()
table.string('account_name')
table.timestamps()
table.timestamp('deleted_at').nullable()
}),
knex.schema.createTable('profiles', function (table) {
table.increments()
table.integer('user_id')
table.string('display_name')
table.timestamps()
table.timestamp('deleted_at').nullable()
}),
knex.schema.createTable('cars', function (table) {
table.increments()
table.integer('user_id')
table.string('car_name')
table.timestamps()
table.timestamp('deleted_at').nullable()
}),
knex.schema.createTable('keys', function (table) {
table.increments()
table.integer('car_id')
table.string('key_number')
table.timestamps()
table.timestamp('deleted_at').nullable()
})
]
return bluebird.all(tables)
},

down: function (knex) {
const dropTables = [
knex.schema.dropTable('users'),
knex.schema.dropTable('accounts'),
knex.schema.dropTable('profiles'),
knex.schema.dropTable('cars'),
knex.schema.dropTable('keys')
]
return bluebird.all(dropTables)
},

setupAccount: function (knex) {
return knex.table('accounts').insert({account_name: 'sales', created_at: new Date(), updated_at: new Date()})
},

setupProfile: function (knex) {
return knex.table('profiles').insert({user_id: 1, display_name: 'virk', created_at: new Date(), updated_at: new Date()})
},

setupCar: function (knex) {
return knex.table('cars').insert({user_id: 1, car_name: 'audi a6', created_at: new Date(), updated_at: new Date()})
},

setupCarKey: function (knex) {
return knex.table('keys').insert({car_id: 1, key_number: '98010291222', created_at: new Date(), updated_at: new Date()})
},

setupUser: function (knex) {
return knex.table('users').insert({
firstname: 'aman',
lastname: 'virk',
username: 'avirk',
created_at: new Date(),
updated_at: new Date()
})
}

}
77 changes: 77 additions & 0 deletions test/unit/fixtures/relations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use strict'

/**
* adonis-lucid
* Copyright(c) 2016-2016 Harminder Virk
* MIT Licensed
*/

const path = require('path')
const bluebird = require('bluebird')
const files = require('./files')

module.exports = {
setupTables: function (knex) {
const tables = [
knex.schema.createTable('suppliers', function (table) {
table.increments()
table.string('name')
table.timestamps()
table.timestamp('deleted_at').nullable()
}),
knex.schema.createTable('accounts', function (table) {
table.increments()
table.integer('supplier_id')
table.string('name')
table.timestamps()
table.timestamp('deleted_at').nullable()
}),
knex.schema.createTable('all_suppliers', function (table) {
table.increments()
table.string('regid').unique()
table.string('name')
table.timestamps()
table.timestamp('deleted_at').nullable()
}),
knex.schema.createTable('all_accounts', function (table) {
table.increments()
table.string('supplier_regid')
table.string('name')
table.timestamps()
table.timestamp('deleted_at').nullable()
}),
knex.schema.createTable('users', function (table) {
table.increments()
table.string('username')
table.integer('manager_id')
table.string('type')
table.timestamps()
table.timestamp('deleted_at').nullable()
})
]
return bluebird.all(tables)
},
dropTables: function (knex) {
const tables = [
knex.schema.dropTable('accounts'),
knex.schema.dropTable('suppliers'),
knex.schema.dropTable('all_accounts'),
knex.schema.dropTable('all_suppliers'),
knex.schema.dropTable('users')
]
return bluebird.all(tables)
},
createRecords: function * (knex, table, values) {
return yield knex.table(table).insert(values)
},
truncate: function * (knex, table) {
yield knex.table(table).truncate()
},
up: function * (knex) {
yield files.createDir()
yield this.setupTables(knex)
},
down: function * (knex) {
yield this.dropTables(knex)
}
}
34 changes: 34 additions & 0 deletions test/unit/helpers/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict'

/**
* adonis-lucid
* Copyright(c) 2016-2016 Harminder Virk
* MIT Licensed
*/
const path = require('path')
const mysqlConnections = require('./mysqlConnections')
const sqliteConnections = require('./sqliteConnections')

module.exports = {
get: function (key) {
if (key === 'database.connection') {
return process.env.DB
}

if (key === 'database.sqlite3') {
return sqliteConnections.default
}

if (key === 'database.mysql') {
return mysqlConnections.default
}

if (key === 'database.alternateConnection' && process.env.DB === 'sqlite3') {
return sqliteConnections.alternateConnection
}

if (key === 'database.alternateConnection' && process.env.DB === 'mysql') {
return mysqlConnections.alternateConnection
}
}
}
27 changes: 27 additions & 0 deletions test/unit/helpers/mysqlConnections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

/**
* adonis-lucid
* Copyright(c) 2016-2016 Harminder Virk
* MIT Licensed
*/

module.exports = {
default : {
client: 'mysql',
connection: {
user : 'root',
password : '',
database : 'default'
}
},

alternateConnection: {
client: 'mysql',
connection: {
user : 'root',
password : '',
database : 'alternate'
}
}
}
16 changes: 16 additions & 0 deletions test/unit/helpers/query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

/**
* adonis-lucid
* Copyright(c) 2016-2016 Harminder Virk
* MIT Licensed
*/

module.exports = {
formatQuery: function (query) {
if(process.env.DB === 'mysql') {
return query.replace(/"/g, '`')
}
return query
}
}
27 changes: 27 additions & 0 deletions test/unit/helpers/sqliteConnections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

/**
* adonis-lucid
* Copyright(c) 2016-2016 Harminder Virk
* MIT Licensed
*/
const path = require('path')

module.exports = {
default : {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '../storage/test.sqlite3')
},
useNullAsDefault: true,
debug: false
},

alternateConnection: {
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '../storage/test2.sqlite3')
},
useNullAsDefault: true
}
}
Binary file added test/unit/storage/test.sqlite3
Binary file not shown.
Binary file added test/unit/storage/test2.sqlite3
Binary file not shown.
Loading

0 comments on commit e1916ae

Please sign in to comment.