1.11.1 • Published 10 months ago

@hedystia/db v1.11.1

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

Installation

npm i @hedystia/db

yarn add @hedystia/db

Nodejs Version

  • v18.0.0 or higher

Links

Example

const Database = require("@hedystia/db");

// Create a file named database.ht and enter the password
const database = new Database("./database.ht", "password");

// You can only use it once to create the table after that you can no longer use it.
database.createTable("users", ["id", "name", "email"]);

database.insert("users", { id: "1", name: "John Doe", email: "jdoe@example.com" });

database.insert("users", { id: "2", name: "María", email: "maria@example.com" });

const users = database.select("users");

console.log("----------------------------------");

console.log(users);

database.addColumn("users", "phone");

database.addColumn("users", "lang", "en-US");

const newUsersPhone = database.select("users");

console.log("----------------------------------");

console.log(newUsersPhone);

database.deleteColumn("users", "phone");

const oldUsersPhone = database.select("users");

console.log("----------------------------------");

console.log(oldUsersPhone);

const userJohn = database.select("users", { name: "John Doe" });

console.log("----------------------------------");

console.log(userJohn);

database.delete("users", { name: "María" });

const users2 = database.select("users");

console.log("----------------------------------");

console.log(users2);

database.update("users", { id: "1" }, { name: "Jane Doe", lang: "es-ES" });

const users3 = database.select("users");

console.log("----------------------------------");

console.log(users3);

database.dropAll();

const users4 = database.select("users");

console.log("----------------------------------");

console.log(users4);

database.enableMigrations();

database.createMigration(
	{
		id: "cdaa5095-0c11-4878-8d89-c9be41215e57",
		description: "Description",
		timestamp: Date.now(),
	},
	() => {
		database.createTableIfNotExists("test_migration", ["name"]);
		database.insert("test_migration", { name: "John" });
	},
);

const migrations = database.select("migrations");

console.log("----------------------------------");

console.log(migrations);

const testMigration = database.select("test_migration");

console.log("----------------------------------");

console.log(testMigration);

Functions

FunctionDescription
dropAllTo drop all data from a table
readTablesTo read the tables from the database
enableMigrationsTo enable migrations
createMigrationTo create a migration
createTableTo create a table
deleteTableTo delete a table
createTableIfNotExistsTo create a table if it does not exist
deleteTableIfExistsTo delete a table if it exists
renameTableTo rename a table
addColumnTo add a column to an already created table
deleteColumnTo remove a column to an already created table
renameColumnTo rename a column
insertTo insert a data in the table
updateTo update a data in the table
selectTo search for information in a table
deleteTo delete a data from the table
getTableNamesTo get the names of all tables
getColumnNamesTo get the names of all columns
getRecordCountTo get the number of records in a table
1.11.1

10 months ago

1.11.0

10 months ago

1.9.0

1 year ago

1.10.0

12 months ago

1.8.0

1 year ago

1.7.0

1 year ago

1.6.2

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.5.0

1 year ago

1.4.0

1 year ago

1.3.7

1 year ago

1.3.6

1 year ago