Skip to content

Commit

Permalink
changes to naming and updates regarding feedback from Draft PR
Browse files Browse the repository at this point in the history
  • Loading branch information
chintannp committed Feb 11, 2022
1 parent 3560af9 commit b212dd3
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 68 deletions.
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"editor.formatOnSave": true,
"editor.insertSpaces": false,
"typescript.tsdk": "node_modules/typescript/lib",
"prettier.requireConfig": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
},
"typescript.format.insertSpaceBeforeAndAfterBinaryOperators": false,
"javascript.format.insertSpaceBeforeAndAfterBinaryOperators": false
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,8 @@
"jest": {
"resetMocks": true,
"verbose": true
},
"dependencies": {
"@react-native-async-storage/async-storage": "^1.15.17"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
deleteByPredicateStatement,
modelCreateTableStatement,
implicitAuthFieldsForModel,
} from '../src/commons/SQLiteUtils';
} from '../src/common/SQLiteUtils';
import {
InternalSchema,
PersistentModelConstructor,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommonSQLiteAdapter } from '../commons/CommonSQLiteAdapter';
import { CommonSQLiteAdapter } from '../common/CommonSQLiteAdapter';
import ExpoSQLiteDatabase from './ExpoSQLiteDatabase';

const ExpoSQLiteAdapter: CommonSQLiteAdapter = new CommonSQLiteAdapter(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as SQLite from 'expo-sqlite';
import { ConsoleLogger as Logger } from '@aws-amplify/core';
import { PersistentModel } from '@aws-amplify/datastore';
import { ParameterizedStatement } from '../commons/SQLiteUtils';
import { Database } from '../commons/Database';
import { ParameterizedStatement } from '../common/SQLiteUtils';
import { CommonSQLiteDatabase } from '../common/types';

const logger = new Logger('ExpoSQLiteDatabase');

Expand All @@ -20,7 +20,7 @@ I purposely used arrow functions () => {} in this class as expo-sqlite library i
*/

class ExpoSQLiteDatabase implements Database {
class ExpoSQLiteDatabase implements CommonSQLiteDatabase {
private db: SQLite.WebSQLDatabase;

public async init(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommonSQLiteAdapter } from '../commons/CommonSQLiteAdapter';
import { CommonSQLiteAdapter } from '../common/CommonSQLiteAdapter';
import SQLiteDatabase from './SQLiteDatabase';

const SQLiteAdapter: CommonSQLiteAdapter = new CommonSQLiteAdapter(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import SQLite from 'react-native-sqlite-storage';
import { ConsoleLogger as Logger } from '@aws-amplify/core';
import { PersistentModel } from '@aws-amplify/datastore';
import { ParameterizedStatement } from '../commons/SQLiteUtils';
import { Database } from '../commons/Database';
import { ParameterizedStatement } from '../common/SQLiteUtils';
import { CommonSQLiteDatabase } from '../common/types';

const logger = new Logger('SQLiteDatabase');

Expand Down Expand Up @@ -32,7 +32,7 @@ get the result of an `executeSql` command inside of a transaction
*/

class SQLiteDatabase implements Database {
class SQLiteDatabase implements CommonSQLiteDatabase {
private db: SQLite.SQLiteDatabase;

public async init(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
deleteByIdStatement,
deleteByPredicateStatement,
ParameterizedStatement,
} from '../commons/SQLiteUtils';
} from '../common/SQLiteUtils';

import {
StorageAdapter,
Expand All @@ -30,7 +30,7 @@ import {
QueryOne,
utils,
} from '@aws-amplify/datastore';
import { Database } from './Database';
import { CommonSQLiteDatabase } from './types';

const { traverseModel, validatePredicate, isModelConstructor } = utils;

Expand All @@ -44,7 +44,7 @@ export class CommonSQLiteAdapter implements StorageAdapter {
namsespaceName: string,
modelName: string
) => PersistentModelConstructor<any>;
private db: Database;
private db: CommonSQLiteDatabase;
private initPromise: Promise<void>;
private resolve: (value?: any) => void;
private reject: (value?: any) => void;
Expand Down
54 changes: 54 additions & 0 deletions packages/datastore-storage-adapter/src/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { GraphQLScalarType } from '@aws-amplify/datastore';
import { PersistentModel } from '@aws-amplify/datastore';
import { ParameterizedStatement } from './SQLiteUtils';

export function getSQLiteType(
scalar: keyof Omit<
typeof GraphQLScalarType,
'getJSType' | 'getValidationFunction' | 'getSQLiteType'
>
): 'TEXT' | 'INTEGER' | 'REAL' | 'BLOB' {
switch (scalar) {
case 'Boolean':
case 'Int':
case 'AWSTimestamp':
return 'INTEGER';
case 'ID':
case 'String':
case 'AWSDate':
case 'AWSTime':
case 'AWSDateTime':
case 'AWSEmail':
case 'AWSJSON':
case 'AWSURL':
case 'AWSPhone':
case 'AWSIPAddress':
return 'TEXT';
case 'Float':
return 'REAL';
default:
const _: never = scalar as never;
throw new Error(`unknown type ${scalar as string}`);
}
}

export interface CommonSQLiteDatabase {
init(): Promise<void>;
createSchema(statements: string[]): Promise<void>;
clear(): Promise<void>;
get<T extends PersistentModel>(statement: string, params: any[]): Promise<T>;
getAll<T extends PersistentModel>(
statement: string,
params: any[]
): Promise<T[]>;
save(statement: string, params: any[]): Promise<void>;
batchQuery(queryStatements: Set<ParameterizedStatement>): Promise<any[]>;
batchSave(
saveStatements: Set<ParameterizedStatement>,
deleteStatements?: Set<ParameterizedStatement>
): Promise<void>;
selectAndDelete(
query: ParameterizedStatement,
_delete: ParameterizedStatement
): Promise<any[]>;
}
23 changes: 0 additions & 23 deletions packages/datastore-storage-adapter/src/commons/Database.ts

This file was deleted.

31 changes: 0 additions & 31 deletions packages/datastore-storage-adapter/src/commons/types.ts

This file was deleted.

0 comments on commit b212dd3

Please sign in to comment.