Giter Club home page Giter Club logo

database-js's People

Contributors

mlaanderson avatar pahan35 avatar thiagodp avatar zachary-d avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

database-js's Issues

Global connection already exists. Call sql.close() first.

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?

There is an issue with the string connection

I think there is an error using a string connection , I had to change my password in order to make it work

for example my password : gwW^/0/L

was not working
image

I think it would be cool if you could receive an object so in that way the regex wont fail and it would be easier to pass the parameters

Add topics

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

Improve subprojects' keywords

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:

NPM uses the keywords from package.json.

Beter examples

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() only escapes the first special character of each type in a string

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.

hang await statement.query always loading

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();
}

SQLite support seems broken

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 ?

Add support to TXT files

Proposal

database-js-txt

Virtual Columns

Text files could have these virtual columns:

  1. line (any line of the file)
  2. 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

Basic Operators

=, <>, >, >=, <, <=, LIKE, NOT, AND, OR, BETWEEN

Basic Constructions

WHERE, ORDER BY

Basic Functions

COUNT, MAX

Expected future enhancements

  • MATCHES operator, for matching a given regular expression.
    E.g., SELECT * WHERE line MATCHES "^Created at [0-9]{1,2}:[0-9]{1,2}"

Cannot list tables

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?

Hack for drivers be tested properly

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?

Simpler driver names

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 files
  • xml for XML files
  • odbc for ODBC access to databases
  • oracle for Oracle databases
  • sqlserver for MS SQL Server databases
  • firebirdsql for Firebird databases
  • mariadb for MariaDB (as an alternative driver to MySQL)

Add Travis build

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.

Unhandled Promise

I have been looking at node-adodb and came across this project.
The use of promises is interesting.
I want to try with Access and Firebase.
How do I get started?

Testing the firebase example with RunKit.

Error:

capture199

Accept connection parameters from a plain object

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.