Skip to content

Commit

Permalink
apply formatting rules (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevensJourney committed May 9, 2024
1 parent 153b817 commit a637d32
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ jobs:
run: |
cd tests
yarn install --frozen-lockfile
- name: Install Cocoapods
- name: Install Cocoapods
run: |
cd tests/ios && pod install
Expand Down
2 changes: 1 addition & 1 deletion .mtslconfig.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"ignore_dirs":[".git","node_modules","tests"]}
{ "ignore_dirs": [".git", "node_modules", "tests"] }
14 changes: 14 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Ignore all node_modules
**/node_modules/**

# Autogenerated files
**/.expo/**
**/.next/**
**/.idea/**
**/.fleet/**

# Other
**/android/**
**/assets/**
**/bin/**
**/ios/**
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"jsxBracketSameLine": true,
"useTabs": false,
"printWidth": 120,
"trailingComma": "none"
}
4 changes: 2 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module.exports = {
plugins: [
'babel-plugin-transform-typescript-metadata',
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
],
['@babel/plugin-proposal-class-properties', { loose: true }]
]
};
9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"scripts": {
"build": "bob build",
"clean": "rm -rf lib tsconfig.tsbuildinfo",
"format": "prettier --write .",
"typescript": "tsc --noEmit",
"prepare": "bob build",
"example": "yarn --cwd example",
Expand All @@ -50,6 +51,7 @@
"@changesets/cli": "^2.26.2",
"@types/lodash": "^4.14.200",
"@types/uuid": "^9.0.1",
"prettier": "^3.2.4",
"react": "18.2.0",
"react-native": "0.71.0",
"react-native-builder-bob": "^0.18.2",
Expand All @@ -59,13 +61,6 @@
"react": "*",
"react-native": "*"
},
"prettier": {
"quoteProps": "consistent",
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"useTabs": false
},
"react-native-builder-bob": {
"source": "src",
"output": "lib",
Expand Down
2 changes: 1 addition & 1 deletion scripts/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const options = {
cwd: process.cwd(),
env: process.env,
stdio: 'inherit',
encoding: 'utf-8',
encoding: 'utf-8'
};

let result;
Expand Down
2 changes: 1 addition & 1 deletion src/DBListenerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class DBListenerManagerInternal extends DBListenerManager {
/**
* COMMIT hooks occur before the commit is completed. This leads to race conditions.
* Only use the rollback event to clear updates.
*/
*/
case TransactionEvent.ROLLBACK:
this.transactionReverted();
break;
Expand Down
8 changes: 4 additions & 4 deletions src/setup-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ export function setupOpen(QuickSQLite: ISQLite) {
const res = await callback(context);

closeContextLock(dbName, id);
resolve(res)
resolve(res);
} catch (ex) {
closeContextLock(dbName, id);
reject(ex)
reject(ex);
} finally {
hooks?.lockReleased?.()
hooks?.lockReleased?.();
}
}
} as LockCallbackRecord);
Expand Down Expand Up @@ -236,4 +236,4 @@ export function setupOpen(QuickSQLite: ISQLite) {
};
}
};
}
}
8 changes: 0 additions & 8 deletions src/type-orm.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
// _________ _______ ______ ____ _____ __ __ _____ _____
// |__ __\ \ / / __ \| ____/ __ \| __ \| \/ | /\ | __ \_ _|
// | | \ \_/ /| |__) | |__ | | | | |__) | \ / | / \ | |__) || |
// | | \ / | ___/| __|| | | | _ /| |\/| | / /\ \ | ___/ | |
// | | | | | | | |___| |__| | | \ \| | | | / ____ \| | _| |_
// |_| |_| |_| |______\____/|_| \_\_| |_| /_/ \_\_| |_____|

import _ from 'lodash';
import { QueryResult, TransactionContext, Open } from './types';

/**
Expand Down
4 changes: 1 addition & 3 deletions tests/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"assetBundlePatterns": [
"**/*"
],
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.reactnativequicksqlite.tests"
Expand Down
2 changes: 1 addition & 1 deletion tests/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function(api) {
module.exports = function (api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
Expand Down
6 changes: 3 additions & 3 deletions tests/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ config.resolver.unstable_enableSymlinks = true;
config.transformer.getTransformOptions = async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
inlineRequires: true
}
});

module.exports = config;
module.exports = config;
10 changes: 3 additions & 7 deletions tests/scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ program

program
.command('run-ios')
.option(
'--simulatorName <name>',
'The iOS simulator name (e.g., "iPhone 11")',
DEFAULT_SIMULATOR_NAME
)
.option('--simulatorName <name>', 'The iOS simulator name (e.g., "iPhone 11")', DEFAULT_SIMULATOR_NAME)
.option('--port', 'Port to run Express HTTP server for getting results on.', DEFAULT_PORT)
.action(async (str, options) => {
const opts = options.opts();
Expand All @@ -78,7 +74,7 @@ program

/** Listen for results */
const server = app.listen(port);

/** Build and run the Expo app, don't await this, we will await a response. */
spawnP('Build Expo App', 'yarn', ['ios']);

Expand Down Expand Up @@ -136,7 +132,7 @@ async function getADBDeviceName(avdName) {
}

async function getSimulatorDeviceName(simulatorName) {
try {
try {
const devicesOutput = await spawnP('List iOS Simulators', 'xcrun', ['simctl', 'list', 'devices', 'x']);
const deviceNames = _.chain(devicesOutput.split('\n'))
.map((line) => line.trim())
Expand Down
33 changes: 20 additions & 13 deletions tests/tests/sqlite/rawQueries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ let db: QuickSQLiteConnection = global.db;
const NUM_READ_CONNECTIONS = 3;

function generateUserInfo() {
return { id: chance.integer(), name: chance.name(), age: chance.integer(), networth: chance.floating() };
return {
id: chance.integer(),
name: chance.name(),
age: chance.integer(),
networth: chance.floating()
};
}

function createTestUser(context: { execute: (sql: string, args?: any[]) => Promise<QueryResult> } = db) {
Expand Down Expand Up @@ -59,7 +64,9 @@ export function registerBaseTests() {
db.delete();
}

global.db = db = open('test', { numReadConnections: NUM_READ_CONNECTIONS });
global.db = db = open('test', {
numReadConnections: NUM_READ_CONNECTIONS
});

await db.execute('DROP TABLE IF EXISTS User; ');
await db.execute('CREATE TABLE User ( id INT PRIMARY KEY, name TEXT NOT NULL, age INT, networth REAL) STRICT;');
Expand Down Expand Up @@ -480,7 +487,9 @@ export function registerBaseTests() {
});

it('Should open a db without concurrency', async () => {
const singleConnection = open('single_connection', { numReadConnections: 0 });
const singleConnection = open('single_connection', {
numReadConnections: 0
});

const [p1, p2] = [
singleConnection.writeLock(async () => {
Expand Down Expand Up @@ -570,9 +579,9 @@ export function registerBaseTests() {
await db.writeLock(async (tx) => {
await tx.execute('BEGIN');
// Creates 100,000 Users
for (let i = 0; i < numberOfUsers; i++) {
await tx.execute('INSERT INTO User (id, name, age, networth) VALUES(?, ?, ?, ?)', [i, 'steven', i, 0])
}
for (let i = 0; i < numberOfUsers; i++) {
await tx.execute('INSERT INTO User (id, name, age, networth) VALUES(?, ?, ?, ?)', [i, 'steven', i, 0]);
}
await tx.execute('COMMIT');
});

Expand All @@ -582,7 +591,9 @@ export function registerBaseTests() {
});

it('Should attach DBs', async () => {
const singleConnection = open('single_connection', { numReadConnections: 0 });
const singleConnection = open('single_connection', {
numReadConnections: 0
});
await singleConnection.execute('DROP TABLE IF EXISTS Places; ');
await singleConnection.execute('CREATE TABLE Places ( id INT PRIMARY KEY, name TEXT NOT NULL) STRICT;');
await singleConnection.execute('INSERT INTO "Places" (id, name) VALUES(0, "Beverly Hills")');
Expand All @@ -602,16 +613,12 @@ export function registerBaseTests() {
let start = performance.now();
for (let i = 0; i < 1000; ++i) {
const n = randomIntFromInterval(0, 100000);
await db.execute(`INSERT INTO t1(a, b, c) VALUES(?, ?, ?)`, [
i + 1,
n,
numberName(n),
]);
await db.execute(`INSERT INTO t1(a, b, c) VALUES(?, ?, ?)`, [i + 1, n, numberName(n)]);
}
await db.execute('PRAGMA wal_checkpoint(RESTART)');
let end = performance.now();
let duration = end - start;

expect(duration).lessThan(2000);
});
});
Expand Down
28 changes: 3 additions & 25 deletions tests/tests/sqlite/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,16 @@ export function assertAlways(condition: boolean) {
}
}

const digits = [
'',
'one',
'two',
'three',
'four',
'five',
'six',
'seven',
'eight',
'nine',
];
const digits = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
const names100: string[] = [
...digits,
...[
'ten',
'eleven',
'twelve',
'thirteen',
'fourteen',
'fifteen',
'sixteen',
'seventeen',
'eighteen',
'nineteen',
],
...['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'],
...digits.map((digit) => `twenty${digit != '' ? '-' + digit : ''}`),
...digits.map((digit) => `thirty${digit != '' ? '-' + digit : ''}`),
...digits.map((digit) => `forty${digit != '' ? '-' + digit : ''}`),
...digits.map((digit) => `fifty${digit != '' ? '-' + digit : ''}`),
...digits.map((digit) => `sixty${digit != '' ? '-' + digit : ''}`),
...digits.map((digit) => `seventy${digit != '' ? '-' + digit : ''}`),
...digits.map((digit) => `eighty${digit != '' ? '-' + digit : ''}`),
...digits.map((digit) => `ninety${digit != '' ? '-' + digit : ''}`),
...digits.map((digit) => `ninety${digit != '' ? '-' + digit : ''}`)
];
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4775,6 +4775,11 @@ prettier@^2.7.1:
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==

prettier@^3.2.4:
version "3.2.5"
resolved "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz#e52bc3090586e824964a8813b09aba6233b28368"
integrity sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==

pretty-format@^26.5.2, pretty-format@^26.6.2:
version "26.6.2"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-26.6.2.tgz#e35c2705f14cb7fe2fe94fa078345b444120fc93"
Expand Down

0 comments on commit a637d32

Please sign in to comment.