Skip to content

Commit

Permalink
Resolve issues with positional params in query
Browse files Browse the repository at this point in the history
  • Loading branch information
Brayden committed Jun 25, 2024
2 parents 385e4b7 + 7c6db1b commit cf740e4
Show file tree
Hide file tree
Showing 30 changed files with 7,606 additions and 1,027 deletions.
21 changes: 21 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Purpose



## Tasks
<!-- [ ] incomplete; [x] complete -->

- [ ]

## Verify
<!-- guidance or steps to assist the reviewer -->

-

## Before
<!-- screenshot before changes -->



## After
<!-- screenshot after changes -->
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: CI

on: push

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install modules
run: npm install

- name: Build
run: npm run build

- name: Run sync-database-models command
id: sync
run: npm exec sync-database-models

- name: Run tests
run: npm test
20 changes: 20 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
**/*.md
**/*.txt
/playground/*

# dependencies
pnpm-lock.yaml
/node_modules

# output
/dist/

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# handlebars
**/*.sh
**/*.handlebars
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true
}
128 changes: 128 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Contributor Covenant Code of Conduct

## Our Pledge

We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.

We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.

## Our Standards

Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities

Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.

Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.

## Scope

This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
[email protected].
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
reporter of any incident.

## Enforcement Guidelines

Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:

### 1. Correction

**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.

**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.

### 2. Warning

**Community Impact**: A violation through a single incident or series
of actions.

**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.

### 3. Temporary Ban

**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.

**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.

### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
the community.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.

Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ Outerbase SDK is a way to interact with your database in a SQL-like manner. This

## Usage

### Install with a package manager

**npm**
```
npm i @outerbase/sdk
```

**pnpm**
```
pnpm add @outerbase/sdk
```

### Initialize a connection to your database

This library currently supports connecting to Outerbase connections, which supports **Postgres**, **MySQL**, **SQLite**, **SQL Server**, **Clickhouse** and more with direct integrations with platforms such as [DigitalOcean](https://digitalocean.com), [Neon](https://neon.tech), and [Turso](https://turso.tech).
Expand All @@ -37,7 +49,11 @@ First we start by creating a connection object which is intended to be extensibl

With a connection object instantiated we can create a new database instance to interact with that connection interface.

```
```ts
import { Outerbase, OuterbaseConnection } from '@outerbase/sdk'

// ...

const connection: OuterbaseConnection = new OuterbaseConnection('INSERT_API_TOKEN');
const db = Outerbase(connection);
```
Expand All @@ -59,7 +75,7 @@ Instead of writing SQL directly in your code you can chain commands together tha
After you construct the series of SQL-like operations you intend to execute, you should end it by calling the `.query()` function call which will send the request to the database for exection.

#### Select data from database
```
```ts
let { data, error } = await db
.selectFrom([
{
Expand All @@ -81,7 +97,7 @@ let { data, error } = await db
```

#### Insert data into a table
```
```ts
let { data } = await db
.insert({ first_name: 'John', last_name: 'Doe', position: 'Developer', avatar: 0 })
.into('person')
Expand All @@ -90,7 +106,7 @@ let { data } = await db
```

#### Update data in a table
```
```ts
let { data } = await db
.update({ first_name: 'Johnny' })
.into('person')
Expand All @@ -99,7 +115,7 @@ let { data } = await db
```

#### Delete data from a table
```
```ts
let { data } = await db
.deleteFrom('person')
.where(equals('id', '1234'))
Expand All @@ -112,21 +128,21 @@ let { data } = await db

Executing raw SQL queries against your database is possible by passing a valid SQL statement into a database instance created by the library.

```
```ts
let { data, error } = await db.queryRaw('SELECT * FROM person');
```

You can optionally pass in an array of parameters for sanitizing your SQL inputs.

```
```ts
let { data, error } = await db.queryRaw('SELECT * FROM person WHERE id=:id', { id: "123" });
```

### Run saved Outerbase queries

When you save queries to your Outerbase bases you can then directly execute those queries from this library. This enables you to make modifications to your query without having to alter and redeploy your codebase, and instead just make the modifications via Outerbase directly for convenience.

```
```ts
let { data, error } = await connection.runSavedQuery(
'ea72da5f-5f7a-4bab-9f72-ffffffffffff'
)
Expand All @@ -138,7 +154,7 @@ Note that this is an exported function directly from the `OuterbaseConnection` c

As you construct a SQL statement to be ran you can also pass in a class type you would like the output to attempt to map to by using `.asClass(ClassName)`. In the below example we pass in `Person` as the class type and the query builder will know to respond either as a single `Person` object or a `Person[]` array based on the contents of the response.

```
```ts
let { data, error } = await db
.asClass(Person)
.queryRaw('SELECT * FROM person');
Expand All @@ -155,7 +171,7 @@ If your database is connected to Outerbase, then you can add a command to your `
To get started first add the following to your `package.json` file:

##### package.json
```
```ts
"scripts": {
"sync-models": "sync-database-models PATH=./folder/path/to/add/models API_KEY=outerbase_api_key"
}
Expand All @@ -169,7 +185,7 @@ npm run sync-models

The output produces a series of files, one per database table, that is a Typescript class for your queries to map their results to and you can access programatically easily. A sample output looks like the following where each property maps to a column in your database.

```
```ts
export interface PersonType {
firstName: string;
lastName: string;
Expand Down
6 changes: 3 additions & 3 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To quote the famous William and Theodore:

## Questions

If you have any questions feel free to utilize our [Discord Community](https://discord.gg/4M6AXzGG84) or the [GitHub Discussions](https://github.com/Outerbase/query-builder/discussions) board.
If you have any questions feel free to utilize our [Discord Community](https://discord.gg/4M6AXzGG84) or the [GitHub Discussions](https://github.com/Outerbase/sdk/discussions) board.
<br /><br />

## Feature Requests
Expand All @@ -35,8 +35,8 @@ Small Changes can directly be crafted and submitted to the GitHub Repository as

**If you find a security vulnerability, do NOT open an issue. Email [email protected] instead.**

Before you submit your issue, please [search the issue archive](https://github.com/Outerbase/query-builder/issues?q=is%3Aissue+is%3Aclosed) - maybe your question or issue has already been identified or addressed.
Before you submit your issue, please [search the issue archive](https://github.com/Outerbase/sdk/issues?q=is%3Aissue+is%3Aclosed) - maybe your question or issue has already been identified or addressed.

If you find a bug in the source code, you can help us by [submitting an issue to our GitHub issue tracker](https://github.com/Outerbase/query-builder/issues). Even better, you can submit a Pull Request with a fix!
If you find a bug in the source code, you can help us by [submitting an issue to our GitHub issue tracker](https://github.com/Outerbase/sdk/issues). Even better, you can submit a Pull Request with a fix!

_More contribution guidelines around code contribution and PR guidelines coming soon._
17 changes: 17 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */

const { pathsToModuleNameMapper } = require('ts-jest')
const { compilerOptions } = require('./tsconfig')

pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>' })

module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>/',
}),
moduleDirectories: ['node_modules', 'src'],
modulePaths: ['<rootDir>'],
setupFiles: ['<rootDir>/jest.setup.js'],
}
7 changes: 7 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const tsconfigPaths = require('tsconfig-paths')
const { compilerOptions } = require('./tsconfig')

tsconfigPaths.register({
baseUrl: './',
paths: compilerOptions.paths,
})
Loading

0 comments on commit cf740e4

Please sign in to comment.