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

xndatabase

v1.0.4

Published

A simple module for creating, saving and loading custom database files with a .xn extension.

Downloads

7

Readme

xndatabase

npm dependents install size Downloads NPM Version run on repl.it

A simple module for creating, saving and loading custom database files with a .xn extension.

Installation

npm install xndatabase

Usage

const XNDatabase = require('xndatabase');

// Create a new database
const myDB = new XNDatabase('My Database');

// Add tables to the database
myDB.addTable('users', {
  name: 'string',
  age: 'number',
  email: 'string'
});

myDB.addTable('posts', {
  title: 'string',
  content: 'string',
  author: 'string'
});

// Save the database to a file
myDB.saveToFile('./my-database.xn');

// Load the database from a file
const loadedDB = XNDatabase.loadFromFile('./my-database.xn');

// Access the tables and fields in the loaded database
const usersTable = loadedDB.tables.users;
const postsTable = loadedDB.tables.posts;

const userName = usersTable.fields.name;
const postTitle = postsTable.fields.title;

API

new XNDatabase(dbName, [version])

Creates a new database with the given name and version.

  • dbName - The name of the database
  • version - The version of the database (optional)

addTable(tableName, fields)

Adds a new table to the database.

  • tableName - The name of the table
  • fields - An object containing the field names and types for the table

saveToFile(filePath)

Saves the database to a file.

  • filePath - The path to the file to save the database to

static loadFromFile(filePath)

Loads a database from a file.

  • filePath - The path to the file to load the database from

static getFileExtension()

Gets the file extension for the custom database format (.xn).

static isDatabaseFile(filePath)

Checks if a file has the custom database format (.xn).

  • filePath - The path to the file to check

Example of use in real world scenario:

const XNDatabase = require('xndatabase');

// Create a new database
const db = new XNDatabase('example');

// Add two tables to the database
db.addTable('users', {
  'id': 'integer',
  'name': 'text',
  'email': 'text'
});
db.addTable('orders', {
  'id': 'integer',
  'user_id': 'integer',
  'product': 'text',
  'quantity': 'integer'
});

// Save the database to a file
db.saveToFile('example_db.xn');

Example of use to load Database:

const XNDatabase = require('xndatabase');

// Load the database from a file
const db = XNDatabase.loadFromFile('example_db.xn');

// Access the 'users' table and print its fields
const usersTable = db.tables['users'];
console.log('Fields in the users table:');
for (const fieldName in usersTable.fields) {
  console.log(fieldName + ': ' + usersTable.fields[fieldName]);
}

// Access the 'orders' table and print its fields
const ordersTable = db.tables['orders'];
console.log('Fields in the orders table:');
for (const fieldName in ordersTable.fields) {
  console.log(fieldName + ': ' + ordersTable.fields[fieldName]);
}