File: DEVELOPMENT.md

package info (click to toggle)
pljs 1.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,704 kB
  • sloc: ansic: 69,356; javascript: 5,408; sql: 878; makefile: 443; sh: 123
file content (83 lines) | stat: -rw-r--r-- 2,477 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# PLJS Development

PLJS provides JavaScript functionality as a language extension for Postgres. It's implemented in `C` and built using `make` and a `C` compiler.

## Building

As long as pre-requisites are met, building can be as simple as running `make`:

```bash
make
```

and installation by running:

```bash
make install
```

Some specific packages and software need to be installed depending on the operating system in use:

### MacOS

- XCode (provides `clang`, `make`, and `git`)
- Postgres (such as with `brew`)

### Linux

- Postgres development packages
- `git`
- `gcc` (typically with `build-essential` or `development tools` depending on operating system)
- `make` (generally installed with the above packages)

## Testing

PLJS uses Postgres' testing framework.

### Tests

Tests use Postgres' [regression testing framework](https://www.postgresql.org/docs/current/regress.html), thus running `make installcheck` after running `make install` will run the test suite and provide results. Tests live in the `sql` directory and are named according to their tests.

## File Naming Conventions

Files are named by function.

### Source

All source for the PLJS extension can be found in the `src` directory:

- `pljs.h` - Header file that defines functions and `structs`
- `pljs.c` - Main entry point for PLJS, including setup and teardown
- `cache.c` - Context and function caching
- `functions.c` - Functions available from PLV8
- `types.c` - Type conversion to/from Postgres/JavaScript
- `params.c` - Parameter management for Postgres

### Tests

All tests live in the `sql` directory, and their expected results live in the `expected` directory.

Tests are named by the function that they test.

## Function Naming Conventions

Naming conventions for this project generally favor using `pljs_` as a prefix for functions that are not private (not marked `static`) in the project. `C` functions accessible from JavaScript are also prefixed with `pljs_` and marked as static, indicating their availability within the JavaScript engine.

A function scoped to `pljs.c`](../src/pljs.c)`:

```c
static Datum call_function(PG_FUNCTION_ARGS, pljs_context *context,
                           JSValueConst *argv);
```

A function available throughout the project:

```c
bool pljs_has_permission_to_execute(const char *signature);
```

A function available in JavaScript:

```c
static JSValue pljs_elog(JSContext *ctx, JSValueConst this, int argc, JSValueConst *argv);
```