@niledatabase/server 4.0.0-alpha.10 → 4.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -15
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,39 +1,83 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img width="1434" alt="Screen Shot 2024-09-18 at 9 20 04 AM" src="https://github.com/user-attachments/assets/20585883-5cdc-4f15-93d3-dc150e87bc11">
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
---
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
# Nile's Server-Side SDK
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
This package (`@niledatabase/server`) is part of [Nile's Javascript SDK](https://github.com/niledatabase/nile-js/tree/main).
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
import Nile from '@niledatabase/server';
|
|
11
|
+
Nile's server-side Javascript package provides:
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
13
|
+
- 🔐 Methods for working with Nile's user and tenant APIs
|
|
14
|
+
- 🔑 Generated routes for authentication
|
|
15
|
+
- 🔍 SQL query execution with tenant and user context management
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
**Nile is a Postgres platform that decouples storage from compute, virtualizes tenants, and supports vertical and horizontal scaling globally to ship B2B applications fast while being safe with limitless scale.** All B2B applications are multi-tenant. A tenant/customer is primarily a company, an organization, or a workspace in your product that contains a group of users. A B2B application provides services to multiple tenants. Tenant is the basic building block of all B2B applications.
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Installation
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
npm install @niledatabase/server
|
|
20
25
|
```
|
|
21
26
|
|
|
22
|
-
###
|
|
27
|
+
### Initialize SDK with env vars
|
|
28
|
+
|
|
29
|
+
The recommended way to initialize Nile SDK is with `.env` file. You can copy the environment variables from [Nile console](https://console.thenile.dev). It should look similar to this:
|
|
23
30
|
|
|
24
31
|
```bash
|
|
25
32
|
NILEDB_USER=username
|
|
26
33
|
NILEDB_PASSWORD=password
|
|
34
|
+
NILEDB_API_URL=https://us-west-2.api.thenile.dev/v2/databases/DBID
|
|
35
|
+
NILEDB_POSTGRES_URL=postgres://us-west-2.db.thenile.dev:5432/dbname
|
|
27
36
|
```
|
|
28
37
|
|
|
29
38
|
```ts
|
|
30
39
|
import Nile from '@niledatabase/server';
|
|
31
40
|
|
|
32
41
|
const nile = await Nile();
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Initialize SDK with configuration object
|
|
33
45
|
|
|
34
|
-
|
|
46
|
+
```ts
|
|
47
|
+
import Nile from '@niledatabase/server';
|
|
48
|
+
|
|
49
|
+
const nile = await Nile({
|
|
50
|
+
user: 'username',
|
|
51
|
+
password: 'password',
|
|
52
|
+
debug: true
|
|
53
|
+
});
|
|
54
|
+
```
|
|
35
55
|
|
|
36
|
-
|
|
56
|
+
### Call Nile APIs
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const tenant = await nile.api.tenants.createTenant(tenantName);
|
|
60
|
+
if (tenant instanceof Response) {
|
|
61
|
+
const err = await tenant.text()
|
|
62
|
+
console.log("ERROR creating tenant: ", tenant, err);
|
|
63
|
+
return { message: "Error creating tenant" };
|
|
64
|
+
}
|
|
65
|
+
nile.tenant_id = tenant.id // set context
|
|
66
|
+
// Get tenant name doesn't need any input parameters
|
|
67
|
+
// because it uses the tenant ID and user token from the context
|
|
68
|
+
const checkTenant = await tenantNile.api.tenants.getTenant();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Query the database
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
nile.tenant_id = tenant.id // set context
|
|
75
|
+
|
|
76
|
+
const todos = await nile.db
|
|
77
|
+
.query("select * from todos order by title")
|
|
78
|
+
.catch((e: Error) => {
|
|
79
|
+
console.error(e);
|
|
80
|
+
}); // no need for where clause if you previously set Nile context
|
|
37
81
|
```
|
|
38
82
|
|
|
39
83
|
## Initialization
|
|
@@ -59,3 +103,9 @@ Configuration passed to `Server` takes precedence over `.env` vars.
|
|
|
59
103
|
| api.cookieKey | `string` | | Key for API cookie. Default is `token`. |
|
|
60
104
|
| api.token | `string` | NILEDB_TOKEN | Token for API authentication. Mostly for debugging. |
|
|
61
105
|
| debug | `boolean` | | Flag for enabling debug logging. |
|
|
106
|
+
|
|
107
|
+
## Learn more
|
|
108
|
+
|
|
109
|
+
- You can learn more about Nile and the SDK in [https://thenile.dev/docs]
|
|
110
|
+
- You can find detailed code examples in [our main repo](https://github.com/niledatabase/niledatabase)
|
|
111
|
+
- Nile SDK interacts with APIs in Nile Auth service. You can learn more about it in the [repository](https://github.com/niledatabase/nile-auth) and the [docs](https://thenile.dev/docs/auth)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@niledatabase/server",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"jose": "^4.15.4",
|
|
94
94
|
"pg": "^8.11.3"
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "e2546b25f126924a52f5d49e4b455e6174e2983a"
|
|
97
97
|
}
|