Merge branch 'master' of ssh://gitea.frontblock.me:2222/fb-vendor/admin

This commit is contained in:
Daniel Hübleitner
2019-08-27 22:20:39 +02:00
11 changed files with 1912 additions and 0 deletions
+4
View File
@@ -43,7 +43,11 @@ steps:
- git config --global user.email "${DRONE_COMMIT_AUTHOR_EMAIL}"
- git config --global user.name "${DRONE_COMMIT_AUTHOR}"
- git clone https://gitea.frontblock.me/fb-dist/${DRONE_REPO_NAME}.git
- mv ./${DRONE_REPO_NAME}/.git ./bak
- rm -rf ./${DRONE_REPO_NAME}/*
- mv ./bak ./${DRONE_REPO_NAME}/.git
- cp -r ./dist/* ./${DRONE_REPO_NAME}
- cp -r ./static ./${DRONE_REPO_NAME}
- cd ./${DRONE_REPO_NAME}
- git add -A
- git commit --allow-empty -m "drone tagged as version ${DRONE_TAG}"
+1188
View File
File diff suppressed because it is too large Load Diff
+182
View File
@@ -0,0 +1,182 @@
## How to contribute to Knex.js
- Make changes in the `/lib` directory.
- Before sending a pull request for a feature or bug fix, be sure to have
[tests](https://github.com/tgriesser/knex/tree/master/test). Every pull request that changes the queries should have
also **integration tests which are ran against real database** (in addition to unit tests which checks which kind of queries
are being created).
- Use the same coding style as the rest of the
[codebase](https://github.com/tgriesser/knex/blob/master/knex.js).
- All pull requests should be made to the `master` branch.
- Pull request description should have link to corresponding PR of documentation branch.
- All pull requests that modify the public API should be updated in [types/index.d.ts](https://github.com/tgriesser/knex/blob/master/types/index.d.ts)
## Documentation
Documentation is no longer maintained in knex master repository. All the documentation pull requests should be sent to https://github.com/knex/documentation
Documentation pull requests should not be merged before knex version which has the new documented feature is released.
## I would like to add support for new dialect to knex, is it possible?
Currently there are already way too many dialects supported in `knex` and instead of adding new dialect to central codebase, all the dialects should be moved to separate npm packages out from `knex` core library with their respective maintainers and test suites.
So if you like to write your own dialect, you can just inherit own dialect from knex base classes and use it by passing dilaect to knex in knex configuration (https://runkit.com/embed/90b3cpyr4jh2):
```js
// simple dialect overriding sqlite3 dialect to use sqlite3-offline driver
require('sqlite3-offline');
const Knex = require('knex');
const Dialect = require(`knex/lib/dialects/sqlite3/index.js`);
Dialect.prototype._driver = () => require('sqlite3-offline');
const knex = Knex({
client: Dialect,
connection: ':memory:',
});
console.log(knex.select(knex.raw(1)).toSQL());
await knex.schema.createTable('fooobar', (t) => {
t.bigincrements('id');
t.string('data');
});
await knex('fooobar').insert({ data: 'nomnom' });
console.log('Gimme all the data:', await knex('fooobar'));
```
## What is minimal code to reproduce bug and why I have to provide that when I can just tell whats the problem is
Writing minimal reproduction code for the problem is time-consuming and sometimes it is also really hard, for
example when the original code where the bug happens is written using express or mocha. So why is it necessary
for me to commit so much time to it when the problem is in `knex`? Contributors should be grateful that I reported
the bug I found.
The point of runnable code to reproduce the problem is to easily verify that there really is a problem and that the one
who did the report did nothing wrong (surprisingly often problem is in the user code). So instead of just description
what to do the complete code encourages devs to actually test out that problem exists and start solving it and it
saves lots of time.
tl;dr list:
1. Actually in most of the cases developer already figures out what was the problem when writing the minimal test case
or if there was problem how stuff was initialized or how async code was written it is easy to point out the problem.
2. It motivates developer to actually try out if the bug really exist by not having to figure out from incomplete example
environment in which and how bug actually manifests.
3. There are currently very few people fixing knex issues and if one has to put easily 15-30 minutes time to issue just
to see that I cannot reproduce this issue it just wastes development hours that were available for improving knex.
Test case should initialize needed tables, insert needed data and fail...
```
const knex = require('knex')({
client: 'pg',
connection: 'postgres:///knex_test'
});
async function main() {
await knex.schema.createTable(...);
await knex('table').insert({foo: 'bar}');
await knex.destroy();
}
main();
```
Usually issues without reproduction code available are just closed and if the same issue is reported multiple
times maybe someone looks into it.
One easy way to setup database for your reproduction is to use database from knex's docker-compose setup (npm run db:start) and by checking the connection settings from tests' `test/knexfile.js`.
## Integration Tests
### The Easy Way
By default, Knex runs tests against sqlite3, postgresql, mysql, mysql2, mssql and oracledb drivers. All databases can be initialized and ran with docker.
Docker databases can be started and initialized and started with:
```bash
npm run db:start
```
and stopped with:
```bash
npm run db:stop
```
### Installing support for oracledb
Oracle has started providing precompiled driver libs for all the platforms, which makes it viable to run oracle tests also locally against oracledb running in docker.
Check message when running
```bash
npm install oracledb
```
and download driver library binary packages and unzip it to ~/lib directory.
### Specifying Databases
You can optionally specify which dialects to test using the `DB` environment variable. Values should be space separated and can include:
- mysql
- mysql2
- postgres
- sqlite3
- oracledb
- mssql
```bash
$ DB='postgres mysql' npm test
```
### Custom Configuration
If you'd like to override the database configuration (to use a different host, for example), you can override the path to the [default test configuration](https://github.com/tgriesser/knex/blob/master/test/knexfile.js) using the `KNEX_TEST` environment variable.
```bash
$ KNEX_TEST='./path/to/my/config.js' npm test
```
### Creating Postgres User
If you are running tests agains own local database one might need to setup test user and databse for knex to connect.
To create a new user, login to Postgres and use the following queries to add the user. This assumes you've already created the `knex_test` database.
```
CREATE ROLE postgres WITH LOGIN PASSWORD '';
GRANT ALL PRIVILEGES ON DATABASE "knex_test" TO postgres;
```
Once this is done, check it works by attempting to login:
```
psql -h localhost -U postgres -d knex_test
```
## Want to be Collaborator?
There is always room for more collaborators. Be active on resolving github issues / sending pull requests / reviewing code and we will ask you to join.
### Etiquette (/ˈɛtᵻkɛt/ or /ˈɛtᵻkɪt/, French: [e.ti.kɛt])
Make pull requests for your changes, do not commit directly to master (release stuff like fixing changelog are ok though).
All the pull requests must be peer reviewed by other collaborator, so don't merge your request before that. If there is no response ping others.
If you are going to add new feature to knex (not just a bugfix) it should be discussed first with others to agree on details.
Join Gitter chat if you feel to chat outside of github issues.
+22
View File
@@ -0,0 +1,22 @@
Copyright (c) 2013-present Tim Griesser
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
+93
View File
@@ -0,0 +1,93 @@
# [knex.js](http://knexjs.org)
[![npm version](http://img.shields.io/npm/v/knex.svg)](https://npmjs.org/package/knex)
[![npm downloads](https://img.shields.io/npm/dm/knex.svg)](https://npmjs.org/package/knex)
[![Build Status](https://travis-ci.org/tgriesser/knex.svg?branch=master)](https://travis-ci.org/tgriesser/knex)
[![Coverage Status](https://coveralls.io/repos/tgriesser/knex/badge.svg?branch=master)](https://coveralls.io/r/tgriesser/knex?branch=master)
[![Dependencies Status](https://david-dm.org/tgriesser/knex.svg)](https://david-dm.org/tgriesser/knex)
[![Gitter chat](https://badges.gitter.im/tgriesser/knex.svg)](https://gitter.im/tgriesser/knex)
[![Language Grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/tgriesser/knex.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/tgriesser/knex/context:javascript)
> **A SQL query builder that is _flexible_, _portable_, and _fun_ to use!**
A batteries-included, multi-dialect (MSSQL, MySQL, PostgreSQL, SQLite3, Oracle (including Oracle Wallet Authentication)) query builder for
Node.js, featuring:
- [transactions](http://knexjs.org/#Transactions)
- [connection pooling](http://knexjs.org/#Installation-pooling)
- [streaming queries](http://knexjs.org/#Interfaces-Streams)
- both a [promise](http://knexjs.org/#Interfaces-Promises) and [callback](http://knexjs.org/#Interfaces-Callbacks) API
- a [thorough test suite](https://travis-ci.org/tgriesser/knex)
- the ability to [run in the Browser](http://knexjs.org/#Installation-browser)
Node.js versions 8+ are supported.
[Read the full documentation to get started!](http://knexjs.org)
[Or check out our Recipes wiki to search for solutions to some specific problems](https://github.com/tgriesser/knex/wiki/Recipes)
If upgrading from older version, see [Upgrading instructions](https://github.com/tgriesser/knex/blob/master/UPGRADING.md)
For support and questions, join the `#bookshelf` channel on freenode IRC
For an Object Relational Mapper, see:
- http://bookshelfjs.org
- https://github.com/Vincit/objection.js
To see the SQL that Knex will generate for a given query, see: [Knex Query Lab](http://michaelavila.com/knex-querylab/)
## Examples
We have several examples [on the website](http://knexjs.org). Here is the first one to get you started:
```js
const knex = require('knex')({
dialect: 'sqlite3',
connection: {
filename: './data.db',
},
});
// Create a table
knex.schema
.createTable('users', function(table) {
table.increments('id');
table.string('user_name');
})
// ...and another
.createTable('accounts', function(table) {
table.increments('id');
table.string('account_name');
table
.integer('user_id')
.unsigned()
.references('users.id');
})
// Then query the table...
.then(function() {
return knex('users').insert({ user_name: 'Tim' });
})
// ...and using the insert id, insert into the other table.
.then(function(rows) {
return knex('accounts').insert({ account_name: 'knex', user_id: rows[0] });
})
// Query both of the rows.
.then(function() {
return knex('users')
.join('accounts', 'users.id', 'accounts.user_id')
.select('users.user_name as user', 'accounts.account_name as account');
})
// .map over the results
.map(function(row) {
console.log(row);
})
// Finally, add a .catch handler for the promise chain
.catch(function(e) {
console.error(e);
});
```
+203
View File
@@ -0,0 +1,203 @@
{
"_from": "knex@0.19.2",
"_id": "knex@0.19.2",
"_inBundle": false,
"_integrity": "sha512-TVYvlp2esS4LjjJSz8XuE48bPJq4N3lWnETQVgJ3hXPEqjiDjxcTa3bCn6F5ipQuBaMAAaFHNrqsZm7BttogdA==",
"_location": "/knex",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "knex@0.19.2",
"name": "knex",
"escapedName": "knex",
"rawSpec": "0.19.2",
"saveSpec": null,
"fetchSpec": "0.19.2"
},
"_requiredBy": [
"#USER",
"/",
"/@types/knex",
"/frontblock-generic"
],
"_resolved": "https://registry.npmjs.org/knex/-/knex-0.19.2.tgz",
"_shasum": "056efdb33fb8c77d3d76266b5d1d12dc483c21b5",
"_spec": "knex@0.19.2",
"_where": "/home/cake/FB/development/repos/vendor/admin",
"author": {
"name": "Tim Griesser",
"url": "https://github.com/tgriesser"
},
"bin": {
"knex": "./bin/cli.js"
},
"browser": {
"./lib/migrate/Migrator.js": "./lib/util/noop.js",
"./lib/bin/cli.js": "./lib/util/noop.js",
"./lib/seed/Seeder.js": "./lib/util/noop.js",
"mssql": false,
"mssql/lib/base": false,
"tedious": false,
"mysql": false,
"mysql2": false,
"pg": false,
"pg-query-stream": false,
"oracle": false,
"sqlite3": false,
"oracledb": false
},
"bugs": {
"url": "https://github.com/tgriesser/knex/issues"
},
"buildDependencies": [
"rimraf"
],
"bundleDependencies": false,
"contributors": [
{
"name": "Simon Liden"
},
{
"name": "Mikael Lepisto"
},
{
"name": "Paul Gaurab",
"url": "https://lorefnon.tech"
},
{
"name": "Igor Savin",
"url": "https://www.codeflashbacks.com"
}
],
"dependencies": {
"bluebird": "^3.5.5",
"colorette": "1.0.8",
"commander": "^2.20.0",
"debug": "4.1.1",
"getopts": "2.2.4",
"inherits": "~2.0.4",
"interpret": "^1.2.0",
"liftoff": "3.1.0",
"lodash": "^4.17.15",
"mkdirp": "^0.5.1",
"pg-connection-string": "2.0.0",
"tarn": "^2.0.0",
"tildify": "2.0.0",
"uuid": "^3.3.2",
"v8flags": "^3.1.3"
},
"deprecated": false,
"description": "A batteries-included SQL query & schema builder for Postgres, MySQL and SQLite3 and the Browser",
"devDependencies": {
"@types/node": "^10.14.13",
"JSONStream": "^1.3.5",
"chai": "^4.2.0",
"chai-subset-in-order": "^2.1.3",
"cli-testlab": "^1.7.0",
"coveralls": "^3.0.5",
"cross-env": "^5.2.0",
"dtslint": "^0.9.0",
"eslint": "^6.1.0",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-import": "^2.18.2",
"husky": "^3.0.1",
"jake": "^8.1.1",
"lint-staged": "^9.2.0",
"mocha": "^6.2.0",
"mock-fs": "^4.10.1",
"mssql": "^5.1.0",
"mysql": "^2.17.1",
"mysql2": "^1.6.5",
"nyc": "^14.1.1",
"pg": "^7.11.0",
"pg-query-stream": "^2.0.0",
"prettier": "^1.18.2",
"rimraf": "^2.6.3",
"sinon": "^7.3.2",
"sinon-chai": "^3.3.0",
"source-map-support": "^0.5.12",
"sqlite3": "^4.0.9",
"tap-spec": "^5.0.0",
"tape": "^4.11.0",
"toxiproxy-node-client": "^2.0.6",
"typescript": "^3.5.3",
"webpack-cli": "^3.3.6"
},
"engines": {
"node": ">=8"
},
"files": [
"CONTRIBUTING.md",
"README.md",
"bin/*",
"lib/*",
"lib/*",
"knex.js",
"LICENSE",
"CHANGELOG.md",
"scripts/*",
"types/index.d.ts",
"types/result.d.ts"
],
"homepage": "https://knexjs.org",
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"keywords": [
"sql",
"query",
"postgresql",
"mysql",
"sqlite3",
"oracle",
"mssql"
],
"license": "MIT",
"lint-staged": {
"*.{js,json}": [
"prettier --write",
"git add"
]
},
"main": "knex.js",
"name": "knex",
"nyc": {
"check-coverage": true,
"lines": 84,
"statements": 82,
"functions": 83,
"branches": 69
},
"react-native": {
"./lib/migrate": "./lib/util/noop.js",
"./lib/seed": "./lib/util/noop.js"
},
"repository": {
"type": "git",
"url": "git://github.com/tgriesser/knex.git"
},
"scripts": {
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"db:start": "docker-compose -f scripts/docker-compose.yml up --build -d mysql oracledbxe postgres mssql; docker-compose -f scripts/docker-compose.yml up initmssqlknexdb waitmysql waitpostgres waitoracledbxe",
"db:stop": "docker-compose -f scripts/docker-compose.yml down",
"debug:tape": "node --inspect-brk test/tape/index.js",
"debug:test": "mocha --inspect-brk --exit -t 0 test/index.js",
"format": "prettier --write \"{lib,bin,scripts,test}/**/*.js\"",
"lint": "eslint \"lib/**/*.js\" \"test/**/*.js\"",
"lint:types": "dtslint types",
"stress:destroy": "docker-compose -f scripts/stress-test/docker-compose.yml stop",
"stress:init": "docker-compose -f scripts/stress-test/docker-compose.yml up --no-start && docker-compose -f scripts/stress-test/docker-compose.yml start",
"stress:test": "node scripts/stress-test/knex-stress-test.js | grep -A 5 -B 60 -- '- STATS '",
"test": "mocha --exit -t 10000 test/index.js && npm run test:tape && npm run test:cli",
"test:cli": "cross-env KNEX_PATH=../knex.js KNEX=bin/cli.js jake -f test/jake/Jakefile",
"test:nyc": "nyc mocha --exit --check-leaks --globals __core-js_shared__ -t 10000 test/index.js && npm run test:tape && npm run test:cli",
"test:sqlite": "cross-env DB=sqlite3 npm test",
"test:tape": "node test/tape/index.js | tap-spec"
},
"tonicExampleFilename": "scripts/runkit-example.js",
"types": "types/index.d.ts",
"version": "0.19.2"
}
+97
View File
@@ -0,0 +1,97 @@
version: '3'
services:
mssql:
image: microsoft/mssql-server-linux:2017-latest
ports:
- '21433:1433'
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=S0meVeryHardPassword
healthcheck:
test: /opt/mssql-tools/bin/sqlcmd -S mssql -U sa -P 'S0meVeryHardPassword' -Q 'select 1'
initmssqlknexdb:
image: microsoft/mssql-server-linux:2017-latest
links:
- mssql
depends_on:
- mssql
entrypoint:
- bash
- -c
- 'until /opt/mssql-tools/bin/sqlcmd -S mssql -U sa -P S0meVeryHardPassword -d master -Q "CREATE DATABASE knex_test"; do sleep 5; done'
mysql:
image: mysql
command: --default-authentication-plugin=mysql_native_password
ports:
- '23306:3306'
environment:
- MYSQL_ROOT_PASSWORD=testrootpassword
- MYSQL_DATABASE=knex_test
- MYSQL_USER=testuser
- MYSQL_PASSWORD=testpassword
healthcheck:
test:
[
'CMD',
'/usr/bin/mysql',
'-hlocalhost',
'-utestuser',
'-ptestpassword',
'-e',
'SELECT 1',
]
interval: 30s
timeout: 5s
retries: 3
restart: always
waitmysql:
image: mysql
links:
- mysql
depends_on:
- mysql
entrypoint:
- bash
- -c
- 'until /usr/bin/mysql -hmysql -utestuser -ptestpassword -e "SELECT 1"; do sleep 5; done'
postgres:
image: postgres:alpine
ports:
- '25432:5432'
environment:
- POSTGRES_USER=testuser
- POSTGRES_PASSWORD=knextest
- POSTGRES_DB=knex_test
waitpostgres:
image: postgres:alpine
links:
- postgres
depends_on:
- postgres
entrypoint:
- bash
- -c
- 'until /usr/local/bin/psql postgres://testuser:knextest@postgres/knex_test -c "SELECT 1"; do sleep 5; done'
oracledbxe:
image: quillbuilduser/oracle-18-xe
container_name: oracledbxe_container
ports:
- '21521:1521'
environment:
- ORACLE_ALLOW_REMOTE=true
waitoracledbxe:
image: quillbuilduser/oracle-18-xe
links:
- oracledbxe
depends_on:
- oracledbxe
environment:
- ORACLE_HOME=/opt/oracle/product/18c/dbhomeXE
entrypoint:
- bash
- -c
- 'until /opt/oracle/product/18c/dbhomeXE/bin/sqlplus -s sys/Oracle18@oracledbxe/XE as sysdba <<< "SELECT 13376411 FROM DUAL; exit;" | grep "13376411"; do echo "Could not connect to oracle... sleep for a while"; sleep 5; done'
+24
View File
@@ -0,0 +1,24 @@
# Checklist for crating knex @next releases
1. Go through all commits since the last release and add them to CHANGELOG.md under unreleased changes section.
2. Commit changes to CHANGELOG
3. Check that master compiles and tests are running fine (check also that CI tests are passing)
```
npm run build
# run bunch of tests, but skipping coverage which doesn't really work locally at least
npm plaintest
npm bin_test
npm oracledb:test
npm mssql:init
npm mssql:test
npm mssql:destroy
```
4. Update package.json version to be e.g. 0.16.0-next1 or 0.16.0-next2 and commit yo master
5. Publish it under @next tag
```
npm publish --tag next
```
+34
View File
@@ -0,0 +1,34 @@
#!/bin/bash -e
changelog=node_modules/.bin/changelog
update_version() {
echo "$(node -p "p=require('./${1}');p.version='${2}';JSON.stringify(p,null,2)")" > $1
echo "Updated ${1} version to ${2}"
}
current_version=$(node -p "require('./package').version")
printf "Next version (current is $current_version)? "
read next_version
if ! [[ $next_version =~ ^[0-9]\.[0-9]+\.[0-9](-.+)? ]]; then
echo "Version must be a valid semver string, e.g. 1.0.2 or 2.3.0-beta.1"
exit 1
fi
next_ref="v$next_version"
git add -u
npm run build
npm test
update_version 'package.json' $next_version
git commit -am "release $next_version"
git tag $next_version
git push --tags
npm publish
+18
View File
@@ -0,0 +1,18 @@
# Test scripts to evaluate stability of drivers / pool etc.
# To run this test you need to be in this directory + have node >= 8
# and startup docker containers with proxy and sql servers
docker-compose up --no-start
docker-compose start
# Select different test script to run:
node mysql2-random-hanging-every-now-and-then.js 2> /dev/null | grep -B500 -A2 -- "- STATS"
node mysql2-sudden-exit-without-error
node knex-stress-test.js | grep -A 3 -- "- STATS "
node reconnect-test-mysql-based-drivers.js 2> /dev/null | grep -A 3 -- "- STATS "
# Shut down docker instances when done:
docker-compose down
@@ -0,0 +1,47 @@
version: '3'
services:
toxiproxy:
image: shopify/toxiproxy
ports:
- "8474:8474"
- "23306:23306"
- "25432:25432"
- "21521:21521"
- "21433:21433"
links:
- "mysql"
- "postgresql"
- "oracledbxe"
- "mssql"
mysql:
image: mysql:5.7
ports:
- "33306:3306"
environment:
- TZ=UTC
- MYSQL_ROOT_PASSWORD=mysqlrootpassword
postgresql:
image: mdillon/postgis
ports:
- "35432:5432"
environment:
- POSTGRES_PASSWORD=postgresrootpassword
- POSTGRES_USER=postgres
oracledbxe:
image: wnameless/oracle-xe-11g
ports:
- "31521:1521"
environment:
- ORACLE_ALLOW_REMOTE=true
mssql:
image: microsoft/mssql-server-linux:2017-latest
ports:
- "31433:1433"
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=S0meVeryHardPassword