Skip to content

Commit

Permalink
update docs and package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-jha98 committed Jan 12, 2021
1 parent 9527cf5 commit b42e141
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 52 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<p class='logo'>
<img alt="logo" src="https://raw.githubusercontent.com/rahul-jha98/google-sheets-db/main/docs/assets/imgs/logo.svg" width="580">
<img alt="logo" src="https://raw.githubusercontent.com/rahul-jha98/sheets-database/main/docs/assets/imgs/logo.svg" width="480">
</p>

[![License](https://img.shields.io/badge/license-MIT-green)](https://raw.githubusercontent.com/rahul-jha98/google-sheets-db/main/LICENSE)
[![License](https://img.shields.io/badge/license-MIT-green)](https://raw.githubusercontent.com/rahul-jha98/sheets-database/main/LICENSE)

> Library to help use a Google Sheet as a database (or CMS)
Expand All @@ -14,10 +14,10 @@
- Provides method to reduce memory and network usage to optimize for your use case.

**Docs site -**
Full docs available at [https://rahul-jha98.github.io/google-sheets-db/](https://rahul-jha98.github.io/google-sheets-db/)
Full docs available at [https://rahul-jha98.github.io/sheets-database/](https://rahul-jha98.github.io/sheets-database/)


> 🚀 **Installation** - `npm i google-sheets-db --save` or `yarn add google-sheets-db`
> 🚀 **Installation** - `npm i sheets-database --save` or `yarn add sheets-database`
## Examples
_the following examples are meant to give you an idea of just some of the things you can do_
Expand All @@ -27,13 +27,13 @@ _the following examples are meant to give you an idea of just some of the things

### Working with Tables
```javascript
const { SheetDatabase } = require('google-sheets-db');
const { SheetDatabase } = require('sheets-database');

// Initialize the Database with doc ID (long id in the sheets URL)
const db = new SheetDatabase('<the sheet ID from the url>');

// Initialize Auth
// see more available options at https://rahul-jha98.github.io/google-sheets-db/#/getting-started/authentication
// see more available options at https://rahul-jha98.github.io/sheets-database/#/getting-started/authentication
await db.useServiceAccount({
client_email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL,
private_key: process.env.GOOGLE_PRIVATE_KEY,
Expand All @@ -58,7 +58,7 @@ await db.dropTable('newTable2');
```
More info:
- [Authentication](https://rahul-jha98.github.io//#/getting-started/authentication)
- [SheetDatabase](https://rahul-jha98.github.io/google-sheets-db//#/classdocs/sheetdatabase)
- [SheetDatabase](https://rahul-jha98.github.io/sheets-database//#/classdocs/sheetdatabase)


### Working with Table Entries
Expand Down Expand Up @@ -112,7 +112,7 @@ console.log(table.getData());
*/
```
More Info:
- [Table](https://rahul-jha98.github.io/google-sheets-db//#/classdocs/table)
- [Table](https://rahul-jha98.github.io/sheets-database//#/classdocs/table)

## Why?
> The library will let you worry only about the CRUD operation you wish to perfrom and handles the task of updating it to the spreadsheet internally.
Expand All @@ -124,9 +124,8 @@ But the Google Sheet's API v4 is a bit awkward with confusing docs, at least to
The library aims to remove the learning curve completely by providing methods that lets you interact with the database without worrying about the Sheets API at all.
Moreover the API of the library is quite intuitive to get started with and provides functionalities for most of the database operations.


## Note
`google-sheets-db` is heavily inspired by and borrows some code from [node-google-spreadsheet](https://github.com/theoephraim/node-google-spreadsheet).
`sheets-database` is heavily inspired by and also borrows some code from [node-google-spreadsheet](https://github.com/theoephraim/node-google-spreadsheet).

## Contributions

Expand All @@ -137,3 +136,6 @@ Also, since I am new to Typescript and still exploring any help in improving the

The docs site is generated using [docsify](https://docsify.js.org). To preview and run locally so you can make edits, install docsify_cli and run `docsify serve ./docs` in the project root folder and head to https://localhost:3000
The content lives in markdown files in the docs folder.

## License
[MIT](https://github.com/rahul-jha98/sheets-database/blob/main/LICENSE)
24 changes: 13 additions & 11 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
_Welcome to the documentation site for_
<p class='logo'>
<img alt="logo" src="./assets/imgs/logo.svg" width="580">
<img alt="logo" src="./assets/imgs/logo.svg" width="480">
</p>

[![License](https://img.shields.io/badge/license-MIT-green)](https://raw.githubusercontent.com/rahul-jha98/google-sheets-db/main/LICENSE)
[![License](https://img.shields.io/badge/license-MIT-green)](https://raw.githubusercontent.com/rahul-jha98/sheets-database/main/LICENSE)

> Library to help use a Google Sheet as a database (or CMS)
Expand All @@ -15,10 +15,10 @@ _Welcome to the documentation site for_
- Provides method to reduce memory and network usage to optimize for your use case.

<!-- **Docs site -**
Full docs available at [https://rahul-jha98.github.io/google-sheets-db/](https://rahul-jha98.github.io/google-sheets-db/) -->
Full docs available at [https://rahul-jha98.github.io/sheets-database/](https://rahul-jha98.github.io/sheets-database/) -->


> 🚀 **Installation** - `npm i google-sheets-db --save` or `yarn add google-sheets-db`
> 🚀 **Installation** - `npm i sheets-database --save` or `yarn add sheets-database`
## Examples
_the following examples are meant to give you an idea of just some of the things you can do_
Expand All @@ -28,13 +28,13 @@ _the following examples are meant to give you an idea of just some of the things

### Working with Tables
```javascript
const { SheetDatabase } = require('google-sheets-db');
const { SheetDatabase } = require('sheets-database');

// Initialize the Database with doc ID (long id in the sheets URL)
const db = new SheetDatabase('<the sheet ID from the url>');

// Initialize Auth
// see more available options at https://rahul-jha98.github.io/google-sheets-db/#/getting-started/authentication
// see more available options at https://rahul-jha98.github.io/sheets-database/#/getting-started/authentication
await db.useServiceAccount({
client_email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL,
private_key: process.env.GOOGLE_PRIVATE_KEY,
Expand All @@ -59,7 +59,7 @@ await db.dropTable('newTable2');
```
More info:
- [Authentication](https://rahul-jha98.github.io//#/getting-started/authentication)
- [SheetDatabase](https://rahul-jha98.github.io/google-sheets-db//#/classdocs/sheetdatabase)
- [SheetDatabase](https://rahul-jha98.github.io/sheets-database//#/classdocs/sheetdatabase)


### Working with Table Entries
Expand Down Expand Up @@ -113,7 +113,7 @@ console.log(table.getData());
*/
```
More Info:
- [Table](https://rahul-jha98.github.io/google-sheets-db//#/classdocs/table)
- [Table](https://rahul-jha98.github.io/sheets-database//#/classdocs/table)

## Why?
> The library will let you worry only about the CRUD operation you wish to perfrom and handles the task of updating it to the spreadsheet internally.
Expand All @@ -125,9 +125,8 @@ But the Google Sheet's API v4 is a bit awkward with confusing docs, at least to
The library aims to remove the learning curve completely by providing methods that lets you interact with the database without worrying about the Sheets API at all.
Moreover the API of the library is quite intuitive to get started with and provides functionalities for most of the database operations.


## Note
`google-sheets-db` is heavily inspired by and borrows some code from [node-google-spreadsheet](https://github.com/theoephraim/node-google-spreadsheet).
`sheets-database` is heavily inspired by and borrows some code from [node-google-spreadsheet](https://github.com/theoephraim/node-google-spreadsheet).

## Contributions

Expand All @@ -137,4 +136,7 @@ Contributions are welcome. Make sure to add relevant documentation along with co
Also, since I am new to Typescript and still exploring any help in improving the code practices and conventions would be appreciated.

The docs site is generated using [docsify](https://docsify.js.org). To preview and run locally so you can make edits, install docsify_cli and run `docsify serve ./docs` in the project root folder and head to https://localhost:3000
The content lives in markdown files in the docs folder.
The content lives in markdown files in the docs folder.

## License
[MIT](https://github.com/rahul-jha98/sheets-database/blob/main/LICENSE)
2 changes: 1 addition & 1 deletion docs/_sidebar.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- docs/_sidebar.md -->
* **Getting Started**
* [Overview](/ "google-sheets-db")
* [Overview](/ "sheets-database")
* [Authentication](getting-started/authentication)
* **Class Documentation**
* [SheetDatabase](classdocs/sheetdatabase)
Expand Down
6 changes: 3 additions & 3 deletions docs/assets/imgs/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>google-sheets-db</title>
<title>sheets-database</title>
<meta
name="description"
content="Library to help use Google Sheets as Database"
content="Library to help use Google Sheets as a Database"
/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
Expand All @@ -20,8 +20,8 @@
<script>
window.$docsify = {
auto2top: true,
name: 'google-sheets-db',
repo: 'https://github.com/rahul-jha98/google-sheets-db',
name: 'sheets-database',
repo: 'https://github.com/rahul-jha98/sheets-database',
loadSidebar: true,
subMaxLevel: 4,
autoTitle: false,
Expand Down
35 changes: 20 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "google-sheets-db",
"name": "sheets-database",
"version": "1.0.0",
"description": "Library to help use a Google Sheet as a database",
"main": "lib/src/index.js",
Expand All @@ -8,8 +8,26 @@
"build": "rm -rf lib/ && tsc",
"start": "npm run build && node lib/src/index.js",
"test": "npm run build && jest --runInBand",
"lintjs": "eslint './lib/src/**/*.{js,ts,tsx}' --quiet --fix"
"jest": "jest --runInBand",
"lintjs": "eslint './lib/src/**/*.{js,ts,tsx}' --quiet --fix",
"prepublishOnly": "npm run jest",
"version": "git add -A src",
"postversion" : "git push && git push --tags"
},
"repository": {
"type": "git",
"url": "git+https://github.com/rahul-jha98/sheets-database.git"
},
"keywords": ["google", "sheets", "database", "db", "google sheets", "spreadsheets", "spreadsheet"],
"author": "Rahul Jha <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/rahul-jha98/sheets-database/issues"
},
"homepage": "https://rahul-jha98.github.io/sheets-database/",
"files": [
"lib/src/"
],
"jest": {
"testMatch": [
"**/__tests__/**/*.js?(x)",
Expand All @@ -20,19 +38,6 @@
],
"testTimeout": 15000
},
"repository": {
"type": "git",
"url": "git+https://github.com/rahul-jha98/google-sheets-db.git"
},
"author": "Rahul Jha",
"license": "MIT",
"bugs": {
"url": "https://github.com/rahul-jha98/google-sheets-db/issues"
},
"homepage": "https://github.com/rahul-jha98/google-sheets-db#readme",
"files": [
"lib/src/"
],
"dependencies": {
"axios": "^0.21.1",
"google-auth-library": "^6.1.3"
Expand Down
2 changes: 1 addition & 1 deletion src/dbhelper/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class Database {
}

async _requestBatchUpdate(requests: any) {
const response = await this.axios.post(':batchUpdate', {
await this.axios.post(':batchUpdate', {
requests,
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/dbhelper/Table.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {checkIfNameValid, columnNumberToName, reduceRowsToDelete} from './utils';
import {Sheet, SheetData, SheetProperties} from './ResponseStructure';
import {columnNumberToName, reduceRowsToDelete} from './utils';

type primitiveTypes = string | boolean | number | null | undefined;
type rowDataObject = Record<string, primitiveTypes>;
Expand Down Expand Up @@ -537,6 +537,7 @@ export class Table {
}

/**
* @private
* resize the number of columns
* @param columnCount new value of column count
*/
Expand Down
6 changes: 3 additions & 3 deletions src/dbhelper/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export function columnNameToNumber(columnName: string): number {

export function reduceRowsToDelete(rowsToDelete: number[]) : number[][] {
const rangeRowsToDelete = rowsToDelete.map((rowNo) => [rowNo, rowNo+1]);
const reducedRowsToDelete : number[][] = []
reducedRowsToDelete.push(rangeRowsToDelete[0])
const reducedRowsToDelete : number[][] = [];
reducedRowsToDelete.push(rangeRowsToDelete[0]);
let lastIdx = 0;

for (let i = 1; i < rangeRowsToDelete.length; i++) {
Expand Down Expand Up @@ -62,4 +62,4 @@ export function checkIfNameValid(data: string[] | string) : boolean {
}
const validRegex = /^[A-Za-z0-9_]+$/;
return data.every((name) => name.match(validRegex) !== null);
}
}
6 changes: 4 additions & 2 deletions test/entries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ describe('Handle CRUD Operations on Table Entries', () => {
await table.updateRow(0, [1, null]);
expect(table.getRow(0).index).toBe(1);
});
it('can update rows using objects', async() => {
it('can update rows using objects', async () => {
await table.updateRow(0, {letter: 'changed'});
expect(table.getRow(0).letter).toBe('changed');
});
it('can update multiple rows', async () => {
await table.updateRows([0, 1, 2], (data) => {return {letter: data?.index}});
await table.updateRows([0, 1, 2], (data) => {
return {letter: data?.index};
});
});
});
});
5 changes: 4 additions & 1 deletion test/names.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ describe('Prevent incorrect naming of tables and columns', () => {
it('can prevent setting incorrect table headers', async () => {
const table = await database.addTable('headers', ['header1', 'header2', 'header3']);
expect(async () => await table.setColumnNames(['header@1', 'header2'])).rejects;
table.drop();
});

afterAll(async () => {
await database.headers.drop();
});
});
});

0 comments on commit b42e141

Please sign in to comment.