[go: nahoru, domu]

Skip to content

Commit

Permalink
Implement the first part of the database library (enso-org#1475)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Feb 25, 2021
1 parent 37a64dd commit 6544c24
Show file tree
Hide file tree
Showing 43 changed files with 1,972 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ jobs:
run: |
$ENGINE_DIST_DIR/bin/enso --run test/Tests
$ENGINE_DIST_DIR/bin/enso --run test/Table_Tests
$ENGINE_DIST_DIR/bin/enso --run test/Database_Tests
$ENGINE_DIST_DIR/bin/enso --run test/Geo_Tests
- name: Test Engine Distribution (Windows)
Expand All @@ -219,6 +220,7 @@ jobs:
run: |
$ENGINE_DIST_DIR/bin/enso.bat --run test/Tests
$ENGINE_DIST_DIR/bin/enso.bat --run test/Table_Tests
$ENGINE_DIST_DIR/bin/enso.bat --run test/Database_Tests
$ENGINE_DIST_DIR/bin/enso.bat --run test/Geo_Tests
# Publish
Expand Down
39 changes: 32 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ GatherLicenses.distributions := Seq(
Distribution(
"std-lib-Table",
file("distribution/std-lib/Table/THIRD-PARTY"),
Distribution.sbtProjects(`table`)
Distribution.sbtProjects(table)
),
Distribution(
"std-lib-Database",
file("distribution/std-lib/Database/THIRD-PARTY"),
Distribution.sbtProjects(database)
)
)
GatherLicenses.licenseConfigurations := Set("compile")
Expand Down Expand Up @@ -1040,6 +1045,7 @@ lazy val runtime = (project in file("engine/runtime"))
(Runtime / compile) := (Runtime / compile)
.dependsOn(`std-bits` / Compile / packageBin)
.dependsOn(table / Compile / packageBin)
.dependsOn(database / Compile / packageBin)
.value
)
.settings(
Expand Down Expand Up @@ -1257,9 +1263,10 @@ lazy val `locking-test-helper` = project
assemblyOutputPath in assembly := file("locking-test-helper.jar")
)

val `std-lib-root` = file("distribution/std-lib/")
val `std-lib-polyglot-root` = `std-lib-root` / "Base" / "polyglot" / "java"
val `table-polyglot-root` = `std-lib-root` / "Table" / "polyglot" / "java"
val `std-lib-root` = file("distribution/std-lib/")
val `std-lib-polyglot-root` = `std-lib-root` / "Base" / "polyglot" / "java"
val `table-polyglot-root` = `std-lib-root` / "Table" / "polyglot" / "java"
val `database-polyglot-root` = `std-lib-root` / "Database" / "polyglot" / "java"

lazy val `std-bits` = project
.in(file("std-bits"))
Expand All @@ -1275,15 +1282,15 @@ lazy val `std-bits` = project
val _ = StdBits
.copyDependencies(
`std-lib-polyglot-root`,
"std-bits.jar",
Some("std-bits.jar"),
ignoreScalaLibrary = true
)
.value
result
}.value
)

lazy val `table` = project
lazy val table = project
.in(file("table"))
.settings(
autoScalaLibrary := false,
Expand All @@ -1297,7 +1304,25 @@ lazy val `table` = project
val _ = StdBits
.copyDependencies(
`table-polyglot-root`,
"table.jar",
Some("table.jar"),
ignoreScalaLibrary = true
)
.value
result
}.value
)

lazy val database = project
.in(file("database"))
.settings(
autoScalaLibrary := false,
libraryDependencies ++= Seq(),
Compile / packageBin := Def.task {
val result = (Compile / packageBin).value
val _ = StdBits
.copyDependencies(
`database-polyglot-root`,
None,
ignoreScalaLibrary = true
)
.value
Expand Down
2 changes: 1 addition & 1 deletion distribution/engine/THIRD-PARTY/NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Enso
Copyright 2020 New Byte Order sp. z o. o.
Copyright 2020 - 2021 New Byte Order sp. z o. o.

'scala-xml_2.13', licensed under the Apache-2.0, is distributed with the engine.
The license file can be found at `licenses/APACHE2.0`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018-2020 Philippus Baalman
Copyright (c) 2018-2021 Philippus Baalman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018-2020 Philippus Baalman
Copyright (c) 2018-2021 Philippus Baalman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 4 additions & 4 deletions distribution/project-manager/THIRD-PARTY/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ some of the dependencies that are listed here may not actually be distributed
with it if their code was removed during compilation. For completeness, this
document lists all source dependencies that were used for its compilation.

The version of this launcher built for the Linux platform uses `zlib` created by
Jean-loup Gailly and Mark Adler, see: `COPYRIGHT-ZLIB`.
The version of this Project Manager built for the Linux platform uses `zlib`
created by Jean-loup Gailly and Mark Adler, see: `COPYRIGHT-ZLIB`.

The version of this launcher built for the Linux platform uses the `musl` libc
licensed under the MIT license. Its copyright notice is included in file
The version of this Project Manager built for the Linux platform uses the `musl`
libc licensed under the MIT license. Its copyright notice is included in file
`COPYRIGHT-MUSL`.

------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018-2020 Philippus Baalman
Copyright (c) 2018-2021 Philippus Baalman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion distribution/std-lib/Base/THIRD-PARTY/NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Enso
Copyright 2020 New Byte Order sp. z o. o.
Copyright 2020 - 2021 New Byte Order sp. z o. o.

'icu4j', licensed under the Unicode/ICU License, is distributed with the std-lib-Base.
The license information can be found along with the copyright notices.
Expand Down
17 changes: 17 additions & 0 deletions distribution/std-lib/Base/src/Data/Any/Extensions.enso
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ Any.is_nothing = case this of
Any.catch : (Error -> Any) -> Any
Any.catch (handler = x->x) = this.catch_primitive handler

## Maps a dataflow error.
If the original value was a non-error value, it is not affected, but if it
was an error, the error is mapped through the provided function.

Arguments:
- f: The function to transform the error.

> Example
Wrapping an error value.
map.get "x" . map_error (_ -> ElementNotFound "x")
Any.map_error : (Error -> Error) -> Any
Any.map_error _ = this

## Checks if the underlying value is an error.
Any.is_error : Boolean
Any.is_error = False

## Applies the function `this` to the provided argument.

Arguments:
Expand Down
2 changes: 1 addition & 1 deletion distribution/std-lib/Base/src/Data/Map.enso
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type Map
## Gets the value associated with `key` in this map, or returns `other` if
it isn't present.
get_or_else : Any -> Any -> Any
get_or_else key other =
get_or_else key ~other =
this.get key . catch (_ -> other)

## Transforms the map's keys and values to create a new map.
Expand Down
9 changes: 9 additions & 0 deletions distribution/std-lib/Base/src/Data/Text/Extensions.enso
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ Text.ends_with suffix = Text_Utils.ends_with this suffix
Text.contains : Text -> Boolean
Text.contains sequence = Text_Utils.contains this sequence

## Replaces each occurrences of `old_sequence` within `this` with `new_sequence`.

The replacement from the beginning of the text, as shown in the example below.

> Example
'aaa'.replace 'aa' 'b' == 'ba'
Text.replace : Text -> Text -> Text
Text.replace old_sequence new_sequence = Text_Utils.replace this old_sequence new_sequence

## Text to JSON conversion.
Text.to_json : Json.String
Text.to_json = Json.String this
Expand Down
50 changes: 49 additions & 1 deletion distribution/std-lib/Base/src/Data/Vector.enso
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ type Vector
0.up_to this.length . fold initial f

## Combines all the elements of a non-empty vector using a binary operation.
If the vector is empty, it returns Nothing.
If the vector is empty, it throws Nothing.

> Example
In the following example, we'll compute the sum of all elements of a
Expand All @@ -141,6 +141,26 @@ type Vector
@Tail_Call go idx+1 (predicate (this.at idx))
go 0 False

## Returns the first element of the vector that satisfies the predicate or
If no elements of the vector satisfy the predicate, it throws nothing.

A predicate is a function that takes an element from the vector and
returns a boolean value.

> Example
Finding a first element of the list that is larger than 3.
[1,2,3,4,5].find (> 3)
find : (Any -> Boolean) -> Any ! Nothing
find predicate =
len = this.length
go idx =
if (idx >= len) then Error.throw Nothing else
elem = this.at idx
if (predicate elem) then elem else
@Tail_Call go idx+1
go 0


## Checks whether a predicate holds for at least one element of this vector.
A predicate is a function that takes an element from the vector and
returns a boolean value.
Expand Down Expand Up @@ -210,6 +230,25 @@ type Vector
map function =
here.new this.length i-> function (this.at i)

## Applies a function to each element of the vector, returning the vector
that contains all results concatenated.

> Example
In the following example, we replace each number `n` with itself
repeated `n` times:
[0, 1, 2] . flat_map (n -> Vector.fill n n)
The result of running the code above is:
[1, 2, 2]
flat_map : (Any -> Vector) -> Vector
flat_map function =
mapped = this.map function
length = mapped.fold 0 acc-> elem-> acc + elem.length
arr = Array.new length
mapped.fold 0 i-> vec->
vec.map_with_index j-> elem-> arr.set_at i+j elem
i + vec.length
Vector arr

## Applies a function to each element of the vector, returning the vector
of results.

Expand Down Expand Up @@ -406,6 +445,15 @@ type Vector
first : Vector ! Nothing
first = this.head

## Get the second element from the vector.
Useful when tuples are implemented as vectors.

> Example
The following code returns 2.
[1, 2, 3, 4].second
second : Vector ! Nothing
second = if this.length >= 2 then this.at 1 else Error.throw Nothing

## Get all elements in the vector except the first.

> Example
Expand Down
17 changes: 17 additions & 0 deletions distribution/std-lib/Base/src/Error/Extensions.enso
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ Error.to_default_visualization_data = this.catch .to_default_visualization_data
Error.to_display_text : Text
Error.to_display_text = "Error: " + (this.catch .to_display_text)

## Maps a dataflow error.
If the original value was a non-error value, it is not affected, but if it
was an error, the error is mapped through the provided function.

Arguments:
- f: The function to transform the error.

> Example
Wrapping an error value.
map.get "x" . map_error (_ -> ElementNotFound "x")
Error.map_error : (Error -> Error) -> Any
Error.map_error f = this.catch (x -> Error.throw (f x))

## Checks if the underlying value is an error.
Error.is_error : Boolean
Error.is_error = True

## Takes any value, and if it is a dataflow error, throws it as a Panic.
Otherwise, returns the original value unchanged.
Panic.rethrow : (Any ! Any) -> Any
Expand Down
2 changes: 2 additions & 0 deletions distribution/std-lib/Database/THIRD-PARTY/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Enso
Copyright 2020 - 2021 New Byte Order sp. z o. o.
6 changes: 6 additions & 0 deletions distribution/std-lib/Database/package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
license: APLv2
name: Database
enso-version: default
version: "0.0.1"
author: "Enso Team <contact@enso.org>"
maintainer: "Enso Team <contact@enso.org>"
29 changes: 29 additions & 0 deletions distribution/std-lib/Database/src/Connection/Connection.enso
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from Base import all
import Database.Data.Table

type Connection

## UNSTABLE

A Database connection.

Allows to access tables from a database.
type Connection internal_connection

## UNSTABLE

SQL dialect that the database associated with that connection is using.
dialect : String
dialect = this.internal_connection.dialect

## UNSTABLE

Accesses a table within the database, returning an object that can be
used to create queries for that table.

Arguments:
- name: name of the table to access
access_table : Text -> Table
access_table name =
column_names = this.internal_connection.fetch_column_names name
Table.make_table this name column_names
Loading

0 comments on commit 6544c24

Please sign in to comment.