Skip to content

Commit

Permalink
chore: Move db. to a new branch (#4349)
Browse files Browse the repository at this point in the history
Co-authored-by: Aljaž Mur Eržen <[email protected]>
  • Loading branch information
max-sixty and aljazerzen authored Mar 23, 2024
1 parent 51347e6 commit 76c4f76
Show file tree
Hide file tree
Showing 202 changed files with 2,464 additions and 2,557 deletions.
7 changes: 0 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
generates Markdown documentation from `.prql` files. (@vanillajonathan,
#4152).

- _Breaking_: References to database tables now require an explicit `db.`
prefix. Example:
```prql no-eval
from db.my_table
join db.another_table (==some_id)
```

**Fixes**:

**Documentation**:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ since it compiles to SQL.
PRQL can be as simple as:

```elm
from db.tracks
from tracks
filter artist == "Bob Marley" # Each line transforms the previous result
aggregate { # `aggregate` reduces each column to a value
plays = sum plays,
Expand All @@ -38,7 +38,7 @@ aggregate { # `aggregate` reduces each column
Here's a fuller example of the language;

```elm
from db.employees
from employees
filter start_date > @2021-01-01 # Clear date syntax
derive { # `derive` adds columns / variables
gross_salary = salary + (tax ?? 0), # Terse coalesce
Expand Down
2 changes: 1 addition & 1 deletion lutra/bindings/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module my_database {
let artists <[{artist_id = int, name = text}]>
}
from db.my_database.artists
from my_database.artists
select {artist_id, text}
into main
```
Expand Down
6 changes: 3 additions & 3 deletions lutra/example-project/Project.prql
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ let favourite_artists = [
{artist_id = 7, last_listen = @2023-05-16},
]

favourite_artists
join (chinook.artists | select {artist_id, name}) side:left (==artist_id)
from favourite_artists
join input = (from chinook.artists | select {artist_id, name}) side:left (==artist_id)
derive aid = favourite_artists.artist_id * 2
select {aid, name, favourite_artists.last_listen}
select {aid, input.name, favourite_artists.last_listen}
sort {-aid}
4 changes: 2 additions & 2 deletions prqlc/bindings/dotnet/PrqlCompiler.Tests/CompilerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void ToCompile_Works()
};

// Act
var result = PrqlCompiler.Compile("from db.employees", options);
var result = PrqlCompiler.Compile("from employees", options);

// Assert
Assert.Equal(expected, result.Output);
Expand All @@ -28,7 +28,7 @@ public void TestOtherFunctions()
{
// Arrange
var query = """
let a = (from db.employees | take 10)
let a = (from employees | take 10)
from a | select {first_name}
""";
Expand Down
2 changes: 1 addition & 1 deletion prqlc/bindings/dotnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var options = new PrqlCompilerOptions
Format = false,
SignatureComment = false,
};
var sql = PrqlCompiler.Compile("from db.employees", options);
var sql = PrqlCompiler.Compile("from employees", options);
Console.WriteLine(sql);
```

Expand Down
4 changes: 2 additions & 2 deletions prqlc/bindings/elixir/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ end
## Basic Usage

```elixir
iex> PRQL.compile("from db.customers")
iex> PRQL.compile("from customers")
{:ok, "SELECT\n *\nFROM\n customers\n\n-- Generated by PRQL compiler version 0.3.1 (https://prql-lang.org)\n"}


iex> PRQL.compile("from db.customers\ntake 10", dialect: :mssql)
iex> PRQL.compile("from customers\ntake 10", dialect: :mssql)
{:ok, "SELECT\n *\nFROM\n customers\nORDER BY\n (\n SELECT\n NULL\n ) OFFSET 0 ROWS\nFETCH FIRST\n 10 ROWS ONLY\n\n-- Generated by PRQL compiler version 0.3.1 (https://prql-lang.org)\n"}
```

Expand Down
4 changes: 2 additions & 2 deletions prqlc/bindings/elixir/lib/prql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ defmodule PRQL do
## Examples
Using default `Generic` target:
iex> PRQL.compile("from db.customers", signature_comment: false)
iex> PRQL.compile("from customers", signature_comment: false)
{:ok, "SELECT\n *\nFROM\n customers\n"}
Using `MSSQL` target:
iex> PRQL.compile("from db.customers\ntake 10", target: :mssql, signature_comment: false)
iex> PRQL.compile("from customers\ntake 10", target: :mssql, signature_comment: false)
{:ok, "SELECT\n *\nFROM\n customers\nORDER BY\n (\n SELECT\n NULL\n ) OFFSET 0 ROWS\nFETCH FIRST\n 10 ROWS ONLY\n"}
"""
@spec compile(binary(), [compile_opts()]) :: {:ok, binary()} | {:error, binary()}
Expand Down
2 changes: 1 addition & 1 deletion prqlc/bindings/elixir/test/prql_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule PRQLTest do
@compile_opts [signature_comment: false]

test "compiles PRQL" do
prql_query = "from db.customers"
prql_query = "from customers"

assert PRQL.compile(prql_query, @compile_opts) ==
{:ok,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class PrqlCompilerTest {
@Test
public void compile() throws Exception {
String found = PrqlCompiler.toSql("from db.my_table", "sql.mysql", true, true);
String found = PrqlCompiler.toSql("from my_table", "sql.mysql", true, true);

// remove signature
found = found.substring(0, found.indexOf("\n\n--"));
Expand All @@ -19,6 +19,6 @@ public void compile() throws Exception {

@Test(expected = Exception.class)
public void compileWithError() throws Exception {
PrqlCompiler.toSql("from db.table | filter id >> 1", "sql.mysql", true, true);
PrqlCompiler.toSql("from table | filter id >> 1", "sql.mysql", true, true);
}
}
16 changes: 8 additions & 8 deletions prqlc/bindings/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Direct usage
```javascript
const prqljs = require("prql-js");

const sql = prqljs.compile(`from db.employees | select first_name`);
const sql = prqljs.compile(`from employees | select first_name`);
console.log(sql);
```

Expand All @@ -43,7 +43,7 @@ opts.target = "sql.mssql";
opts.format = false;
opts.signature_comment = false;

const sql = prqljs.compile(`from db.employees | take 10`, opts);
const sql = prqljs.compile(`from employees | take 10`, opts);
console.log(sql);
```

Expand All @@ -53,7 +53,7 @@ Template literal
const prqljs = require("prql-js");
const prql = (string) => prqljs.compile(string[0] || "");

const sql = prql`from db.employees | select first_name`;
const sql = prql`from employees | select first_name`;
console.log(sql);
```

Expand All @@ -64,7 +64,7 @@ const prqljs = require("prql-js");
const prql = (string) => prqljs.compile(string[0] || "");

const sql = prql`
from db.employees
from employees
select first_name
`;
console.log(sql);
Expand All @@ -76,10 +76,10 @@ console.log(sql);
<html>
<head>
<script type="module">
import init, { compile } from './dist/web/prql_js.js';
import init, { compile } from "./dist/web/prql_js.js";
await init();
const sql = compile("from db.employees | select first_name");
const sql = compile("from employees | select first_name");
console.log(sql);
</script>
</head>
Expand All @@ -93,7 +93,7 @@ console.log(sql);
```typescript
import compile from "prql-js/dist/bundler";

const sql = compile(`from db.employees | select first_name`);
const sql = compile(`from employees | select first_name`);
console.log(sql);
```

Expand Down Expand Up @@ -135,7 +135,7 @@ These errors can be caught as such:

```javascript
try {
const sql = prqlJs.compile(`from db.employees | foo first_name`);
const sql = prqlJs.compile(`from employees | foo first_name`);
} catch (error) {
const errorMessages = JSON.parse(error.message).inner;

Expand Down
20 changes: 10 additions & 10 deletions prqlc/bindings/js/tests/test_all.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import assert from "assert";
import { expect } from "chai";
import prql from "../dist/node/prql_js.js";

const employee_prql = `from db.employees
join db.salaries (==emp_no)
const employee_prql = `from employees
join salaries (==emp_no)
group {employees.emp_no, employees.gender} (
aggregate {
emp_salary = average salaries.salary
}
)
join de = db.dept_emp (==emp_no)
join dm = db.dept_manager (
join de=dept_emp (==emp_no)
join dm=dept_manager (
(dm.dept_no == de.dept_no) && s"(de.from_date, de.to_date) OVERLAPS (dm.from_date, dm.to_date)"
)
group {dm.emp_no, gender} (
Expand All @@ -20,7 +20,7 @@ group {dm.emp_no, gender} (
}
)
derive mng_no = emp_no
join managers = db.employees (==emp_no)
join managers=employees (==emp_no)
derive mng_name = s"managers.first_name || ' ' || managers.last_name"
select {mng_name, managers.gender, salary_avg, salary_sd}`;

Expand All @@ -46,7 +46,7 @@ describe("prql-js", () => {
opts.format = false;
opts.signature_comment = false;

const res = prql.compile("from db.a | take 10", opts);
const res = prql.compile("from a | take 10", opts);
assert.equal(
res,
"SELECT * FROM a ORDER BY (SELECT NULL) OFFSET 0 ROWS FETCH FIRST 10 ROWS ONLY",
Expand All @@ -60,7 +60,7 @@ describe("prql-js", () => {
opts.signature_comment = true;

const res = prql.compile(
"prql target:sql.sqlite\nfrom db.a | take 10",
"prql target:sql.sqlite\nfrom a | take 10",
opts,
);
assert(
Expand Down Expand Up @@ -94,7 +94,7 @@ describe("prql-js", () => {
const opts = new prql.CompileOptions();

opts.target = "sql.any";
const res = prql.compile("prql target:sql.mssql\nfrom db.a | take 1", opts);
const res = prql.compile("prql target:sql.mssql\nfrom a | take 1", opts);
assert(res.includes("1 ROWS ONLY"));
});
});
Expand All @@ -110,7 +110,7 @@ describe("prql-js", () => {
describe("compile error", () => {
it("should contain json", () => {
try {
prql.compile("from db.x | select a | select b");
prql.compile("from x | select a | select b");
} catch (error) {
const errorMessages = JSON.parse(error.message).inner;

Expand All @@ -122,7 +122,7 @@ describe("prql-js", () => {

it("should contain error code", () => {
try {
prql.compile("let a = (from db.x)");
prql.compile("let a = (from x)");
} catch (error) {
const errorMessages = JSON.parse(error.message).inner;

Expand Down
2 changes: 1 addition & 1 deletion prqlc/bindings/php/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ enabled. Set `ffi.enable` in your php.ini configuration file to `"true"`.
use Prql\Compiler\Compiler;

$prql = new Compiler();
$result = $prql->compile("from db.employees");
$result = $prql->compile("from employees");

echo $result->output;
```
Expand Down
6 changes: 3 additions & 3 deletions prqlc/bindings/php/tests/CompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testCompileWorks(): void
$options->target = "sql.mssql";
$prql = new Compiler();

$actual = $prql->compile("from db.employees | take 10", $options);
$actual = $prql->compile("from employees | take 10", $options);
$this->assertCount(0, $actual->messages);

$this->assertEquals(
Expand All @@ -59,9 +59,9 @@ public function testOtherFunctions(): void
$prql = new Compiler();

$query = "
let a = (from db.employees | take 10)
let a = (from employees | take 10)
from db.a | select {first_name}
from a | select {first_name}
";

$pl = $prql->prqlToPL($query);
Expand Down
2 changes: 1 addition & 1 deletion prqlc/bindings/prqlc-c/examples/minimal-c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void print_result(CompileResult res) {

int main() {
char *prql_query;
prql_query = "from db.albums | select {album_id, title} | take 3";
prql_query = "from albums | select {album_id, title} | take 3";
CompileResult res;
CompileResult res2;

Expand Down
2 changes: 1 addition & 1 deletion prqlc/bindings/prqlc-c/examples/minimal-cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void print_result(CompileResult res) {
}

int main() {
const auto prql_query = "from db.albums | select {album_id, title} | take 3";
const auto prql_query = "from albums | select {album_id, title} | take 3";

CompileResult res = compile(prql_query, nullptr);
print_result(res);
Expand Down
4 changes: 2 additions & 2 deletions prqlc/bindings/prqlc-c/examples/minimal-zig/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn main() !void {
};

// Compile the PRQL query
const prql_query = "from db.albums | select {album_id, title} | take 3";
const prql_query = "from albums | select {album_id, title} | take 3";
const result = prql.compile(prql_query, &options);
defer prql.result_destroy(result);

Expand All @@ -23,7 +23,7 @@ pub fn main() !void {
}

test "simple test" {
const prql_query = "from db.albums | select {album_id, title} | take 3";
const prql_query = "from albums | select {album_id, title} | take 3";
const result = prql.compile(prql_query, null);
defer prql.result_destroy(result);
try std.testing.expect(result.messages_len == 0);
Expand Down
4 changes: 2 additions & 2 deletions prqlc/bindings/prqlc-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ The crate is not published to crates.io; only to PyPI at
import prqlc

prql_query = """
from db.employees
join db.salaries (==emp_id)
from employees
join salaries (==emp_id)
group {employees.dept_id, employees.gender} (
aggregate {
avg_salary = average salaries.salary
Expand Down
8 changes: 4 additions & 4 deletions prqlc/bindings/prqlc-python/python/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_all() -> None:
should write more tests at some point.
"""

prql_query = "from db.employee"
prql_query = "from employee"

res = prqlc.prql_to_pl(prql_query)
assert res is not None
Expand All @@ -26,8 +26,8 @@ def test_all() -> None:

# Example from readme
prql_query = """
from db.employees
join db.salaries (==emp_id)
from employees
join salaries (==emp_id)
group {employees.dept_id, employees.gender} (
aggregate {
avg_salary = average salaries.salary
Expand All @@ -47,7 +47,7 @@ def test_compile_options() -> None:
"""
Test the CompileOptions
"""
query_mssql = "prql target:sql.mssql\nfrom db.a | take 3"
query_mssql = "prql target:sql.mssql\nfrom a | take 3"

assert prqlc.compile(query_mssql).startswith(
"SELECT\n *\nFROM\n a\nORDER BY\n (\n SELECT\n NULL\n ) OFFSET 0 ROWS\nFETCH FIRST\n 3 ROWS ONLY"
Expand Down
4 changes: 2 additions & 2 deletions prqlc/bindings/prqlc-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ mod test {
});

assert_snapshot!(
compile("from db.employees | filter (age | in 20..30)", opts).unwrap(),
compile("from employees | filter (age | in 20..30)", opts).unwrap(),
@r###"
SELECT
*
Expand All @@ -170,7 +170,7 @@ mod test {
display: "plain".to_string(),
});

let prql = r#"from db.artists | select {name, id} | filter (id | in [1, 2, 3])"#;
let prql = r#"from artists | select {name, id} | filter (id | in [1, 2, 3])"#;
assert_snapshot!(
prql_to_pl(prql).and_then(|x| pl_to_rq(x.as_str())).and_then(|x|rq_to_sql(x.as_str(), opts)).unwrap(), @r###"
SELECT
Expand Down
Loading

0 comments on commit 76c4f76

Please sign in to comment.