npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

africa.js

v2.0.7

Published

A fulfilled query builder and ORM with support for SQL language based databases, such as SQL Server, SQLite, MySQL, MariaDB and PostgreSQL.

Downloads

7

Readme

:earth_africa: África.js

África is a fulfilled ORM and query builder that runs over SQL Server, SQLite, MySQL, MariaDB and PostgreSQL.

CLI

To install the CLI, you need to run on your bash:

$ npm install -g africa.js

Init

The init command, starts the CLI creating a .env file and the folders for migrations and seeds. You can change it after the .env file is created.

$ africa init <database_client> <host> <user> <password> <database_name>

Or, if you already have a .env file, you can just run:

$ africa init

The .env file

Heres a example of how the .env file show be like:

AFRICA_MIGRATIONS='migrations/'
AFRICA_SEEDS='seeds/'

DB_CLIENT='mysql|mariadb|postgresql|sqlite|sqlserver'
DB_HOST='localhost'
DB_USER='root'
DB_PASS=''
DB_NAME='africa'

Create Migration

To create a migration, you need to run:

$ africa create-migration example_migration
'20010911_084600-example_migration' migration file created with success!

Create Seeder

To create a seeder, you can run:

$ africa create-seeder example_seed
'20010911_101010-example_seed' seed file created with success!

Migrate

To run the migrations in the folder, you need to run:

$ africa migrate

Seed

To run the seeders in the folder, you need to run:

$ africa seed

Rollback

To rollback the migrations (in the database), you can run:

$ africa rollback

The API

The API follows the SQL syntax, so we get the same API methods for every database client.

Lets start with the connection over a MySQL client as a example:

import { Africa, MariaDB, MySQL, PostgreSQL, SQLite, SQLServer } from 'africa.js';

const mysql = new MySQL('host', 'user', 'password', 'database');
const mariadb = new MariaDB('host', 'user', 'password', 'database');
const postgre = new PostgreSQL('host', 'user', 'password', 'database');
const sqlserver = new SQLServer('host', 'user', 'password', 'database');
const sqlite = new SQLite('path/to/database_filename');

The Querie Builder

Gets SQL value of the query:

  await mysql
    .create('news', {
      'id': new Africa().int().null(false).primary_key().auto_increment(),
      'name': new Africa().varchar(255).null(false),
      'age': new Africa().varchar(255).null(false),
      'email': new Africa().varchar(255).null(false)
    });

Running queries

Create a new table:

  await mysql
    .create('news', {
      'id': new Africa().int().null(false).primary_key().auto_increment(),
      'name': new Africa().varchar(255).null(false),
      'age': new Africa().varchar(255).null(false),
      'email': new Africa().varchar(255).null(false)
    });

Read table from database:

  await mysql
    .select() // default brings all records
    .from('news');

Insert into table:

  await mysql
    .insert('news',
      {
        name: 'John Doe',
        age: 21,
        email: '[email protected]'
      }
    );

Update record in a table:

  await mysql
    .update('news', {
      name: 'Jane Doe'
    })
    .where('name', '=', 'John Doe')
    .where('email', '=', '[email protected]');

Delete in table:

  await mysql
    .delete('news')
    .cascade();

Read table from database with clausules:

  await mysql
    .select('id, name')
    .from('news')
    .where('collumn', 'operator', 'value');

Read table from database with order by clausules:

  await mysql
    .select('id, name')
    .from('news')
    .where('collumn', 'operator', 'value')
    .order_by('collumn')
    .desc();

Read table from database with INNER JOIN:

  await mysql
    .select('id, name')
    .from('news')
    .join('authors', {
      author_name: 'author'
    }); // { id: 1, title: 'example', author: 'Author Name' }

Read table from database with LEFT JOIN:

  await mysql
    .select('News.id, News.title, Authors.name')
    .as('id', 'title', 'author')
    .from('news')
    .left_join('authors', {
      'News.author': 'Authors.id'
    }); // { 'id: 1, title: 'example', author: 'Author Name' }

Read table from database with RIGHT JOIN:

  await mysql
    .select('News.id, News.title, News.content')
    .as('id', 'title', 'content')
    .from('news_categories')
    .right_join('news', {
      'NewsCategories.id': 'News.category_id'
    }); // { 'id: 1, title: 'example', author: 'Author Name' }

Read table from database with FULL OUTER JOIN:

  await mysql
    .select() // all collumns by default
    .from('table1')
    .outer_join('table2', {
      'table1.collumn': 'table2.collumn'
    });

RAW SQL:

  await mysql
    .raw('SELECT * FROM news');

COPYRIGHT

MIT License.

Made with :hearts: by John.