per-samuelsson / misc Goto Github PK
View Code? Open in Web Editor NEWJust anything - snippets, docs that are are WIP, etc
Just anything - snippets, docs that are are WIP, etc
using System;
using Xunit;
using Starcounter;
using Starcounter.Hosting;
namespace Listonosz.XTests
{
public class DatabaseTest
{
[Fact]
public void DatabaseAccessTest()
{
ICodeHost host = new AppHostBuilder().UseDefaultDatabase().UseApplication(typeof(DatabaseTest).Assembly).Build();
host.Start();
host.Dispose();
}
}
}
[8/24/2017 8:33:05 AM Warning] System.NullReferenceException: Object reference not set to an instance of an object.
at Starcounter.Hosting.RuntimeHosts.SelfHosted.LifetimeService.System.IDisposable.Dispose()
at Starcounter.Hosting.SelfHostedCodeHost.Finalize()
at Starcounter.Hosting.RuntimeHosts.SelfHosted.LifetimeService.System.IDisposable.Dispose()
at Starcounter.Hosting.SelfHostedCodeHost.Finalize()
Starcounter-Develop-2.4.0.2608 (Aug 22, 2017 1:01:50 AM)
Need to learn that better.
Basics first, which is this issue. The setup is what's in the OP over at https://github.com/Starcounter/Starcounter/issues/3374.
Yes: this is not yet even a proposal. It's a first simple draft, just showing a direction I would get some basic feedback on before even considering it further.
So, main objective:
Better differentiate between stateful and stateless app programming models. A stateful web application will explicitly declare itself as such.
Traits at this point, and aims:
Handle.GET
etc.Application.Current.Use
and handle registration.app.Session
.Using RC4 tooling. Engine + unit tests + workloads for each distribution.
[Database] public class Person {
public string Name { get; set; }
public Person Friend;
}
[Database] public class BestFriend : Person {
SynonymousTo("Friend")]
public BestFriend Besty;
}
class Program {
static void Main() {
Db.Transact(() => {
var besty = Db.SQL<BestFriend>("SELECT b FROM BasicWithSynonym.BestFriend b").FirstOrDefault();
if (besty == null) {
var bill = new BestFriend() { Name = "Bill" };
var bull = new BestFriend() { Name = "Bull" };
bill.Besty = bull;
var piff = new BestFriend() { Name = "Piff" };
var puff = new BestFriend() { Name = "Puff" };
piff.Friend = puff;
Console.WriteLine("Is Puff Piffs best friend? {0}", piff.Besty?.Equals(puff));
}
});
}
}
When bound, we have metadata such as:
select * from Starcounter.Internal.Metadata.RawColumn c where c.Table.Name = 'bestfriend'
Doing this query produce expected result ("Bull") and below queryplan:
select f.Besty.Name from BasicWithSynonym.bestfriend f where f.Besty.Name = 'Bull'
Queryplan:
Tables(
0 = BasicWithSynonym.BestFriend
1 = BasicWithSynonym.BestFriend
)
Projection(
0 =
StringPath(
ObjectProperty(0, Besty)
StringProperty(-1, Name)
)
)
Join(
Inner
FullTableScan(
BasicWithSynonym.BestFriend
0
LogicalValue(TRUE)
Ascending
)
ReferenceLookup(
1
ObjectProperty(0, Besty)
ComparisonString(
Equal
StringProperty(1, Name)
StringLiteral(Bull)
)
)
)
[Database] public class Person {
public string Name { get; set; }
public Person Friend;
}
[Database] public class BestFriend : Person {
public BestFriend Besty {
get { return (BestFriend) Friend; }
set { Friend = value; }
}
}
class Program {
static void Main() {
Db.Transact(() => {
var besty = Db.SQL<BestFriend>("SELECT b FROM BasicWithoutSynonym.BestFriend b").FirstOrDefault();
if (besty == null) {
var bill = new BestFriend() { Name = "Bill" };
var bull = new BestFriend() { Name = "Bull" };
bill.Besty = bull;
var piff = new BestFriend() { Name = "Piff" };
var puff = new BestFriend() { Name = "Puff" };
piff.Friend = puff;
Console.WriteLine("Is Puff Piffs best friend? {0}", piff.Besty?.Equals(puff));
}
});
}
}
When bound, we have metadata such as:
select c.* from Starcounter.Internal.Metadata.RawColumn c where c.Table.FullName = 'BasicWithoutSynonym.BestFriend'
And query:
select f.Name from BasicWithoutSynonym.bestfriend f where f.Besty.Name = 'Bull'
Queryplan
Tables(
0 = BasicWithoutSynonym.BestFriend
1 = BasicWithoutSynonym.BestFriend
)
Projection(
0 =
StringProperty(0, Name)
)
Join(
Inner
FullTableScan(
BasicWithoutSynonym.BestFriend
0
LogicalValue(TRUE)
Ascending
)
ReferenceLookup(
1
ObjectProperty(0, Besty)
ComparisonString(
Equal
StringProperty(1, Name)
StringLiteral(Bull)
)
)
)
Note: starx
is a working name. The final name of the tool is TBD.
We are starting in empty src\app
.
dotnet new mvc
dotnet add package Starcounter.Nova --version 1.2.3
The above creates a standard MVC project and adds a reference to Nova stack. After this, developer can start coding and get a feeling of our API.
But...
dotnet run
Exception: Unable to connect to `[app_name]\default`.
Database config not found. Have you forgot to run 'starx init'?
See https://starcounter.io/getting-started
dotnet new tool-manifest
dotnet tool install starx --version 1.2.3
The above install starx
as a .NET Core 3.0 local tool. The tool is versioned, and bring down with it the entire Starcounter runtime, i.e. a version of the appropriate Bluestar
package. This directory - and hence the app - now have a manifest file that ties the app to a certain version of the tool.
Still though...
dotnet run
Exception: Unable to connect to `[app_name]\default`.
Database config not found. Have you forgot to run 'starx init'?
See https://starcounter.io/getting-started
dotnet tool run starx init <optional: data path, default: bin\data>
Running starx
with the init
argument does this:
bin\data
folderbin\data\default
, to host default database.db.default.config
After this, directory will look conceptually like:
\bin
app.exe
\bin\data\default
default.cfg
Program.cs
Project.csproj
db.default.config
Now the error is something else:
dotnet run
Exception: Unable to connect to `[app_name]\default`.
Database is not running. Have you forgot to run 'starx start'?
See https://starcounter.io/getting-started
What happened was that the app/host now found db.default.config
(because no database config was explicitly given, it looked for db.default.config
in the current working directory. This can be overridden in environment.
In that file, it looked for the UUID the starx
tool has generated and stored in there when the default database was created (or, alternatively, if it's better to store path to database file + tool version, and every consumer generate UUID on the fly). It tried to connect using that, but failed because database was not started.
dotnet tool run starx start <optional: data name, default: default>
The starx
tool now simply works as the host does, and reads the db.default.config
file in the same manner as the above, but instead invokes starting of scdata
with the UUID in there. Because of how the restore works, starx
will be bundled with the Bluestar
natives and the tool can easily resolve their path in a predictable way.
Voila:
dotnet run
Hello world from Starcounter Nova.
First we create the unit test project.
cd ..\..
mkdir app.test
cd app.test
dotnet new xunit
dotnet add reference ..\src\app\app.proj
As part of one time test setup when tests are executed, we connect to the database using the same config that belong to the app, e.g. db.default.config
. Alternatively, we can grab the UUID from there and simply store it in our tests. Not sure about the best approach here, so the exact details need to be worked out.
The entire getting started:
dotnet new mvc
dotnet add package Starcounter.Nova --version 1.2.3
dotnet new tool-manifest
dotnet tool install starx --version 1.2.3
dotnet tool run starx init
dotnet tool run starx start
dotnet run
TBD 1: We can, in version 2, have app/host try to start database if it can't connect, using library shared between host and the tool. But that's an opt-in. The config model is prepared for that at least.
TBD 2: Consider publish story. Do we want to publish the tool manifest and/or config?
TBD 3: We can consider making starx init
implicit, i.e. assure it runs on the first usage. And/or have init
start the default database implicitly.
TBD 4: Maybe we don't want init
, but rather starx newdb
or something.
TBD 5: We could consider delivering starx
tool as part of Bluestar package instead, and have application directly reference Bluestar
, but I think the propsed design is better.
You install the latest 2.3+ version from http://downloads.starcounter.com/download. You run the setup with all default values.
** WORK IN PROGRESS **
All Starcounter binary files are stored under C:\Program Files\Starcounter
:
Program Files\Starcounter:
[Image]
This is where your data reside. It also include all configuration. And logs.
localhost:8181. Is there a desktop icon? Here you see all your databases and the running applications. Also, you can see the log and make queries.
If you have Visual Studio installed, there will now be a new project type: Starcounter Application. These applications are hosted by the database.
Under \configuration
Windows service or not.
Complement the web interface.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.