Skip to content

Commit

Permalink
feat: added @ulixee/client package
Browse files Browse the repository at this point in the history
  • Loading branch information
calebjclark committed Jan 26, 2023
1 parent 21c0175 commit c71cc8b
Show file tree
Hide file tree
Showing 47 changed files with 1,024 additions and 267 deletions.
128 changes: 128 additions & 0 deletions client/docs/interface/local-client.md
@@ -0,0 +1,128 @@
# Local Client

When developing a new Datastore, sometimes you'll want to test your code by querying specific Runners and Tables or even the entire Datastore. You can initialize a new Client by passing one of these instances directly into the constructor. This allows you to interact with your new Datastore (or parts of it) without needing to build and deploy to a Cloud Node:

```javascript
import Client from '@ulixee/client-playground';
import myTable from './myTable';

const client = new Client(testingTable);
client.query('SELECT firstName, lastName FROM self WHERE lastName=$1', ['Jordan']).then(records => {
console.log(records);
});
```

`new Client` will return different class instances depending on what was passed in to the constructor. Each of these class instances provide different methods:

## Client for Datastore

### client.query _(sql, boundValues)_ {#query}

Send a SQL query to the datastore.

#### **Arguments**:

- sql `string`. Any valid Ulixee SQL query
- boundValues `array`. Optional. Values you want to use in your sql query

#### **Returns**: `Promise<Record[]>`

### client.fetch _(tableName, inputFilter)_ {#fetch}

Send a NoSQL query to the specified table.

#### **Arguments**:

- tableName `string`. The name of the remote table you want to query. Case sensitive.
- inputFilter `object`. Optional. Any column/values you want to filter on.

#### **Returns**: `Promise<Record[]>`


### client.run _(runnerName, inputFilter)_ {#run}

Run one of the Datastore's functions.

#### **Arguments**:

- runnerName `string`. Any valid Ulixee SQL query. Case sensitive.
- inputFilter `object`. Optional. Any named arguments required or allowed by the function.

#### **Returns**: `Promise<Record[]>`


### client.crawl _(crawlerName, inputFilter)_ {#crawl}

Trigger one of the Datastore's crawlers.

#### **Arguments**:

- crawlerName `string`. The name of the crawler. Case sensitive.
- inputFilter `object`. Optional. A key/value object that will be passed to the crawler as input.

#### **Returns**: `Promise<Record[]>`


## Client for Function

### client.run _(inputFilter)_ {#run}

Run the function.

#### **Arguments**:

- inputFilter `object`. Optional. Any named arguments required or allowed by the function.


### client.query _(sql, boundValues)_ {#query}

Send a SQL query to the table. You can use `self` as an alias for the table name.

#### **Arguments**:

- sql `string`. Any valid Ulixee SQL query
- boundValues `array`. Optional. Values you want to use in your sql query

#### **Returns**: `Promise<Record[]>`



## Client for Table

### client.fetch _(inputFilter)_ {#fetch}

Send a NoSQL query to the table.

#### **Arguments**:

- inputFilter `object`. Optional. Any column/values you want to filter on.

#### **Returns**: `Promise<Record[]>`



### client.query _(sql, boundValues)_ {#query}

Send a SQL query to the table. You can use `self` as an alias for the table name.

#### **Arguments**:

- sql `string`. Any valid Ulixee SQL query
- boundValues `array`. Optional. Values you want to use in your sql query

#### **Returns**: `Promise<Record[]>`



## Client for Crawler

### client.crawl _(inputFilter)_ {#crawl}

Trigger the crawler.

#### **Arguments**:

- inputFilter `object`. Optional. A key/value object that will be passed to the crawler as input.

#### **Returns**: `Promise<Record[]>`

137 changes: 137 additions & 0 deletions client/docs/interface/remote-client.md
@@ -0,0 +1,137 @@
# Remote Client

This is the default use-case for using Ulixee Client. You supply a connection URI or Object to the datastore you want to query.

You can also pass in a local Datastore, Function, Table, or Crawl instance to the constructor, however, this will return a
different set of properties and methods than shown on this page. See [Local Client](./local-client.md).

## Constructor

### new Client _(uriOrObject)_ {#constructor}

Creates a new Client instance.

#### **Arguments**:

- uri `string` | `Object`. A connection string in the format of `ulx://USERNAME:PASSWORD@HOST:PORT/DB`. You can also supply
an object with the following properties:
- username `string`
- password `string`
- host `string`
- port `number`
- database `string`

```js
import Client from '@ulixee/client-playground';

const client = new Client({
username: 'test',
password: 'test',
host: 'localhost',
port: 1818,
database: 'test',
});
```
## Properties

### client.username {#username}

The username authenticated with the remote server.

#### **Type**: `string`


### client.password {#password}

The password used to authenticate with the remote server.

#### **Type**: `string`


### client.host {#host}

The host of the remote server. Defaults to localhost.

#### **Type**: `string`


### client.port {#port}

The port sent of the remote server. Defaults to 1818.

#### **Type**: `number`


### client.database {#database}

The name of the datastore the client is connected.

#### **Type**: `string`


## Methods

### client.query _(sql, boundValues)_ {#query}

Send a SQL query to the remote datastore. You can optionally attach bound values:

```js
const client = new Client();
const records = await client.query('SELECT * FROM developers WHERE lastName=$1', ['Clark']);
```

#### **Arguments**:

- sql `string`. Any valid Ulixee SQL query
- boundValues `array`. Optional. Values you want to use in your sql query

#### **Returns**: `Promise<Record[]>`

### client.fetch _(tableName, inputFilter)_ {#fetch}

Send a NoSQL query to the specified table:

```js
const client = new Client();
const records = await client.fetch('developers' { lastname: 'Clark' });
```

#### **Arguments**:

- tableName `string`. The name of the remote table you want to query. Case sensitive.
- inputFilter `object`. Optional. Any column/values you want to filter on.

#### **Returns**: `Promise<Record[]>`

### client.run _(runnerName, inputFilter)_ {#run}

Run one of the Datastore's functions (what we call them Runners):

```js
const client = new Client();
const records = await client.fetch('daysUntilWorldDomination' { probability: 5 });
```

#### **Arguments**:

- runnerName `string`. Any valid Ulixee SQL query. Case sensitive.
- inputFilter `object`. Optional. Any named arguments required or allowed by the function.

#### **Returns**: `Promise<Record[]>`


### client.crawl _(crawlerName, inputFilter)_ {#crawl}

Trigger one of the Datastore's crawlers:

```js
const client = new Client();
const records = await client.fetch('ulixee' { page: 'Home' });
```

#### **Arguments**:

- crawlerName `string`. The name of the crawler. Case sensitive.
- inputFilter `object`. Optional. A key/value object that will be passed to the crawler as input.

#### **Returns**: `Promise<Record[]>`
15 changes: 5 additions & 10 deletions client/docs/links.yaml
@@ -1,18 +1,13 @@
- title: Overview
items:
- Introduction
- SQL
- NoSQL

- title: API
- title: Interface
items:
- Client
- ConnectionParameters

- title: Features
items:
- Connecting
- Queries
- Data Types
- SQL Spec
- Remote Client
- Local Client

- title: Help
items:
Expand Down
50 changes: 50 additions & 0 deletions client/docs/overview/introduction.md
@@ -0,0 +1,50 @@
# Introduction

> Ulixee Client is a main tool for querying and interacting with Datastores.
Client supports both [SQL](./sql) and [NoSQL](./no-sql) capabilities.

SQL Example:

```javascript
import Client from '@ulixee/client-playground';

const client = new Client('ulx://USERNAME:PASSWORD@DOMAIN:PORT/DATABASE');
client.query(`SELECT * FROM developers WHERE status='founder'`).then(records => {
console.log(records);
});
```

NoSQL Example:

```javascript
import Client from '@ulixee/client-playground';

const client = new Client('ulx://USERNAME:PASSWORD@DOMAIN:PORT/DATABASE');
client.fetch('developers', { status: 'founders' }).then(records => {
console.log(records);
});
```

You can also use Client with local datastores/functions/tables while in development mode:

```javascript
import Client from '@ulixee/client-playground';
import { Table, string } from '@ulixee/datastore';

const testingTable = new Table({
schema: {
firstName: string(),
lastName: string(),
},
seedlings: [
{ firstName: 'Dennis', lastName: 'Rodman' },
{ firstName: 'Michael', lastName: 'Jordan' },
],
});

const client = new Client(testingTable);
client.query('SELECT * FROM self WHERE lastName=$1', ['Jordan']).then(records => {
console.log(records);
});
```
38 changes: 38 additions & 0 deletions client/docs/overview/no-sql.md
@@ -0,0 +1,38 @@
# Using NoSQL

Ulixee's NoSQL capabilities are still very minimal. You can do straightforward fetches, runs, and crawls, but no complicated structures such as joins are supported at this time. We recommend using Ulixee SQL for more complicated query needs.

Fetch datastore tables:

```javascript
import Client from '@ulixee/client-playground';

const client = new Client('ulx://USERNAME:PASSWORD@DOMAIN:PORT/DATABASE');
client.fetch('developers', { status: 'founders' }).then(records => {
console.log(records);
});
```

Run datastore runners:


```javascript
import Client from '@ulixee/client-playground';

const client = new Client('ulx://USERNAME:PASSWORD@DOMAIN:PORT/DATABASE');
client.run('lastCommit', { package: 'hero' }).then(records => {
console.log(records);
});
```

Crawl datastore crawlers:


```javascript
import Client from '@ulixee/client-playground';

const client = new Client('ulx://USERNAME:PASSWORD@DOMAIN:PORT/DATABASE');
client.crawl('ulixee', { page: 'home' }).then(records => {
console.log(records);
});
```

0 comments on commit c71cc8b

Please sign in to comment.