Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
fluent-sql
Advanced tools
Readme
This library basically takes your fluent SQL and generates SQL strings and replacement
Create your table
const users = new SqlTable({
TableName: 'users',
columns: [{ ColumnName: 'id' }, { ColumnName: 'username' }, { ColumnName: 'password' }],
});
const bank = new SqlTable({
TableName: 'bank_account',
columns: [{ ColumnName: 'id' }, { ColumnName: 'user_id' }, { ColumnName: 'account_no' }, { ColumnName: 'balance' }],
});
Create your query. SqlQuery takes an options object.
SqlQuery object to copy options from OR
an object of options
Non-record set paging
select * from some-table where x > 1
offset 0 rows
fetch next 50 rows only
select * from some-table where x > 1
limit 50 offset 0
SELECT * FROM (
SELECT *, row_number() OVER (ORDER BY name ASC) as Paging_RowNumber FROM (
select * from some-table where x > 1
) base_query
) as detail_query WHERE Paging_RowNumber BETWEEN 0 AND 50
import { setPostgres, setSqlServer } from 'fluent-sql';
setPostgres(); // from here forward sqlQuery will use postgres options
export const postgresOptions = {
sqlStartChar: '"',
sqlEndChar: '"',
namedValues: true,
namedValueMarker: '$',
markerType: 'number',
dialect: 'pg',
recordSetPaging: false,
};
export const sqlServerOptions = {
sqlStartChar: '[',
sqlEndChar: ']',
escapeLevel: ['table-alias', 'column-alias'],
namedValues: true,
namedValueMarker: ':',
markerType: 'name',
dialect: 'MS',
recordSetPaging: false,
};
const query = new SqlQuery()
.select(users.id, users.username, users.password)
.from(users)
.where(users.username.eq('jsmith'));
Get your SQL
const sql = query.genSql(decryptFunction, maskingFunction);
Sql looks like the following (MS Dialect)
{
fetchSql:
'SELECT\n[users].id as [id],\n[users].username as [username],\n[users].password as [password]\nFROM\nusers as [users]\nWHERE [users].username = (:username0)',
countSql: undefined,
hasEncrypted: false,
values: {
username0: 'jsmith'
}
}
Sql looks like the following (Postgres)
{
fetchSql:
'SELECT\n"users".id as "id",\n"users".username as "username",\n"users".password as "password"\nFROM\nusers as "users"\nWHERE "users".username = ($1)',
countSql: undefined,
hasEncrypted: false,
values: [ 'jsmith' ]
}
Decrypt & Masking functions are just a function that takes 2 parameters, SqlColumn and boolean on weather or not to use a fully qualified column name (ie. table.col), you can do anything in these and return null or a SQL literal to insert for that column in the generated SQL. Both functions can be NULL
The sql returned is an object
Aggregate example
const query = new SqlQuery().select(bank.balance.sum().by(bank.userId)).from(bank);
generates:
SELECT SUM(bank_account.balance) as balance_sum
FROM bank_account as bank_account
GROUP BY bank_account.user_id
Limits & paging
const query = new SqlQuery()
.select(users.id)
.page(5)
.pageSize(10);
Update/Insert
const insert = bank.insert({ id: 1, userId: 1, accountNo: 1, balance: 1000.0 });
const update = bank.update({ id: 1, balance: 1000.0 });
Look through the tests for more examples, the tests should have every possible option exercised
npm install fluent-sql
SqlTable
classes from database (supports Sqlite and postgres)npm i -D simple-db-migrate
(I used my command line parsing from this module)npm i -D sqlite3
or npm i -D pg
if you are not using one of these alreadyfluent-sql-gen
toggle on
one of [pg, sqlite]
string
string
string
string
number
https://www.npmjs.com/package/simple-db-migrate
did a terrible job up till now on this
3.0.0
2.6.0
SqlTable
classes from database2.5.0
FAQs
Fluent SQL lib
The npm package fluent-sql receives a total of 39 weekly downloads. As such, fluent-sql popularity was classified as not popular.
We found that fluent-sql demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.