Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
⏪ Revert PR #1879 and bump framework to v1.6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
sameersubudhi committed Oct 27, 2023
1 parent 04d0de9 commit 51f1920
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 43 deletions.
2 changes: 1 addition & 1 deletion framework/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ module.exports = {
sqlite3: require('./src/database/sqlite3'),
},
Utils: {
delay: require('./src/delay'),
requireAllJs: require('./src/requireAllJs'),
waitForIt: require('./src/waitForIt'),
Data: require('./src/data'),
fs: require('./src/fs'),
...require('./src/data'),
delay: require('./src/delay'),
},
Constants: {
...require('./constants/ErrorCodes'),
Expand Down
2 changes: 1 addition & 1 deletion framework/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lisk-service-framework",
"version": "1.6.3",
"version": "1.6.4",
"description": "Lisk Service Framework",
"keywords": [
"lisk",
Expand Down
14 changes: 7 additions & 7 deletions framework/src/database/sqlite3.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,24 @@ const createDBConnection = async (dbDataDir, tableName) => {
return knex;
};

const getDBConnection = async (tableName, dbDataDir = DB_DATA_DIR) => {
if (!connectionPool[dbDataDir]) {
const getDBConnection = async (tableName, dbDataDir) => {
if (!connectionPool[tableName]) {
if (!(await exists(dbDataDir))) {
await mkdir(dbDataDir, { recursive: true });
}
connectionPool[dbDataDir] = await createDBConnection(dbDataDir, tableName);
connectionPool[tableName] = await createDBConnection(dbDataDir, tableName);
}

const knex = connectionPool[dbDataDir];
const knex = connectionPool[tableName];
return knex;
};

const createTableIfNotExists = async (tableConfig, dbDataDir = DB_DATA_DIR) => {
const createTableIfNotExists = async tableConfig => {
const { tableName } = tableConfig;

if (!tablePool[tableName]) {
logger.info(`Creating schema for ${tableName}`);
const knex = await getDBConnection(tableName, dbDataDir);
const knex = await getDBConnection(tableName);
await util.loadSchema(knex, tableName, tableConfig);
tablePool[tableName] = true;
}
Expand All @@ -100,7 +100,7 @@ const getTableInstance = async (tableConfig, dbDataDir = DB_DATA_DIR) => {

const createDefaultTransaction = async connection => util.startDBTransaction(connection);

await createTableIfNotExists(tableConfig, dbDataDir);
await createTableIfNotExists(tableConfig);

const dbOperations = util.getTableInstance(tableConfig, knex);

Expand Down
27 changes: 7 additions & 20 deletions framework/tests/unit/database/sqlite3.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,22 @@ const {
} = require('../../../src/database/sqlite3');

const schema = require('../../constants/blocksSchema');
const transactionsSchema = require('../../constants/transactionsSchema');

const tableName = 'functional_test';
const transactionsTableName = 'transactions_functional_test';

const testDir = 'testDir';

schema.tableName = tableName;
transactionsSchema.tableName = transactionsTableName;

const getTable = () => getTableInstance(schema, testDir);
const getTransactionsTable = () => getTableInstance(transactionsSchema, testDir);

const { blockWithoutTransaction, blockWithTransaction } = require('../../constants/blocks');

describe('Test sqlite3 implementation', () => {
// eslint-disable-next-line no-unused-vars
let transactionsTable;
let testTable;

beforeAll(async () => {
// Create table
transactionsTable = await getTransactionsTable();
testTable = await getTable();
});

Expand All @@ -59,12 +52,6 @@ describe('Test sqlite3 implementation', () => {
const result = await testTable.find();
expect(result.length).toBe(0);
});

it('should return same connection for two different table from same db', async () => {
const functionalTableConn = await getDBConnection(tableName, testDir);
const transactionsTableConn = await getDBConnection(transactionsTableName, testDir);
expect(functionalTableConn).toBe(transactionsTableConn);
});
});

describe('With IMPLICIT DB transaction (auto-commit mode)', () => {
Expand Down Expand Up @@ -291,7 +278,7 @@ describe('Test sqlite3 implementation', () => {
it('should insert row', async () => {
const preUpsertResult = await testTable.find();
expect(preUpsertResult.length).toBe(0);
const connection = await getDBConnection(tableName, testDir);
const connection = await getDBConnection(tableName);
const trx = await startDBTransaction(connection);
await testTable.upsert([blockWithoutTransaction.header], trx);
await commitDBTransaction(trx);
Expand All @@ -309,7 +296,7 @@ describe('Test sqlite3 implementation', () => {
});

it('should update row', async () => {
const connection = await getDBConnection(tableName, testDir);
const connection = await getDBConnection(tableName);
const trx = await startDBTransaction(connection);
const { id } = blockWithTransaction.header;
await testTable.upsert([{ ...blockWithTransaction.header, height: 20 }], trx);
Expand All @@ -332,7 +319,7 @@ describe('Test sqlite3 implementation', () => {
});

it('should increment column value', async () => {
const connection = await getDBConnection(tableName, testDir);
const connection = await getDBConnection(tableName);
const trx = await startDBTransaction(connection);
const { id } = blockWithoutTransaction.header;
await testTable.increment(
Expand All @@ -349,7 +336,7 @@ describe('Test sqlite3 implementation', () => {
});

it('should delete row by primary key', async () => {
const connection = await getDBConnection(tableName, testDir);
const connection = await getDBConnection(tableName);
const trx = await startDBTransaction(connection);
const [existingBlock] = await testTable.find();
const existingBlockId = existingBlock[`${schema.primaryKey}`];
Expand All @@ -364,7 +351,7 @@ describe('Test sqlite3 implementation', () => {
});

it('should delete rows', async () => {
const connection = await getDBConnection(tableName, testDir);
const connection = await getDBConnection(tableName);
const trx = await startDBTransaction(connection);

await testTable.upsert([blockWithoutTransaction.header, blockWithTransaction.header]);
Expand All @@ -385,7 +372,7 @@ describe('Test sqlite3 implementation', () => {
});

it('should delete row', async () => {
const connection = await getDBConnection(tableName, testDir);
const connection = await getDBConnection(tableName);
const trx = await startDBTransaction(connection);

await testTable.upsert([blockWithoutTransaction.header]);
Expand All @@ -406,7 +393,7 @@ describe('Test sqlite3 implementation', () => {
});

it('should insert rows in a batch', async () => {
const connection = await getDBConnection(tableName, testDir);
const connection = await getDBConnection(tableName);
const trx = await startDBTransaction(connection);
const preUpsertResult = await testTable.find();
expect(preUpsertResult.length).toBe(0);
Expand Down
28 changes: 14 additions & 14 deletions framework/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,11 @@
"@types/istanbul-lib-report" "*"

"@types/node@*", "@types/node@>=10.0.0":
version "20.8.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.8.8.tgz#adee050b422061ad5255fc38ff71b2bb96ea2a0e"
integrity sha512-YRsdVxq6OaLfmR9Hy816IMp33xOBjfyOgUd77ehqg96CFywxAPbDbXvAsuN2KVg2HOT8Eh6uAfU+l4WffwPVrQ==
version "20.8.9"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.8.9.tgz#646390b4fab269abce59c308fc286dcd818a2b08"
integrity sha512-UzykFsT3FhHb1h7yD4CA4YhBHq545JC0YnEz41xkipN88eKQtL6rSgocL5tbAP6Ola9Izm/Aw4Ora8He4x0BHg==
dependencies:
undici-types "~5.25.1"
undici-types "~5.26.4"

"@types/prettier@^2.1.5":
version "2.7.3"
Expand Down Expand Up @@ -706,9 +706,9 @@ acorn@^7.1.1:
integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==

acorn@^8.2.4:
version "8.10.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.10.0.tgz#8be5b3907a67221a81ab23c7889c4c5526b62ec5"
integrity sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==
version "8.11.2"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.11.2.tgz#ca0d78b51895be5390a5903c5b3bdcdaf78ae40b"
integrity sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==

agent-base@6:
version "6.0.2"
Expand Down Expand Up @@ -1362,9 +1362,9 @@ [email protected]:
integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==

electron-to-chromium@^1.4.535:
version "1.4.566"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.566.tgz#5c5ba1d2dc895f4887043f0cc7e61798c7e5919a"
integrity sha512-mv+fAy27uOmTVlUULy15U3DVJ+jg+8iyKH1bpwboCRhtDC69GKf1PPTZvEIhCyDr81RFqfxZJYrbgp933a1vtg==
version "1.4.568"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.568.tgz#6ab444e120dd7fd9c3789eac54d3132b6cfcd0f9"
integrity sha512-3TCOv8+BY6Ltpt1/CmGBMups2IdKOyfEmz4J8yIS4xLSeMm0Rf+psSaxLuswG9qMKt+XbNbmADybtXGpTFlbDg==

emittery@^0.8.1:
version "0.8.1"
Expand Down Expand Up @@ -4120,10 +4120,10 @@ unbox-primitive@^1.0.2:
has-symbols "^1.0.3"
which-boxed-primitive "^1.0.2"

undici-types@~5.25.1:
version "5.25.3"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.25.3.tgz#e044115914c85f0bcbb229f346ab739f064998c3"
integrity sha512-Ga1jfYwRn7+cP9v8auvEXN1rX3sWqlayd4HP7OKk4mZWylEmu3KzXDUGrQUN6Ol7qo1gPvB2e5gX6udnyEPgdA==
undici-types@~5.26.4:
version "5.26.5"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==

universalify@^0.1.0:
version "0.1.2"
Expand Down

0 comments on commit 51f1920

Please sign in to comment.