mlaanderson / database-js Goto Github PK
View Code? Open in Web Editor NEWCommon Database Interface for Node
License: MIT License
Common Database Interface for Node
License: MIT License
I have a test like:
async myFunction() {
...
try {
conn = new Connection(connStr);
statement = conn.prepareStatement(orderIdsQuery);
do {
results = await statement.query();
}
while ([undefined, null].includes(results));
let randomIndex = getRandomInt(0, results.length - 1);
let orderId = results[randomIndex].Id;
let multiDrive = results[randomIndex].DriverAmount === 1;
statement = conn.prepareStatement(orderPeopleQuery);
do {
results = await statement.query(orderId);
}
while ([undefined, null].includes(results));
result = {'orderId': orderId, 'multiDrive': multiDrive, 'people': results};
}
catch (reason) {
console.log(reason);
}
finally {
if (conn) {
await conn.close();
}
}
return result;
}
Before() {
...
let res = await myFunction();
...
}
Scenario() {
...
}.retry(1)
It is expected that test to work like this:
If it fails - it starts again, completes request once more, and then goes to scenario steps, but
I got this exception after test restarted:
Error: Global connection already exists. Call sql.close() first.
at Object.connect (/Users/orkhan.mamedov/WebstormProjects/SravniClient/node_modules/database-js-mssql/node_modules/mssql/lib/base.js:1639:10)
at MsSql._pool (/Users/orkhan.mamedov/WebstormProjects/SravniClient/node_modules/database-js-mssql/index.js:61:33)
at MsSql.query (/Users/orkhan.mamedov/WebstormProjects/SravniClient/node_modules/database-js-mssql/index.js:73:31)
at /Users/orkhan.mamedov/WebstormProjects/SravniClient/node_modules/database-js/lib/statement.js:69:38
at new Promise (<anonymous>)
at PreparedStatement.query (/Users/orkhan.mamedov/WebstormProjects/SravniClient/node_modules/database-js/lib/statement.js:60:16)
...
It seems as a bug, can you help me with that?
Is this deprecated in favor of the current version,
or is it something different entirely?
Add topics in order to find database-js easily in GitHub searches. Suggested (copy & paste?):
database javascript node sql wrapper mysql postgresql sqlite firebase json csv ini excel msaccess
With help of compiled by JSweet partial OpenJDK code of JDBC.
When trying to search "database-js"
in NPM, the subprojects don't appear. Maybe adding the keyword database-js
to them would make they do.
So, in order to improve the discoverability of database-js and subprojects, I suggest that:
database-js
as a keyword;
database-js-mysql
, etc.). DONENPM uses the keywords from package.json
.
Please,
Can you provide better examples, how to use database-js?
Something like this https://www.w3schools.com/nodejs/nodejs_mysql_create_db.asp
How to create database, create table, insert into table a single row and insert multiple rows from array, update data, delete data ...
database-je nice because support a lot of different drivers.
Thanks in advance,
VladanO
QuoteString()
uses the string.replace()
method to escape special characters, but passes the patterns to it as strings. When the pattern is given as a string, only the first instance of the pattern is replaced.
The patterns need to be converted to regex patterns/objects in order for every instance to be replaced properly. For example, string = string.replace("'", "''");
becomes string = string.replace(/'/g, "''");
.
I'm preparing a PR and will be submitting it soon if you'd be willing to accept it.
Please adopt Semantic Versioning in this project and in related projects. New versions could be released as tags.
conn = new Connection("database-js-postgres://postgres:password@ip:5432/db");
try {
statement = await conn.prepareStatement("SELECT * FROM connection WHERE name = ?");
rows = await statement.query('datasama');
console.log(rows);
} catch (error) {
console.log(error);
} finally {
await connection.close();
}
Hi,
it seems that database-js-sqlite is no more usable (use a too old sql.js), at least with database-js. Could you find an other driver ?
database-js-txt
Text files could have these virtual columns:
line
(any line of the file)line_number
Examples:
# Line starting with Hello
SELECT `line_number`, `line` WHERE `line` LIKE "Hello%"
# First line in the file
SELECT `line` WHERE `line_number` = 1
# Number of lines in the file
SELECT COUNT( `line` )
# Number of lines in the file, different way
SELECT MAX( `line_number` )
# Last line in the file
SELECT `line` WHERE `line_number` = COUNT( `line` )
# Content from some lines
SELECT `line` WHERE `line_number` BETWEEN 5 AND 10
# Content from some lines, different way (needed?)
SELECT `line` OFFSET 5 LIMIT 5
=
, <>
, >
, >=
, <
, <=
, LIKE
, NOT
, AND
, OR
, BETWEEN
WHERE
, ORDER BY
COUNT
, MAX
MATCHES
operator, for matching a given regular expression.SELECT * WHERE line MATCHES "^Created at [0-9]{1,2}:[0-9]{1,2}"
I'm currently working with xlsx tables and I need a query like "SHOW TABLES".
I did not find it, is there a particular reason?
database-js-csv
?
Maybe in a project named database-js-json
Maybe in a project named database-js-xml
database-js
does not support transactions yet, right?
:-)
Database-js has drivers as separated projects. It does not need to include them as dev
dependencies.
On the other side, the drivers should include database-js
as a dev
dependency, for testing purposes (or they have to me maintained inside database-js, but never committed). However, database-js
loads the drivers according to the driverName
, including (with require
) the respective file. Since the driver's index.js
is not inside database-js
, it is not able to find it and, thus, to load the driver.
There is a little hack, however, to solve this problem. I have used it in database-js-json, inside its mocha test file:
var obj = {
// hack to load the index of the driver as a module of database-js
driverName: '../../../index',
. . .
};
var conn = new dbjs.Connection( obj );
. . .
It would be nice having another solution to the driver loading problem. I the mean time, this hack can be useful to add proper tests in each driver project. @mlaanderson What do you think?
Instead of using database-js-driver://
, the project could adopt just driver://
.
Examples (JDBC-like):
mysql
for MySQL databases (currently database-js-mysql
)postgresql
for PostgreSQL databases (currently database-js-postgres
)sqlite
for SQLite databases (currently database-js-sqlite
)firebase
for Firebase databases (currently database-js-firebase
)ado
for ActiveX Data Objects, like MS Excel tables and MS Access databases (currently database-js-adodb
)ini
for INI files (currently database-js-ini
)Other examples (for future use?):
json
for JSON filesxml
for XML filesodbc
for ODBC access to databasesoracle
for Oracle databasessqlserver
for MS SQL Server databasesfirebirdsql
for Firebird databasesmariadb
for MariaDB (as an alternative driver to MySQL)Activate this project in Travis, in order to let it check the build status. Then we can add an image of the build status to the README.md
file.
@mlaanderson I've already added the file .travis.yml
to the project.
Just to document, I've already added a PR.
The original projected named 'database-js' is abandoned. Acessing its project page returns a 404.
NPM has a policy about disputes that states This process is an excellent way to: - Adopt an "abandoned" package (...)
, among other things. So, I think this is a good opportunity to get the name database-js
.
If database-js-ini is stable enough, database-js
could be updated to include it.
E.g.: update README.md
and package.json
Add support to Google Spreadsheets through tabletop.
I'm currently building a version here, but I couldn't test it yet. I'll try to release it ASAP.
Currently, Connection
currently receives a connectionString
:
class Connection {
constructor(connectionString, driver) {
this.__base = ParseConnection(connectionString, driver);
. . .
}
. . .
}
Sometimes it is desirable to create a connection passing parameters, such as in ConnectionObject
, or maybe using a plain object.
So, to adjusting Connection
's constructor to accept both a string or a ConnectionObject
would be:
class Connection {
constructor(conn, driver) {
this.__base = 'string' === typeof conn ? ParseConnection(conn, driver) : conn;
. . .
}
. . .
}
To receiving a plain object with connection properties, I think it would be better changing ConnectionObject
instead of Connection
. In this case, ConnectionObject
could have a static constructor-like method:
class ConnectionObject {
...
static fromPlain( obj, driver ) {
return new ConnectionObject(
obj[ 'driverName' ],
obj[ 'username' ],
obj[ 'password' ],
obj[ 'hostname' ],
obj[ 'port' ],
obj[ 'database' ],
obj[ 'parameters' ],
driver
);
}
. . .
}
And then we could create a connection from a plain object:
let p = require( 'mydb.json' ); // a JSON file with database connection properties
let c = new Connection( ConnectionObject.fromPlain( p, driver ), driver );
// or just
let c = new Connection( ConnectionObject.fromPlain( require( 'mydb.json' ), driver ) );
Wouldn't it be nice?
With Node 9 and 10 out we need to test against them as well.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.