Skip to content

Commit

Permalink
Merge branch 'main' into zack/shell-cp
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored Apr 16, 2024
2 parents 4950554 + fbe2fe0 commit 28390fd
Show file tree
Hide file tree
Showing 79 changed files with 2,445 additions and 892 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bun-release-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v1
uses: ./.github/actions/setup-bun
with:
bun-version: "1.1.0"
- name: Setup Node
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/bun-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
- name: Setup Bun
uses: oven-sh/setup-bun@v1
uses: ./.github/actions/setup-bun
with:
bun-version: "1.0.21"
- name: Install Dependencies
Expand All @@ -83,7 +83,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v1
uses: ./.github/actions/setup-bun
with:
bun-version: "1.0.21"
- name: Install Dependencies
Expand Down Expand Up @@ -112,12 +112,12 @@ jobs:
node-version: latest
- name: Setup Bun
if: ${{ env.BUN_VERSION != 'canary' }}
uses: oven-sh/setup-bun@v1
uses: ./.github/actions/setup-bun
with:
bun-version: "1.0.21"
- name: Setup Bun
if: ${{ env.BUN_VERSION == 'canary' }}
uses: oven-sh/setup-bun@v1
uses: ./.github/actions/setup-bun
with:
bun-version: "canary" # Must be 'canary' so tag is correct
- name: Install Dependencies
Expand Down Expand Up @@ -254,7 +254,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v1
uses: ./.github/actions/setup-bun
with:
bun-version: "1.0.21"
- name: Install Dependencies
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.22)
cmake_policy(SET CMP0091 NEW)
cmake_policy(SET CMP0067 NEW)

set(Bun_VERSION "1.1.3")
set(Bun_VERSION "1.1.4")
set(WEBKIT_TAG e3a2d89a0b1644cc8d5c245bd2ffee4d4bd6c1d5)

set(BUN_WORKDIR "${CMAKE_CURRENT_BINARY_DIR}")
Expand Down Expand Up @@ -555,6 +555,7 @@ else()
add_compile_definitions("BUN_DEBUG=1")
set(ASSERT_ENABLED "1")
endif()

message(STATUS "Using WebKit from ${WEBKIT_DIR}")
else()
if(NOT EXISTS "${WEBKIT_DIR}/lib/${libWTF}.${STATIC_LIB_EXT}" OR NOT EXISTS "${WEBKIT_DIR}/lib/${libJavaScriptCore}.${STATIC_LIB_EXT}")
Expand Down
54 changes: 49 additions & 5 deletions docs/api/sqlite.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const db = new Database("mydb.sqlite", { create: true });
You can also use an import attribute to load a database.

```ts
import db from "./mydb.sqlite" with {"type": "sqlite"};
import db from "./mydb.sqlite" with { "type": "sqlite" };

console.log(db.query("select * from users LIMIT 1").get());
```
Expand All @@ -74,16 +74,39 @@ import { Database } from "bun:sqlite";
const db = new Database("./mydb.sqlite");
```

### `.close()`
### `.close(throwOnError: boolean = false)`

To close a database:
To close a database connection, but allow existing queries to finish, call `.close(false)`:

```ts
const db = new Database();
db.close();
// ... do stuff
db.close(false);
```

Note: `close()` is called automatically when the database is garbage collected. It is safe to call multiple times but has no effect after the first.
To close the database and throw an error if there are any pending queries, call `.close(true)`:

```ts
const db = new Database();
// ... do stuff
db.close(true);
```

Note: `close(false)` is called automatically when the database is garbage collected. It is safe to call multiple times but has no effect after the first.

### `using` statement

You can use the `using` statement to ensure that a database connection is closed when the `using` block is exited.

```ts
import { Database } from "bun:sqlite";

{
using db = new Database("mydb.sqlite");
using query = db.query("select 'Hello world' as message;");
console.log(query.get()); // => { message: "Hello world" }
}
```

### `.serialize()`

Expand Down Expand Up @@ -128,6 +151,8 @@ db.exec("PRAGMA journal_mode = WAL;");

{% details summary="What is WAL mode" %}
In WAL mode, writes to the database are written directly to a separate file called the "WAL file" (write-ahead log). This file will be later integrated into the main database file. Think of it as a buffer for pending writes. Refer to the [SQLite docs](https://www.sqlite.org/wal.html) for a more detailed overview.

On macOS, WAL files may be persistent by default. This is not a bug, it is how macOS configured the system version of SQLite.
{% /details %}

## Statements
Expand Down Expand Up @@ -387,6 +412,25 @@ db.loadExtension("myext");

{% /details %}

### .fileControl(cmd: number, value: any)

To use the advanced `sqlite3_file_control` API, call `.fileControl(cmd, value)` on your `Database` instance.

```ts
import { Database, constants } from "bun:sqlite";

const db = new Database();
// Ensure WAL mode is NOT persistent
// this prevents wal files from lingering after the database is closed
db.fileControl(constants.SQLITE_FCNTL_PERSIST_WAL, 0);
```

`value` can be:

- `number`
- `TypedArray`
- `undefined` or `null`

## Reference

```ts
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/ecosystem/neon-serverless-postgres.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ console.log(rows[0].version);

---

Start the program using `bun run`. The Postgres version should be printed to the console.
Start the program using `bun ./index.ts`. The Postgres version should be printed to the console.

```sh
$ bun run index.ts
$ bun ./index.ts
PostgreSQL 16.2 on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
```

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"build:release": "cmake . -DCMAKE_BUILD_TYPE=Release -GNinja -Bbuild-release && ninja -Cbuild-release",
"build:debug-zig-release": "cmake . -DCMAKE_BUILD_TYPE=Release -DZIG_OPTIMIZE=Debug -GNinja -Bbuild-debug-zig-release && ninja -Cbuild-debug-zig-release",
"build:safe": "cmake . -DZIG_OPTIMIZE=ReleaseSafe -DUSE_DEBUG_JSC=ON -DCMAKE_BUILD_TYPE=Release -GNinja -Bbuild-safe && ninja -Cbuild-safe",
"build:windows": "cmake -B build -S . -G Ninja -DCMAKE_BUILD_TYPE=Debug && ninja -Cbuild",
"typecheck": "tsc --noEmit && cd test && bun run typecheck",
"fmt": "prettier --write --cache './{.vscode,src,test,bench,packages/{bun-types,bun-inspector-*,bun-vscode,bun-debug-adapter-protocol}}/**/*.{mjs,ts,tsx,js,jsx}'",
"fmt:zig": "zig fmt src/*.zig src/*/*.zig src/*/*/*.zig src/*/*/*/*.zig",
Expand Down
6 changes: 5 additions & 1 deletion packages/bun-internal-test/src/banned.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"std.debug.assert": "Use bun.assert instead"
"std.debug.assert": "Use bun.assert instead",
"@import(\"root\").bun.": "Only import 'bun' once",
"std.mem.indexOfAny": "Use bun.strings.indexAny or bun.strings.indexAnyComptime",
"std.debug.print": "Don't let this be committed",
"": ""
}
6 changes: 5 additions & 1 deletion packages/bun-internal-test/src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ const write = (text: string) => {
report += text;
};
for (const [banned, suggestion] of Object.entries(BANNED)) {
if (banned.length === 0) continue;
// Run git grep to find occurrences of std.debug.assert in .zig files
let stdout = await $`git grep -n "${banned}" "src/**/**.zig"`.text();
// .nothrow() is here since git will exit with non-zero if no matches are found.
let stdout = await $`git grep -n -F "${banned}" "src/**/**.zig" | grep -v -F '//' | grep -v -F bench`
.nothrow()
.text();

stdout = stdout.trim();
if (stdout.length === 0) continue;
Expand Down
10 changes: 9 additions & 1 deletion packages/bun-internal-test/src/runner.node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,17 @@ if (failing_tests.length) {
report += "[Link to file](" + linkToGH(path) + ")\n\n";
report += `${reason}\n\n`;
report += "```\n";
report += output

let failing_output = output
.replace(/\x1b\[[0-9;]*m/g, "")
.replace(/^::(group|endgroup|error|warning|set-output|add-matcher|remove-matcher).*$/gm, "");

if (failing_output.length > 1024 * 64) {
failing_output = failing_output.slice(0, 1024 * 64) + `\n\n[truncated output (length: ${failing_output.length})]`;
}

report += failing_output;

report += "```\n\n";
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/bun-types/bun.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4145,6 +4145,11 @@ declare module "bun" {
*/
windowsHide?: boolean;

/**
* If true, no quoting or escaping of arguments is done on Windows.
*/
windowsVerbatimArguments?: boolean;

/**
* Path to the executable to run in the subprocess. This defaults to `cmds[0]`.
*
Expand Down
Loading

0 comments on commit 28390fd

Please sign in to comment.