enchantedsql
v0.0.1
Published
Improved official wrapper of Qui Database
Downloads
6
Maintainers
Readme
EnchantedSQL
EnchantedSQL es una API de base de datos basada en el lenguaje "SQL" y que combina la tecnología de secuenciación de Qui Database.
¿Por qué usar EnchantedSQL?
Enchanted mejora la experiencia de gestión de datos con estas funciones:
- Nueva extensión .qui para las bases de datos (basada en la tecnología MongoDB BSON)
- Sintaxis similar a SQL, por lo que es más fácil para las personas que normalmente usan SQLite o MySQL
- Soporte de consultas y evaluaciones
Instalación
Puedes instalar el NPM ejecutando: npm install enchantedsql --save
Es recomendado utilizar la versión de NodeJS 14.15.1 LTS para este NPM.
Documentación y Ejemplos
Recuerda: Puedes encontrar diversos ejemplos y la documentación completa de Enchanted SQL en nuestra página web.
createConnection
createConnection es para establecer una conexión para hacer funcionar la base de datos.
Además, esto creará una configuración .entconfig.yaml
con algunos parámetros para aplicar.
const enchanted = require('enchantedsql')
const db = enchanted.createConnection({
host: '127.0.0.1',
port: 25560, // este es el puerto por defecto de EnchantedSQL. Puedes cambiarlo si quieres.
user: 'root', // root siempre tendrá todos los permisos de la base de datos.
pass: '' // Contraseña de la base de datos
})
connect
connect()
solo funcionará si utilizaste createConnection
antes.
db.connect()
prepare
prepare
está destinado a preparar datos para luego asignar cambios a la función de consulta.
db.prepare({ db: 'test', key: 'id1', value: '1234' })
// test es la base de datos.
// id1 es la key
// 1234 es el valor
query
query
está destinado a ejecutar el lenguaje SQL para crear archivos db. Primero debe usar la función prepare
para usar query.
// insert
db.query('INSERT ON DATABASE test PARAMETERS (id1, jake)')
// select
db.query('SELECT VALUE FROM DATABASE test WHERE KEY = id1')
// evaluate result (for checking if an object exists)
db.query('EVALUATE RESULT FROM DATABASE test WHERE KEY = id1')
// delete a database
db.query('DELETE DATABASE test')
viewSettings
viewSettings
te permite ver toda la configuración actual.
db.viewSettings()
// devuelve el archivo .entconfig.yaml
close
cierra la conexión a EnchantedSQL
Como funciona:
Linea de codigo JavaScript:
db.query('INSERT ON DATABASE foods PARAMETERS (14, popcorn)')
Lo que se almacena en la base de datos:
{"14": "Popcorn"}