nav-orm

Currently, only mysql is supported.

Usage no npm install needed!

<script type="module">
  import navOrm from 'https://cdn.skypack.dev/nav-orm';
</script>

README

ORM

Currently, only mysql is supported.

npm install nav-orm --save

Setup

You must set the following environment variables in your app. We recommend creating a .env file and using dotenv

DB_DRIVER=mysql
DB_HOST=localhost
DB_USERNAME=test
DB_PASSWORD=secret
DB_NAME=blah

Create a Model

chat.js

import { Model } from 'orm'

export default class Chat extends Model {

  /*
  overwrite table name, this function is optional

  static tableName() {
    return 'dashboard_chats'
  }
  */
}


Using the Model

As long as the plural version of the model is available in the database (you can overwrite this), you can query the database.

import Chat from './chat'

async function getChats {
  let chats = await Chat.all()
  console.log(chats)
}

Supported methods

.all() - returns everything in the table .where({ fieldName: 'value' }) - returns any matching results .create({ field: 'value'}) - create a new row